spinach 0.1.5.4 → 0.2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Gemfile +2 -0
  2. data/README.markdown +18 -12
  3. data/features/background.feature +13 -0
  4. data/features/reporting/show_step_source_location.feature +11 -1
  5. data/features/steps/automatic_feature_generation.rb +7 -7
  6. data/features/steps/background.rb +30 -0
  7. data/features/steps/exit_status.rb +12 -13
  8. data/features/steps/feature_name_guessing.rb +7 -7
  9. data/features/steps/reporting/display_run_summary.rb +22 -22
  10. data/features/steps/reporting/error_reporting.rb +7 -7
  11. data/features/steps/reporting/show_step_source_location.rb +63 -14
  12. data/features/steps/reporting/undefined_feature_reporting.rb +7 -7
  13. data/features/steps/rspec_compatibility.rb +14 -14
  14. data/features/support/error_reporting.rb +5 -5
  15. data/features/support/filesystem.rb +71 -0
  16. data/features/support/spinach_runner.rb +5 -6
  17. data/lib/spinach.rb +11 -6
  18. data/lib/spinach/background.rb +11 -0
  19. data/lib/spinach/capybara.rb +7 -1
  20. data/lib/spinach/cli.rb +36 -13
  21. data/lib/spinach/config.rb +40 -6
  22. data/lib/spinach/dsl.rb +14 -11
  23. data/lib/spinach/exceptions.rb +1 -1
  24. data/lib/spinach/feature.rb +16 -0
  25. data/lib/spinach/frameworks.rb +2 -0
  26. data/lib/spinach/{suites → frameworks}/minitest.rb +0 -0
  27. data/lib/spinach/{suites → frameworks}/rspec.rb +0 -0
  28. data/lib/spinach/generators/feature_generator.rb +12 -23
  29. data/lib/spinach/generators/step_generator.rb +5 -5
  30. data/lib/spinach/hookable.rb +6 -4
  31. data/lib/spinach/hooks.rb +12 -4
  32. data/lib/spinach/parser.rb +6 -8
  33. data/lib/spinach/parser/visitor.rb +109 -0
  34. data/lib/spinach/reporter.rb +10 -6
  35. data/lib/spinach/reporter/stdout.rb +41 -16
  36. data/lib/spinach/reporter/stdout/error_reporting.rb +2 -2
  37. data/lib/spinach/runner.rb +9 -6
  38. data/lib/spinach/runner/feature_runner.rb +40 -34
  39. data/lib/spinach/runner/scenario_runner.rb +63 -36
  40. data/lib/spinach/scenario.rb +12 -0
  41. data/lib/spinach/step.rb +10 -0
  42. data/lib/spinach/version.rb +1 -1
  43. data/spinach.gemspec +3 -3
  44. data/test/spinach/background_test.rb +6 -0
  45. data/test/spinach/capybara_test.rb +30 -13
  46. data/test/spinach/cli_test.rb +46 -1
  47. data/test/spinach/config_test.rb +39 -0
  48. data/test/spinach/dsl_test.rb +12 -10
  49. data/test/spinach/feature_steps_test.rb +3 -3
  50. data/test/spinach/feature_test.rb +6 -0
  51. data/test/spinach/{suites → frameworks}/minitest_test.rb +2 -2
  52. data/test/spinach/generators/feature_generator_test.rb +18 -58
  53. data/test/spinach/generators/step_generator_test.rb +3 -3
  54. data/test/spinach/generators_test.rb +12 -10
  55. data/test/spinach/hookable_test.rb +8 -0
  56. data/test/spinach/hooks_test.rb +6 -7
  57. data/test/spinach/parser/visitor_test.rb +173 -0
  58. data/test/spinach/parser_test.rb +14 -27
  59. data/test/spinach/reporter/stdout/error_reporting_test.rb +9 -9
  60. data/test/spinach/reporter/stdout_test.rb +15 -19
  61. data/test/spinach/reporter_test.rb +15 -0
  62. data/test/spinach/runner/feature_runner_test.rb +79 -69
  63. data/test/spinach/runner/scenario_runner_test.rb +118 -92
  64. data/test/spinach/runner_test.rb +10 -6
  65. data/test/spinach/scenario_test.rb +6 -0
  66. data/test/spinach/step_test.rb +6 -0
  67. data/test/spinach_test.rb +7 -7
  68. metadata +60 -39
  69. data/lib/spinach/suites.rb +0 -2
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source 'http://rubygems.org'
3
3
  # Specify your gem's dependencies in spinach.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'rake'
7
+
6
8
  group :test do
7
9
  gem 'guard'
8
10
  gem 'guard-minitest'
data/README.markdown CHANGED
@@ -35,8 +35,6 @@ use it with RSpec as well if you put the following in `features/support/env.rb`:
35
35
  Now create a `features` folder in your app or library and write your first
36
36
  feature:
37
37
 
38
- ## features/test_how_spinach_works.feature
39
-
40
38
  Feature: Test how spinach works
41
39
  In order to know what the heck is spinach
42
40
  As a developer
@@ -62,7 +60,7 @@ scaffolding for you:
62
60
 
63
61
  Spinach will detect your features and generate the following class:
64
62
 
65
- ## features/steps/test_how_spinach_works.rb
63
+ ## features/steps/test_how_spinach_works.rb
66
64
 
67
65
  class TestHowSpinachWorks < Spinach::FeatureSteps
68
66
  Given 'I have an empty array' do
@@ -102,7 +100,7 @@ use private methods, mix in modules or whatever!
102
100
  end
103
101
  end
104
102
 
105
- Then 'the output should contain a formal salutation' do
103
+ Then 'the output should contain a formal greeting' do
106
104
  @output.must_include "Hello, mr. John Doe"
107
105
  end
108
106
 
@@ -110,14 +108,14 @@ use private methods, mix in modules or whatever!
110
108
  @array += ["John"]
111
109
  end
112
110
 
113
- Then 'the output should contain a casual salutation' do
111
+ Then 'the output should contain a casual greeting' do
114
112
  @output.must_include "Yo, John! Whassup?"
115
113
  end
116
114
 
117
115
  private
118
116
 
119
117
  def capture_output
120
- out = StreamIO.new
118
+ out = StringIO.new
121
119
  $stdout = out
122
120
  $stderr = out
123
121
  yield
@@ -126,6 +124,15 @@ use private methods, mix in modules or whatever!
126
124
  out.string
127
125
  end
128
126
  end
127
+ module Greeter
128
+ def self.greet(name)
129
+ if name.length > 1
130
+ puts "Hello, mr. #{name.join(' ')}"
131
+ else
132
+ puts "Yo, #{name.first}! Whassup?"
133
+ end
134
+ end
135
+ end
129
136
 
130
137
  Then run your feature again running `spinach` and watch it all turn green! :)
131
138
 
@@ -136,12 +143,12 @@ after any feature, scenario or step execution.
136
143
 
137
144
  So, for example, you could:
138
145
 
139
- Spinach.hooks.before_scenario do |data|
146
+ Spinach.hooks.before_scenario do |scenario|
140
147
  clear_database
141
148
  end
142
149
 
143
- Spinach.hooks.on_successful_step do |step_data, location|
144
- count_steps(step_data)
150
+ Spinach.hooks.on_successful_step do |step, location|
151
+ count_steps(step.scenario.steps)
145
152
  end
146
153
 
147
154
  Spinach.hooks.after_run do |status|
@@ -152,7 +159,6 @@ Full hook documentation is here:
152
159
 
153
160
  [Spinach's hook documentation on rubydoc](http://rubydoc.info/github/codegram/spinach/master/Spinach/Hooks)
154
161
 
155
-
156
162
  ## Wanna use it with Rails 3?
157
163
 
158
164
  Use [spinach-rails](http://github.com/codegram/spinach-rails)
@@ -179,7 +185,6 @@ Check out our [spinach-sinatra demo](https://github.com/codegram/spinach-sinatra
179
185
  * [spinach rails demo](https://github.com/codegram/spinach-rails-demo)
180
186
  * [spinach sinatra demo](https://github.com/codegram/spinach-sinatra-demo)
181
187
 
182
-
183
188
  ## Contributing
184
189
 
185
190
  * [List of spinach contributors](https://github.com/codegram/spinach/contributors)
@@ -196,10 +201,11 @@ You can easily contribute to Spinach. Its codebase is simple and
196
201
  in a commit by itself I can ignore when I pull.
197
202
  * Send me a pull request. Bonus points for topic branches.
198
203
 
199
- [gherkin]: http://github.com/cucumber/gherkin
204
+ [gherkin]: http://github.com/codegram/gherkin-ruby
200
205
  [cucumber]: http://github.com/cucumber/cucumber
201
206
  [documentation]: http://rubydoc.info/github/codegram/spinach/master/frames
202
207
 
203
208
  ## License
204
209
 
205
210
  MIT License. Copyright 2011 [Codegram Technologies](http://codegram.com)
211
+
@@ -0,0 +1,13 @@
1
+ Feature: Background
2
+ In order to avoid duplication of Steps in Scenarios
3
+ As a developer
4
+ I want to describe the background Steps once
5
+
6
+ Background:
7
+ Given Spinach has Background support
8
+
9
+ Scenario: Using Background
10
+ And another step in this scenario
11
+ When I run this Scenario
12
+ Then the background step should have been executed
13
+ And the scenario step should have been executed
@@ -3,7 +3,7 @@ Feature: Show step source location
3
3
  I want spinach to give me every step source location in output
4
4
  So I can easyly know where I defined a step
5
5
 
6
- Scenario: Show class steps source location in output
6
+ Scenario: Show class steps source location in output when all is ok
7
7
  Given I have a feature that has no error or failure
8
8
  When I run it
9
9
  Then I should see the source location of each step of every scenario
@@ -12,3 +12,13 @@ Feature: Show step source location
12
12
  Given I have a feature that has no error or failure and use external steps
13
13
  When I run it
14
14
  Then I should see the source location of each step, even external ones
15
+
16
+ Scenario: Show class steps source location in output even when there is an error
17
+ Given I have a feature that has an error
18
+ When I run it
19
+ Then I should see the source location of each step, even ones with errors
20
+
21
+ Scenario: Show class steps source location in output even when there is a failure
22
+ Given I have a feature that has a failure
23
+ When I run it
24
+ Then I should see the source location of each step, even ones with failures
@@ -4,12 +4,13 @@ class AutomaticFeatureGeneration < Spinach::FeatureSteps
4
4
 
5
5
  include Integration::SpinachRunner
6
6
  Given 'I have defined a "Cheezburger can I has" feature' do
7
- write_file('features/cheezburger_can_i_has.feature',
8
- 'Feature: Cheezburger can I has
9
- Scenario: Some Lulz
10
- Given I haz a sad
11
- When I get some lulz
12
- Then I haz a happy')
7
+ write_file('features/cheezburger_can_i_has.feature', """
8
+ Feature: Cheezburger can I has
9
+ Scenario: Some Lulz
10
+ Given I haz a sad
11
+ When I get some lulz
12
+ Then I haz a happy
13
+ """)
13
14
  end
14
15
 
15
16
  When 'I run spinach with "--generate"' do
@@ -17,7 +18,6 @@ class AutomaticFeatureGeneration < Spinach::FeatureSteps
17
18
  end
18
19
 
19
20
  Then 'I a feature should exist named "features/steps/cheezburger_can_i_has.rb"' do
20
- stop_processes!
21
21
  in_current_dir do
22
22
  @file = 'features/steps/cheezburger_can_i_has.rb'
23
23
  File.exists?(@file).must_equal true
@@ -0,0 +1,30 @@
1
+ class Background < Spinach::FeatureSteps
2
+
3
+ feature 'Background'
4
+
5
+ def initialize
6
+ @background_step = false
7
+ @scenario_step = false
8
+ end
9
+
10
+ And 'another step in this scenario' do
11
+ @scenario_step = true
12
+ end
13
+
14
+ When 'I run this Scenario' do
15
+ # Nothing to be done.
16
+ end
17
+
18
+ Then 'the background step should have been executed' do
19
+ @background_step.must_equal true
20
+ end
21
+
22
+ Then 'the scenario step should have been executed' do
23
+ @scenario_step.must_equal true
24
+ end
25
+
26
+ Given 'Spinach has Background support' do
27
+ @background_step = true
28
+ end
29
+
30
+ end
@@ -5,12 +5,12 @@ class ExitStatus < Spinach::FeatureSteps
5
5
  include Integration::SpinachRunner
6
6
 
7
7
  Given "I have a feature that has no error or failure" do
8
- write_file('features/success_feature.feature',
9
- 'Feature: A success feature
8
+ write_file('features/success_feature.feature', """
9
+ Feature: A success feature
10
10
 
11
- Scenario: This is scenario will succeed
12
- Then I succeed
13
- ')
11
+ Scenario: This is scenario will succeed
12
+ Then I succeed
13
+ """)
14
14
  write_file('features/steps/success_feature.rb',
15
15
  'class ASuccessFeature < Spinach::FeatureSteps
16
16
  feature "A success feature"
@@ -21,12 +21,12 @@ class ExitStatus < Spinach::FeatureSteps
21
21
  end
22
22
 
23
23
  Given "I have a feature that has a failure" do
24
- write_file('features/failure_feature.feature',
25
- 'Feature: A failure feature
24
+ write_file('features/failure_feature.feature', """
25
+ Feature: A failure feature
26
26
 
27
- Scenario: This is scenario will fail
28
- Then I fail
29
- ')
27
+ Scenario: This is scenario will fail
28
+ Then I fail
29
+ """)
30
30
  write_file('features/steps/failure_feature.rb',
31
31
  'class AFailureFeature < Spinach::FeatureSteps
32
32
  feature "A failure feature"
@@ -39,14 +39,13 @@ class ExitStatus < Spinach::FeatureSteps
39
39
 
40
40
  When "I run it" do
41
41
  run_feature @feature
42
- all_stdout # Hack to get a correct exit status
43
42
  end
44
43
 
45
44
  Then "the exit status should be 0" do
46
- last_exit_status.must_equal 0
45
+ @last_exit_status.must_equal 0
47
46
  end
48
47
 
49
48
  Then "the exit status should be 1" do
50
- last_exit_status.must_equal 1
49
+ @last_exit_status.must_equal 1
51
50
  end
52
51
  end
@@ -5,13 +5,13 @@ class FeatureNameGuessing < Spinach::FeatureSteps
5
5
  include Integration::SpinachRunner
6
6
 
7
7
  Given 'I am writing a feature called "My cool feature"' do
8
- write_file('features/my_cool_feature.feature',
9
- 'Feature: My cool feature
8
+ write_file('features/my_cool_feature.feature', """
9
+ Feature: My cool feature
10
10
 
11
- Scenario: This is scenario is cool
12
- When this is so meta
13
- Then the world is crazy
14
- ')
11
+ Scenario: This is scenario is cool
12
+ When this is so meta
13
+ Then the world is crazy
14
+ """)
15
15
  end
16
16
 
17
17
  And 'I write a class named "MyCoolFeature"' do
@@ -30,6 +30,6 @@ class FeatureNameGuessing < Spinach::FeatureSteps
30
30
  end
31
31
 
32
32
  Then 'I want "MyCoolFeature" class to be used to run it' do
33
- last_exit_status.must_equal 0
33
+ @last_exit_status.must_equal 0
34
34
  end
35
35
  end
@@ -1,5 +1,3 @@
1
- require 'aruba/api'
2
-
3
1
  class DisplayRunSummary < Spinach::FeatureSteps
4
2
 
5
3
  feature 'automatic'
@@ -7,25 +5,27 @@ class DisplayRunSummary < Spinach::FeatureSteps
7
5
  include Integration::SpinachRunner
8
6
 
9
7
  Given "I have a feature that has some successful, undefined, failed and error steps" do
10
- write_file('features/test_feature.feature',
11
- 'Feature: A test feature
12
-
13
- Scenario: Undefined scenario
14
- Given I am a fool
15
- When I jump from Codegrams roof
16
- Then I must be pwned by floor
17
-
18
- Scenario: Failed scenario
19
- Given I love risk
20
- When I jump from Codegrams roof
21
- Then my parachute must open
22
- Then I must not be pwned by floor
23
-
24
- Scenario: Error scenario
25
- Given I am not a fool
26
- When I go downstairs
27
- Then I must succeed
28
- ')
8
+ write_file('features/test_feature.feature', """
9
+
10
+ Feature: A test feature
11
+
12
+ Scenario: Undefined scenario
13
+ Given I am a fool
14
+ When I jump from Codegrams roof
15
+ Then I must be pwned by floor
16
+
17
+ Scenario: Failed scenario
18
+ Given I love risk
19
+ When I jump from Codegrams roof
20
+ Then my parachute must open
21
+ Then I must not be pwned by floor
22
+
23
+ Scenario: Error scenario
24
+ Given I am not a fool
25
+ When I go downstairs
26
+ Then I must succeed
27
+ """)
28
+
29
29
  write_file('features/steps/test_feature.rb',
30
30
  'class ATestFeature < Spinach::FeatureSteps
31
31
  feature "A test feature"
@@ -65,7 +65,7 @@ class DisplayRunSummary < Spinach::FeatureSteps
65
65
  end
66
66
 
67
67
  Then "I should see a summary with steps status information" do
68
- all_stdout.must_match(
68
+ @stdout.must_match(
69
69
  /Summary:.*4.*Successful.*1.*Undefined.*1.*Failed.*1.*Error/
70
70
  )
71
71
  end
@@ -6,13 +6,13 @@ class ErrorReporting < Spinach::FeatureSteps
6
6
  include Integration::ErrorReporting
7
7
 
8
8
  Given "I have a feature with some failures" do
9
- write_file('features/feature_with_failures.feature',
10
- 'Feature: Feature with failures
9
+ write_file('features/feature_with_failures.feature', """
10
+ Feature: Feature with failures
11
11
 
12
- Scenario: This scenario will fail
13
- Given true is false
14
- Then remove all the files in my hard drive
15
- ')
12
+ Scenario: This scenario will fail
13
+ Given true is false
14
+ Then remove all the files in my hard drive
15
+ """)
16
16
 
17
17
  write_file('features/steps/failure_feature.rb',
18
18
  'class FeatureWithFailures < Spinach::FeatureSteps
@@ -38,7 +38,7 @@ class ErrorReporting < Spinach::FeatureSteps
38
38
 
39
39
  Then 'I should see the failure count along with their messages' do
40
40
  check_error_messages(1)
41
- all_stderr.wont_match /gems.*minitest.*assert_equal/
41
+ @all_stderr.wont_match /gems.*minitest.*assert_equal/
42
42
  end
43
43
 
44
44
  Then 'I should see the error count along with their messages and backtrace' do
@@ -1,5 +1,3 @@
1
- require 'aruba/api'
2
-
3
1
  class ShowStepSourceLocation < Spinach::FeatureSteps
4
2
 
5
3
  feature "Show step source location"
@@ -7,12 +5,13 @@ class ShowStepSourceLocation < Spinach::FeatureSteps
7
5
  include Integration::SpinachRunner
8
6
 
9
7
  Given "I have a feature that has no error or failure" do
10
- write_file('features/success_feature.feature',
11
- 'Feature: A success feature
8
+ write_file('features/success_feature.feature', """
9
+ Feature: A success feature
10
+
11
+ Scenario: This is scenario will succeed
12
+ Then I succeed
13
+ """)
12
14
 
13
- Scenario: This is scenario will succeed
14
- Then I succeed
15
- ')
16
15
  write_file('features/steps/success_feature.rb',
17
16
  'class ASuccessFeature < Spinach::FeatureSteps
18
17
  feature "A success feature"
@@ -27,18 +26,19 @@ class ShowStepSourceLocation < Spinach::FeatureSteps
27
26
  end
28
27
 
29
28
  Then "I should see the source location of each step of every scenario" do
30
- all_stdout.must_match(
29
+ @stdout.must_match(
31
30
  /I succeed.*features\/steps\/success_feature\.rb.*3/
32
31
  )
33
32
  end
34
33
 
35
34
  Given "I have a feature that has no error or failure and use external steps" do
36
- write_file('features/success_feature.feature',
37
- 'Feature: A feature that uses external steps
35
+ write_file('features/success_feature.feature', """
36
+ Feature: A feature that uses external steps
37
+
38
+ Scenario: This is scenario will succeed
39
+ Given this is a external step
40
+ """)
38
41
 
39
- Scenario: This is scenario will succeed
40
- Given this is a external step
41
- ')
42
42
  write_file('features/steps/success_feature.rb',
43
43
  'class AFeatureThatUsesExternalSteps < Spinach::FeatureSteps
44
44
  feature "A feature that uses external steps"
@@ -54,8 +54,57 @@ class ShowStepSourceLocation < Spinach::FeatureSteps
54
54
  end
55
55
 
56
56
  Then "I should see the source location of each step, even external ones" do
57
- all_stdout.must_match(
57
+ @stdout.must_match(
58
58
  /this is a external step.*features\/support\/external_steps\.rb.*3/
59
59
  )
60
60
  end
61
+
62
+ Given "I have a feature that has an error" do
63
+ write_file('features/error_feature.feature', """
64
+ Feature: An error feature
65
+
66
+ Scenario: This is scenario will not succeed
67
+ Then I do not succeed
68
+ """)
69
+
70
+ write_file('features/steps/error_feature.rb',
71
+ 'class AnErrorFeature < Spinach::FeatureSteps
72
+ feature "An error feature"
73
+ Then "I do not succeed" do
74
+ i_do_not_exist.must_be_equal "Your Mumma"
75
+ end
76
+ end')
77
+ @feature = "features/error_feature.feature"
78
+ end
79
+
80
+ Then "I should see the source location of each step, even ones with errors" do
81
+ @stdout.must_match(
82
+ /I do not succeed.*features\/steps\/error_feature\.rb.*3/
83
+ )
84
+ end
85
+
86
+ Given "I have a feature that has a failure" do
87
+ write_file('features/failure_feature.feature', """
88
+ Feature: A failure feature
89
+
90
+ Scenario: This is scenario will not succeed
91
+ Then I do not succeed
92
+ """)
93
+
94
+ write_file('features/steps/failure_feature.rb',
95
+ 'class AFailureFeature < Spinach::FeatureSteps
96
+ feature "A failure feature"
97
+ Then "I do not succeed" do
98
+ i_exist = "Your Pappa"
99
+ i_exist.must_be_equal "Your Mumma"
100
+ end
101
+ end')
102
+ @feature = "features/failure_feature.feature"
103
+ end
104
+
105
+ Then "I should see the source location of each step, even ones with failures" do
106
+ @stdout.must_match(
107
+ /I do not succeed.*features\/steps\/failure_feature\.rb.*3/
108
+ )
109
+ end
61
110
  end