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)


12
13
14
15
16
17
# File 'lib/cucumber/core/test/case.rb', line 12

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



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

def around_hooks
  @around_hooks
end

#sourceObject (readonly)

Returns the value of attribute source



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

def source
  @source
end

#test_stepsObject (readonly)

Returns the value of attribute test_steps



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

def test_steps
  @test_steps
end

Instance Method Details

#==(other) ⇒ Object



111
112
113
# File 'lib/cucumber/core/test/case.rb', line 111

def ==(other)
  eql?(other)
end

#all_locationsObject



87
88
89
# File 'lib/cucumber/core/test/case.rb', line 87

def all_locations
  @all_locations ||= Ast::Location.merge(all_source.map(&:all_locations).flatten)
end

#all_sourceObject



91
92
93
# File 'lib/cucumber/core/test/case.rb', line 91

def all_source
  @all_source ||= (source + test_steps.map(&:source)).flatten.uniq
end

#describe_source_to(visitor, *args) ⇒ Object



34
35
36
37
38
39
# File 'lib/cucumber/core/test/case.rb', line 34

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

#describe_to(visitor, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/cucumber/core/test/case.rb', line 23

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/cucumber/core/test/case.rb', line 107

def eql?(other)
  other.hash == hash
end

#featureObject



99
100
101
# File 'lib/cucumber/core/test/case.rb', line 99

def feature
  source.first
end

#hashObject



103
104
105
# File 'lib/cucumber/core/test/case.rb', line 103

def hash
  location.hash
end

#inspectObject



95
96
97
# File 'lib/cucumber/core/test/case.rb', line 95

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

#keywordObject



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

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

#languageObject



69
70
71
# File 'lib/cucumber/core/test/case.rb', line 69

def language
  feature.language
end

#locationObject



73
74
75
# File 'lib/cucumber/core/test/case.rb', line 73

def location
  source.last.location
end

#match_locations?(queried_locations) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
# File 'lib/cucumber/core/test/case.rb', line 77

def match_locations?(queried_locations)
  queried_locations.any? { |queried_location|
    all_source.any? { |node|
      node.all_locations.any? { |location|
        queried_location.match? location
      }
    }
  }
end

#match_name?(name_regexp) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/cucumber/core/test/case.rb', line 65

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

#match_tags?(*expressions) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/cucumber/core/test/case.rb', line 61

def match_tags?(*expressions)
  Cucumber::Core::Gherkin::TagExpression.new(expressions.flatten).evaluate(tags)
end

#nameObject



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

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

#step_countObject



19
20
21
# File 'lib/cucumber/core/test/case.rb', line 19

def step_count
  test_steps.count
end

#tagsObject



57
58
59
# File 'lib/cucumber/core/test/case.rb', line 57

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

#with_around_hooks(around_hooks) ⇒ Object



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

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

#with_steps(test_steps) ⇒ Object



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

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