turnip 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +5 -0
  3. data/README.md +196 -44
  4. data/Rakefile +8 -0
  5. data/examples/alignment_steps.rb +7 -0
  6. data/examples/autoload_steps.feature +5 -0
  7. data/examples/autoload_steps.rb +5 -0
  8. data/examples/dragon_steps.rb +17 -0
  9. data/examples/evil_steps.rb +7 -0
  10. data/examples/knight_steps.rb +29 -0
  11. data/examples/more_steps.rb +7 -0
  12. data/examples/neutral_steps.rb +7 -0
  13. data/examples/red_dragon_steps.rb +18 -0
  14. data/examples/step_calling.feature +14 -0
  15. data/examples/step_calling_steps.rb +23 -0
  16. data/examples/steps.rb +0 -22
  17. data/examples/steps_for_super.feature +16 -0
  18. data/lib/turnip.rb +12 -12
  19. data/lib/turnip/builder.rb +20 -4
  20. data/lib/turnip/config.rb +18 -0
  21. data/lib/turnip/dsl.rb +19 -13
  22. data/lib/turnip/feature_file.rb +20 -0
  23. data/lib/turnip/loader.rb +6 -3
  24. data/lib/turnip/placeholder.rb +1 -1
  25. data/lib/turnip/runner_dsl.rb +9 -0
  26. data/lib/turnip/scenario_context.rb +41 -0
  27. data/lib/turnip/scenario_runner.rb +35 -0
  28. data/lib/turnip/step_definition.rb +14 -30
  29. data/lib/turnip/step_loader.rb +27 -0
  30. data/lib/turnip/step_module.rb +89 -0
  31. data/lib/turnip/table.rb +12 -0
  32. data/lib/turnip/version.rb +1 -1
  33. data/spec/builder_spec.rb +41 -2
  34. data/spec/dsl_spec.rb +22 -34
  35. data/spec/feature_file_spec.rb +18 -0
  36. data/spec/integration_spec.rb +1 -1
  37. data/spec/runner_dsl_spec.rb +23 -0
  38. data/spec/scenario_context_spec.rb +51 -0
  39. data/spec/scenario_runner_spec.rb +79 -0
  40. data/spec/spec_helper.rb +1 -3
  41. data/spec/step_definition_spec.rb +22 -34
  42. data/spec/step_loader_spec.rb +29 -0
  43. data/spec/step_module_spec.rb +106 -0
  44. data/spec/table_spec.rb +8 -1
  45. data/turnip.gemspec +2 -1
  46. metadata +51 -7
@@ -1,5 +1,3 @@
1
1
  RSpec.configure do |config|
2
- config.before(:each, :turnip => true) do
3
- require File.expand_path('../examples/steps', File.dirname(__FILE__))
4
- end
2
+ Turnip::Config.step_dirs = 'examples'
5
3
  end
@@ -1,63 +1,46 @@
1
1
  describe Turnip::StepDefinition do
2
- after do
3
- Turnip::StepDefinition.all.clear
4
- end
5
-
6
- describe ".add" do
7
- it "adds a step definition to the list of definitions" do
8
- Turnip::StepDefinition.add "this is a test"
9
- Turnip::StepDefinition.all.first.expression.should eq("this is a test")
10
- end
11
- end
2
+ let(:all_steps) { [] }
12
3
 
13
4
  describe ".find" do
14
5
  it "returns a step definition that matches the description" do
15
- Turnip::StepDefinition.add "there are :count monsters"
16
- Turnip::StepDefinition.find("there are 23 monsters").expression.should eq("there are :count monsters")
17
- end
18
-
19
- it "respects the for option" do
20
- Turnip::StepDefinition.add "alignment", :for => [:evil]
21
- Turnip::StepDefinition.add "alignment", :for => [:good]
22
- Turnip::StepDefinition.find("alignment", :evil => true, :bad => true).options[:for].should == [:evil]
6
+ all_steps << Turnip::StepDefinition.new("there are :count monsters")
7
+ Turnip::StepDefinition.find(all_steps, "there are 23 monsters").expression.should eq("there are :count monsters")
23
8
  end
24
9
 
25
10
  it "raises an error if the match is ambiguous" do
26
- Turnip::StepDefinition.add "there are :count monsters"
27
- Turnip::StepDefinition.add "there are 23 monsters"
28
- expect { Turnip::StepDefinition.find("there are 23 monsters") }.to raise_error(Turnip::StepDefinition::Ambiguous)
11
+ all_steps << Turnip::StepDefinition.new("there are :count monsters")
12
+ all_steps << Turnip::StepDefinition.new("there are 23 monsters")
13
+ expect { Turnip::StepDefinition.find(all_steps, "there are 23 monsters") }.to raise_error(Turnip::StepDefinition::Ambiguous)
29
14
  end
