Module: Rutabaga::Feature

Defined in:
lib/rutabaga/feature.rb

Instance Method Summary collapse

Instance Method Details

#feature(feature_file = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rutabaga/feature.rb', line 6

def feature(feature_file = nil)
  RSpec.deprecate(
    "Calling `feature` from an `it` block",
    :message => "Calling `feature` from an `it` block " \
                "is deprecated.\nYou should now put your steps inside " \
                "a `feature` block.\n\n" \
                "```\n" \
                "feature \"optional feature file location\" do\n" \
                "  step \"a step\" do\n" \
                "    ...\n" \
                "  end\n" \
                "end\n" \
                "```"
  )

  feature_file = Util.find_feature(feature_file || RSpec.current_example.description)
  example_group_class = self.class

  # Hack turnip into the rspec only when needed
  example_group_class.send(:include, Turnip::RSpec::Execute)
  example_group_class.send(:include, Turnip::Steps)

  run(feature_file, example_group_class)
end

#run(feature_file, example_group_class) ⇒ Object

Adapted from jnicklas/turnip v2.0.0



32
33
34
35
36
37
# File 'lib/rutabaga/feature.rb', line 32

def run(feature_file, example_group_class)
  Turnip::Builder.build(feature_file).features.each do |feature|
    describe = example_group_class.describe feature.name, feature.
    run_feature(describe, feature, feature_file, example_group_class)
  end
end

#run_feature(describe, feature, filename, example_group_class) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rutabaga/feature.rb', line 39

def run_feature(describe, feature, filename, example_group_class)
  example_group_class.before do
    # This is kind of a hack, but it will make RSpec throw way nicer exceptions
    RSpec.current_example.[:file_path] = filename

    feature.backgrounds.map(&:steps).flatten.each do |step|
      run_step(filename, step)
    end
  end

  feature.scenarios.each do |scenario|
    example_group_class.describe scenario.name, scenario. do
      it(scenario.steps.map(&:to_s).join(' -> ')) do
        scenario.steps.each do |step|
          run_step(filename, step)
        end
      end
    end
  end
end