Module: Spinach::DSL::ClassMethods

Defined in:
lib/spinach/dsl.rb

Overview

Class methods to extend the host class.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) feature_name (readonly)

The feature name.



21
22
23
# File 'lib/spinach/dsl.rb', line 21

def feature_name
  @feature_name
end

Instance Method Details

- (Object) after(&block)

Defines a after hook for each scenario. The scope is limited only to the current step class (thus the current feature).

When a scenario is executed, the after each block will be run after any steps

User can define multiple after blocks throughout the class hierarchy and they are chained through the inheritance chain when executing.

Examples:


class MySpinach::Base < Spinach::FeatureSteps
  after do
    @var1 = 30
    @var2 = 40
  end
end

class MyFeature < MySpinach::Base
  after do
    change_session_timeout_to(original_session_timeout)
    @var2 = 50
  end
end

When running a scenario in MyFeature, @var1 is 30 and @var2 is 50


126
127
128
# File 'lib/spinach/dsl.rb', line 126

def after(&block)
  define_before_or_after_method_with_block(:after, &block)
end

- (Object) before(&block)

Defines a before hook for each scenario. The scope is limited only to the current step class (thus the current feature).

When a scenario is executed, the before each block will be run first before any steps

User can define multiple before blocks throughout the class hierarchy and they are chained through the inheritance chain when executing

Examples:


class MySpinach::Base< Spinach::FeatureSteps
  before do
    @var1 = 30
    @var2 = 40
  end
end

class MyFeature < MySpinach::Base
  before do
    self.original_session_timeout = 1000
    change_session_timeout_to(1)
    @var2 = 50
  end
end

When running a scenario in MyFeature, @var1 is 30 and @var2 is 50


95
96
97
# File 'lib/spinach/dsl.rb', line 95

def before(&block)
  define_before_or_after_method_with_block(:before, &block)
end

- (Object) feature(name)

Sets the feature name.

Examples:

class MyFeature < Spinach::FeatureSteps
  feature "Satisfy needs"
end

Parameters:

  • name (String)

    The name.



141
142
143
# File 'lib/spinach/dsl.rb', line 141

def feature(name)
  @feature_name = name
end

- (Object) step(step, &block) Also known as: Given, When, Then, And, But

Defines an action to perform given a particular step literal.

Examples:

These 3 examples are equivalent:

class MyFeature < Spinach::FeatureSteps
  When "I go to the toilet" do
    @sittin_on_the_toilet.must_equal true
  end
end

class MyFeature < Spinach::FeatureSteps
  step "I go to the toilet" do
    @sittin_on_the_toilet.must_equal true
  end
end

class MyFeature < Spinach::FeatureSteps
  def i_go_to_the_toilet
    @sittin_on_the_toilet.must_equal true
  end
end

Parameters:

  • step (String)

    The step name.

  • block (Proc)

    Action to perform in that step. If no block is given, step will be defined as pending.



53
54
55
56
57
58
59
# File 'lib/spinach/dsl.rb', line 53

def step(step, &block)
  method_body = if block_given? then block
                else lambda { pending "step not implemented" }
                end

  define_method(Spinach::Support.underscore(step), &method_body)
end