30
15
 
31
16
  it "raises an error if there is no match" do
32
- expect { Turnip::StepDefinition.find("there are 23 monsters") }.to raise_error(Turnip::StepDefinition::Pending)
17
+ expect { Turnip::StepDefinition.find(all_steps, "there are 23 monsters") }.to raise_error(Turnip::StepDefinition::Pending)
33
18
  end
34
19
  end
35
20
 
36
21
  describe ".execute" do
22
+ let(:context) { stub }
23
+
37
24
  it "executes a step in the given context" do
38
- context = stub(:example => stub(:metadata => {}))
39
- Turnip::StepDefinition.add("there are :count monsters") { @testing = 123 }
40
- Turnip::StepDefinition.execute(context, stub(:description => "there are 23 monsters", :extra_arg => nil))
25
+ all_steps << Turnip::StepDefinition.new("there are :count monsters") { @testing = 123 }
26
+ Turnip::StepDefinition.execute(context, all_steps, stub(:description => "there are 23 monsters", :extra_arg => nil))
41
27
  context.instance_variable_get(:@testing).should == 123
42
28
  end
43
29
 
44
30
  it "tells the context that the step is pending" do
45
- context = stub(:example => stub(:metadata => {}))
46
31
  context.should_receive(:pending).with("the step 'there are 23 monsters' is not implemented")
47
- Turnip::StepDefinition.execute(context, stub(:description => "there are 23 monsters", :extra_arg => nil))
32
+ Turnip::StepDefinition.execute(context, all_steps, stub(:description => "there are 23 monsters", :extra_arg => nil))
48
33
  end
49
34
 
50
35
  it "sends along arguments" do
51
- context = stub(:example => stub(:metadata => {}))
52
- Turnip::StepDefinition.add("there are :count monsters") { |count| @testing = count.to_i }
53
- Turnip::StepDefinition.execute(context, stub(:description => "there are 23 monsters", :extra_arg => nil))
36
+ all_steps << Turnip::StepDefinition.new("there are :count monsters") { |count| @testing = count.to_i }
37
+ Turnip::StepDefinition.execute(context, all_steps, stub(:description => "there are 23 monsters", :extra_arg => nil))
54
38
  context.instance_variable_get(:@testing).should == 23
55
39
  end
56
40
 
57
41
  it "sends along extra arguments" do
58
- context = stub(:example => stub(:metadata => {}))
59
- Turnip::StepDefinition.add("there are :count monsters") { |count, extra| @testing = extra }
60
- Turnip::StepDefinition.execute(context, stub(:description => "there are 23 monsters", :extra_arg => 'foo'))
42
+ all_steps << Turnip::StepDefinition.new("there are :count monsters") { |count, extra| @testing = extra }
43
+ Turnip::StepDefinition.execute(context, all_steps, stub(:description => "there are 23 monsters", :extra_arg => 'foo'))
61
44
  context.instance_variable_get(:@testing).should == 'foo'
62
45
  end
63
46
  end
@@ -77,6 +60,12 @@ describe Turnip::StepDefinition do
77
60
  step.should match("there are 324 monsters")
78
61
  step.should_not match("there are no monsters")
79
62
  end
63
+
64
+ it "matches quoted placeholders" do
65
+ step = Turnip::StepDefinition.new("there is a monster named :name") {}
66
+ step.should match("there is a monster named 'Scary'")
67
+ step.should match('there is a monster named "Hairy"')
68
+ end
80
69
 
81
70
  it "matches alternative words" do
82
71
  step = Turnip::StepDefinition.new("there is/are monsters") {}
@@ -115,4 +104,3 @@ describe Turnip::StepDefinition do
115
104
  end
116
105
  end
117
106
  end
