All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.specs2.mutable.Tags.scala Maven / Gradle / Ivy

There is a newer version: 3.7
Show newest version
package org.specs2
package mutable

import specification.TagFragments._
import specification.{Fragments, Fragment}

/**
 * The tags trait allows the creation of Tags fragments in a mutable specification where the tags are defined for the
 * _next_ fragment (or fragments for a section)
 *
 */
trait Tags extends org.specs2.specification.Tags { outer: FragmentsBuilder =>
  /** create a Tag fragment */
  override def tag(names: String*): TagFragment = addTag(Tag(names:_*))

  /** create a Section fragment */
  override def section(names: String*): TagFragment = addTag(Section(names:_*))

  /** add a tagging fragment to the specification */
  def addTag(t: TagFragment) = {
    addFragments(t)
    t
  }

  /**
   * This implicit allows to add tags and sections _after_ the examples
   */
  implicit def fragmentTaggedAs[T <: Fragment](f: =>T) = new FragmentTaggedAs(f)
  class FragmentTaggedAs[T <: Fragment](f: =>T) {
    def tag(names: String*): T = {
      addFragments(Tag(names:_*))
      f
    }
    def section(names: String*): T = {
      addFragments(Section(names:_*))
      f
    }
  }
  /**
   * This implicit allows to add tags and sections _after_ the examples
   */
  implicit def fragmentsTaggedAs(fs: =>Fragments) = new FragmentsTaggedAs(fs)
  class FragmentsTaggedAs(fs: =>Fragments) {
    def section(names: String*): Fragments = {
      def section = outer.fragments(Section(names:_*))
      addFragments(section)
      val fragments = fs
      addFragments(section)
      fragments
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy