Class: Cucumber::Core::Test::Case

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/core/test/case.rb

Defined Under Namespace

Classes: NameBuilder, TagCollector

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_steps, source, around_hooks = []) ⇒ Case

Returns a new instance of Case.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/cucumber/core/test/case.rb', line 9

def initialize(test_steps, source, around_hooks = [])
  raise ArgumentError.new("test_steps should be an Array but is a #{test_steps.class}") unless test_steps.kind_of?(Array)
  @test_steps = test_steps
  @source = source
  @around_hooks = around_hooks
end

Instance Attribute Details

#around_hooksObject (readonly)

Returns the value of attribute around_hooks.



7
8
9
# File 'lib/cucumber/core/test/case.rb', line 7

def around_hooks
  @around_hooks
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/cucumber/core/test/case.rb', line 7

def source
  @source
end

#test_stepsObject (readonly)

Returns the value of attribute test_steps.



7
8
9
# File 'lib/cucumber/core/test/case.rb', line 7

def test_steps
  @test_steps
end

Instance Method Details

#describe_source_to(visitor, *args) ⇒ Object



31
32
33
34
35
36
# File 'lib/cucumber/core/test/case.rb', line 31

def describe_source_to(visitor, *args)
  source.reverse.each do |node|
    node.describe_to(visitor, *args)
  end
  self
end

#describe_to(visitor, *args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/cucumber/core/test/case.rb', line 20

def describe_to(visitor, *args)
  visitor.test_case(self, *args) do |child_visitor|
    compose_around_hooks(child_visitor, *args) do
      test_steps.each do |test_step|
        test_step.describe_to(child_visitor, *args)
      end
    end
  end
  self
end

#featureObject



84
85
86
# File 'lib/cucumber/core/test/case.rb', line 84

def feature
  source.first
end

#inspectObject



80
81
82
# File 'lib/cucumber/core/test/case.rb', line 80

def inspect
  "#<#{self.class}: #{location}>"
end

#keywordObject



50
51
52
# File 'lib/cucumber/core/test/case.rb', line 50

def keyword
  @keyword ||= NameBuilder.new(self).keyword
end

#languageObject



67
68
69
# File 'lib/cucumber/core/test/case.rb', line 67

def language
  feature.language
end

#locationObject



71
72
73
# File 'lib/cucumber/core/test/case.rb', line 71

def location
  source.last.location
end

#match_locations?(queried_locations) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/cucumber/core/test/case.rb', line 75

def match_locations?(queried_locations)
  return true if source.any? { |s| s.match_locations?(queried_locations) }
  test_steps.any? { |node| node.match_locations? queried_locations }
end

#match_name?(name_regexp) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/cucumber/core/test/case.rb', line 63

def match_name?(name_regexp)
  source.any? { |node| node.respond_to?(:name) && node.name =~ name_regexp }
end

#match_tags?(*expressions) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/cucumber/core/test/case.rb', line 59

def match_tags?(*expressions)
  ::Gherkin::TagExpression.new(expressions.flatten).evaluate(tags.map {|t| ::Gherkin::Formatter::Model::Tag.new(t.name, t.line) })
end

#nameObject



46
47
48
# File 'lib/cucumber/core/test/case.rb', line 46

def name
  @name ||= NameBuilder.new(self).result
end

#step_countObject



16
17
18
# File 'lib/cucumber/core/test/case.rb', line 16

def step_count
  test_steps.count
end

#tagsObject



54
55
56
# File 'lib/cucumber/core/test/case.rb', line 54

def tags
  @tags ||= TagCollector.new(self).result
end

#with_around_hooks(around_hooks) ⇒ Object



42
43
44
# File 'lib/cucumber/core/test/case.rb', line 42

def with_around_hooks(around_hooks)
  self.class.new(test_steps, source, around_hooks)
end

#with_steps(test_steps) ⇒ Object



38
39
40
# File 'lib/cucumber/core/test/case.rb', line 38

def with_steps(test_steps)
  self.class.new(test_steps, source, around_hooks)
end