Class: Lime::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/lime/feature.rb

Overview

Features contain scenarios.

The ‘advice` are given, when and then rules.

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}, &block) ⇒ Feature

Returns a new instance of Feature.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lime/feature.rb', line 33

def initialize(settings={}, &block)
  @label   = settings[:label]
  @setup   = settings[:setup]

  @advice  = Advice.new

  @story     = []
  @scenarios = []

  @scope = Scope.new(self, &block)

  @scenarios.each do |scenario|
    scenario.scope.__send__(:extend, @scope)
  end
end

Instance Attribute Details

#adviceObject (readonly)

Advice are labeled procedures, such as before and after advice.



27
28
29
# File 'lib/lime/feature.rb', line 27

def advice
  @advice
end

#labelObject (readonly)

Brief description of the feature.



16
17
18
# File 'lib/lime/feature.rb', line 16

def label
  @label
end

#scenariosObject (readonly)

List of scenarios.



23
24
25
# File 'lib/lime/feature.rb', line 23

def scenarios
  @scenarios
end

#scopeObject (readonly)

Module for evaluating tests.



30
31
32
# File 'lib/lime/feature.rb', line 30

def scope
  @scope
end

#storyObject (readonly)

The descriptive details of the feature, defined using the ‘To`, `As` and `We` methods.



20
21
22
# File 'lib/lime/feature.rb', line 20

def story
  @story
end

Instance Method Details

#[](key) ⇒ Object

Convenience method for accessing advice, aka step definitions.



50
51
52
# File 'lib/lime/feature.rb', line 50

def [](key)
  @advice[key]
end

#each(&block) ⇒ Object

Iterate over each scenario.



55
56
57
# File 'lib/lime/feature.rb', line 55

def each(&block)
  scenarios.each(&block)
end

#sizeObject

Number of scenarios.



60
61
62
# File 'lib/lime/feature.rb', line 60

def size
  scenarios.size
end

#to_sObject



71
72
73
# File 'lib/lime/feature.rb', line 71

def to_s
  (["#{label}"] + story).join("\n")
end

#typeObject

Subclasses of TestCase can override this to describe the type of test case they define.



66
67
68
# File 'lib/lime/feature.rb', line 66

def type
  'Feature'
end

#update(mixin) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/lime/feature.rb', line 76

def update(mixin)
  @advice[:given].update( mixin[:given] || {} )
  @advice[:when].update(  mixin[:when]  || {} )
  @advice[:then].update(  mixin[:then]  || {} )

  #@scope.__send__(:include, mixin) if Module === mixin
end