118
-
@@ -0,0 +1,29 @@
1
+ require 'turnip/step_loader'
2
+
3
+ describe Turnip::StepLoader do
4
+ describe '.load_steps' do
5
+ context 'when the steps have not been loaded' do
6
+ before { Turnip::StepLoader.steps_loaded = false }
7
+
8
+ it 'loads all the steps' do
9
+ Turnip::StepLoader.should_receive :load_step_files
10
+ Turnip::StepLoader.load_steps
11
+ end
12
+
13
+ it 'marks the steps as loaded' do
14
+ Turnip::StepLoader.stub :load_step_files
15
+ Turnip::StepLoader.load_steps
16
+ Turnip::StepLoader.should be_steps_loaded
17
+ end
18
+ end
19
+
20
+ context 'when the steps have been loaded' do
21
+ before { Turnip::StepLoader.steps_loaded = true }
22
+
23
+ it 'does not reload all the steps' do
24
+ Turnip::StepLoader.should_not_receive :load_step_files
25
+ Turnip::StepLoader.load_steps
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,106 @@
1
+ describe Turnip::StepModule do
2
+ before(:each) do
3
+ Turnip::StepModule.clear_module_registry
4
+ end
5
+
6
+ describe '.modules_for' do
7
+ it 'returns the unique registered modules' do
8
+ Turnip::StepModule.steps_for(:first) {}
9
+ Turnip::StepModule.steps_for(:second) {}
10
+ Turnip::StepModule.modules_for(:first, :second).size.should eq(2)
11
+ end
12
+
13
+ it 'returns the unique registered modules with use_steps' do
14
+ Turnip::StepModule.steps_for(:first) {}
15
+ Turnip::StepModule.steps_for(:second) { use_steps :first }
16
+ Turnip::StepModule.steps_for(:third) { use_steps :first, :second }
17
+ Turnip::StepModule.modules_for(:third).size.should eq(3)
18
+ end
19
+
20
+ it 'ignores a circular step dependency' do
21
+ Turnip::StepModule.steps_for(:first) { use_steps :second }
22
+ Turnip::StepModule.steps_for(:second) { use_steps :first }
23
+ expect do
24
+ Turnip::StepModule.modules_for(:second)
25
+ end.should_not raise_error
26
+ end
27
+
28
+ it 'orders the step modules from use_steps before the using step module' do
29
+ Turnip::StepModule.steps_for(:first) {}
30
+ Turnip::StepModule.steps_for(:second) { use_steps :first }
31
+ Turnip::StepModule.modules_for(:second).first.should == Turnip::StepModule.module_registry[:first].first.step_module
32
+ Turnip::StepModule.modules_for(:second).last.should == Turnip::StepModule.module_registry[:second].first.step_module
33
+ end
34
+ end
35
+
36
+ describe '.steps_for' do
37
+ it 'registers the given tag' do
38
+ Turnip::StepModule.steps_for(:first) {}
39
+ Turnip::StepModule.should be_registered(:first)
40
+ end
41
+
42
+ it 'registers an anonymous modle for the given tags' do
43
+ Turnip::StepModule.steps_for(:first) {}
44
+ Turnip::StepModule.module_registry[:first].first.step_module.should be_instance_of(Module)
45
+ end
46
+
47
+ end
48
+
49
+ describe '.step_module' do
50
+ subject do
51
+ Turnip::StepModule.step_module do
52
+ def marker; end
53
+ end
54
+ end
55
+
56
+ it 'extends the steps DSL' do
57
+ subject.should be_kind_of(Turnip::StepModule::DSL)
58
+ end
59
+
60
+ it 'creates an anonymous module' do
61
+ # Check for empty string to allow for rbx
62
+ subject.name.should satisfy {|name| name.nil? || name.empty? }
63
+ end
64
+
65
+ it 'executes the block in the module' do
66
+ # Map to sym to allow for rbx
67
+ subject.instance_methods.map(&:to_sym).should include(:marker)
68
+ end
69
+ end
70
+
71
+ describe Turnip::StepModule::DSL do
72
+ describe '.step' do
73
+ it 'registers the step for the module' do
74
+ mod = Module.new do
75
+ extend Turnip::StepModule::DSL
76
+ step('example') { true }
77
+ end
78
+ mod.steps.first.expression.should eq('example')
79
+ end
80
+ end
81
+
82
+ describe '.placeholder' do
83
+ before { Turnip::Placeholder.send(:placeholders).clear }
84
+
85
+ it 'registers the placeholder globally' do
86
+ mod = Module.new do
87
+ extend Turnip::StepModule::DSL
88
+ placeholder('example') { true }
89
+ end
90
+ Turnip::Placeholder.send(:placeholders).should have_key('example')
91
+ end
92
+ end
93
+
94
+ describe '.use_steps' do
95
+ it "updates the list of used steps" do
96
+ mod = Module.new do
97
+ extend Turnip::StepModule::DSL
98
+ step('example') { true }
99
+
100
+ use_steps :other_steps
101
+ end
102
+ mod.uses_steps.should include(:other_steps)
103
+ end
104
+ end
105
+ end
106
+ end
@@ -30,7 +30,7 @@ describe Turnip::Table do
30
30
  end
31
31
 
32
32
  describe '#hashes' do
33
- it 'returns a list of hashe based on the headers' do
33
+ it 'returns a list of hashes based on the headers' do
34
34
  table = Turnip::Table.new([['foo', 'bar'], ['moo', '55'], ['quox', '42']])
35
35
  table.hashes.should == [
36
36
  {'foo' => 'moo', 'bar' => '55'},
@@ -38,6 +38,13 @@ describe Turnip::Table do
38
38
  ]
39
39
  end
40
40
  end
41
+
42
+ describe '#rows_hash' do
43
+ it 'converts this table into a Hash where the first column is used as keys and the second column is used as values' do
44
+ table = Turnip::Table.new([['foo', 'moo'], ['bar', '55']])
45
+ table.rows_hash.should == {'foo' => 'moo', 'bar' => '55'}
46
+ end
47
+ end
41
48
 
42
49
  describe '#map' do
43
50
  it 'iterates over the raw table' do
@@ -19,5 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency "rspec", "~>2.0"
22
- s.add_runtime_dependency "gherkin"
22
+ s.add_runtime_dependency "gherkin", ">= 2.5"
23
+ s.add_development_dependency "rake"
23
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-05 00:00:00.000000000 Z
12
+ date: 2012-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152642360 !ruby/object:Gem::Requirement
16
+ requirement: &2160891520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,18 +21,29 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152642360
24
+ version_requirements: *2160891520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: gherkin
27
- requirement: &2152641940 !ruby/object:Gem::Requirement
27
+ requirement: &2160890740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '2.5'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152641940
35
+ version_requirements: *2160890740
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2160890120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2160890120
36
47
  description: Provides the ability to define steps and run Gherkin files from with
37
48
  RSpec
38
49
  email:
@@ -43,36 +54,62 @@ extra_rdoc_files: []
43
54
  files:
44
55
  - .gitignore
45
56
  - .rspec
57
+ - .travis.yml
46
58
  - Gemfile
47
59
  - README.md
48
60
  - Rakefile
61
+ - examples/alignment_steps.rb
49
62
  - examples/ambiguous.feature
63
+ - examples/autoload_steps.feature
64
+ - examples/autoload_steps.rb
50
65
  - examples/backgrounds.feature
66
+ - examples/dragon_steps.rb
67
+ - examples/evil_steps.rb
51
68
  - examples/interpolation.feature
69
+ - examples/knight_steps.rb
70
+ - examples/more_steps.rb
52
71
  - examples/multiline_string.feature
72
+ - examples/neutral_steps.rb
53
73
  - examples/pending.feature
74
+ - examples/red_dragon_steps.rb
54
75
  - examples/scenario_outline.feature
55
76
  - examples/simple_feature.feature
77
+ - examples/step_calling.feature
78
+ - examples/step_calling_steps.rb
56
79
  - examples/steps.rb
57
80
  - examples/steps_for.feature
81
+ - examples/steps_for_super.feature
58
82
  - examples/table.feature
59
83
  - examples/tags.feature
60
84
  - examples/with_comments.feature
61
85
  - lib/turnip.rb
62
86
  - lib/turnip/builder.rb
63
87
  - lib/turnip/capybara.rb
88
+ - lib/turnip/config.rb
64
89
  - lib/turnip/dsl.rb
90
+ - lib/turnip/feature_file.rb
65
91
  - lib/turnip/loader.rb
66
92
  - lib/turnip/placeholder.rb
93
+ - lib/turnip/runner_dsl.rb
94
+ - lib/turnip/scenario_context.rb
95
+ - lib/turnip/scenario_runner.rb
67
96
  - lib/turnip/step_definition.rb
97
+ - lib/turnip/step_loader.rb
98
+ - lib/turnip/step_module.rb
68
99
  - lib/turnip/table.rb
69
100
  - lib/turnip/version.rb
70
101
  - spec/builder_spec.rb
71
102
  - spec/dsl_spec.rb
103
+ - spec/feature_file_spec.rb
72
104
  - spec/integration_spec.rb
73
105
  - spec/placeholder_spec.rb
106
+ - spec/runner_dsl_spec.rb
107
+ - spec/scenario_context_spec.rb
108
+ - spec/scenario_runner_spec.rb
74
109
  - spec/spec_helper.rb
75
110
  - spec/step_definition_spec.rb
111
+ - spec/step_loader_spec.rb
112
+ - spec/step_module_spec.rb
76
113
  - spec/table_spec.rb
77
114
  - turnip.gemspec
78
115
  homepage: ''
@@ -102,8 +139,15 @@ summary: Gherkin extension for RSpec
102
139
  test_files:
103
140
  - spec/builder_spec.rb
104
141
  - spec/dsl_spec.rb
142
+ - spec/feature_file_spec.rb
105
143
  - spec/integration_spec.rb
106
144
  - spec/placeholder_spec.rb
145
+ - spec/runner_dsl_spec.rb
146
+ - spec/scenario_context_spec.rb
147
+ - spec/scenario_runner_spec.rb
107
148
  - spec/spec_helper.rb
108
149
  - spec/step_definition_spec.rb
150
+ - spec/step_loader_spec.rb
151
+ - spec/step_module_spec.rb
109
152
  - spec/table_spec.rb
153
+ has_rdoc: