aslakhellesoy-cucumber 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Manifest.txt +22 -10
  2. data/README.textile +147 -17
  3. data/README.txt +41 -0
  4. data/config/hoe.rb +1 -1
  5. data/examples/calculator/features/addition.feature +7 -7
  6. data/examples/calculator/features/division.feature +3 -4
  7. data/examples/calculator/features/steps/{addition_steps.rb → calculator_steps.rb} +0 -1
  8. data/examples/calculator/lib/calculator.rb +2 -4
  9. data/examples/{pure_ruby → calculator_ruby_features}/Rakefile +0 -0
  10. data/examples/{pure_ruby → calculator_ruby_features}/features/addition.rb +2 -2
  11. data/examples/{pure_ruby/features/steps/addition_steps.rb → calculator_ruby_features/features/steps/calculator_steps.rb} +0 -0
  12. data/examples/java/src/cucumber/demo/Hello.java +1 -1
  13. data/examples/{simple_norwegian → norwegian_calculator}/Rakefile +0 -0
  14. data/examples/{simple_norwegian/features/steps/matte_steg.rb.rb → norwegian_calculator/features/kalkulator_steps.rb} +2 -2
  15. data/examples/{simple_norwegian → norwegian_calculator}/features/summering.feature +4 -4
  16. data/examples/{web → watir}/Rakefile +0 -0
  17. data/examples/{web → watir}/features/search.feature +1 -1
  18. data/examples/{web → watir}/features/steps/stories_steps.rb +4 -4
  19. data/gem_tasks/gemspec.rake +6 -0
  20. data/generators/cucumber/cucumber_generator.rb +20 -0
  21. data/generators/cucumber/templates/common_webrat.rb +30 -0
  22. data/generators/cucumber/templates/cucumber.rake +7 -0
  23. data/generators/cucumber/templates/env.rb +6 -0
  24. data/generators/feature/feature_generator.rb +17 -0
  25. data/generators/feature/templates/feature.erb +27 -0
  26. data/generators/feature/templates/steps.erb +22 -0
  27. data/lib/cucumber.rb +9 -1
  28. data/lib/cucumber/cli.rb +13 -8
  29. data/lib/cucumber/executor.rb +0 -4
  30. data/lib/cucumber/formatters/html_formatter.rb +1 -0
  31. data/lib/cucumber/formatters/pretty_formatter.rb +15 -5
  32. data/lib/cucumber/languages.yml +1 -1
  33. data/lib/cucumber/rails/rspec.rb +12 -0
  34. data/lib/cucumber/rails/world.rb +18 -16
  35. data/lib/cucumber/rake/task.rb +17 -14
  36. data/lib/cucumber/step_methods.rb +3 -1
  37. data/lib/cucumber/tree/scenario.rb +6 -0
  38. data/lib/cucumber/tree/step.rb +8 -0
  39. data/lib/cucumber/treetop_parser/feature.treetop.erb +10 -6
  40. data/lib/cucumber/treetop_parser/feature_en.rb +132 -81
  41. data/lib/cucumber/treetop_parser/feature_fr.rb +136 -85
  42. data/lib/cucumber/treetop_parser/feature_no.rb +132 -81
  43. data/lib/cucumber/treetop_parser/feature_pt.rb +132 -81
  44. data/lib/cucumber/version.rb +1 -1
  45. data/spec/cucumber/treetop_parser/feature_parser_spec.rb +40 -0
  46. data/spec/cucumber/treetop_parser/spaces.feature +10 -0
  47. metadata +25 -12
data/Manifest.txt CHANGED
@@ -2,6 +2,7 @@ History.txt
2
2
  License.txt
3
3
  Manifest.txt
4
4
  README.textile
5
+ README.txt
5
6
  Rakefile
6
7
  TODO.txt
7
8
  bin/cucumber
@@ -10,8 +11,11 @@ config/requirements.rb
10
11
  examples/calculator/Rakefile
11
12
  examples/calculator/features/addition.feature
12
13
  examples/calculator/features/division.feature
13
- examples/calculator/features/steps/addition_steps.rb
14
+ examples/calculator/features/steps/calculator_steps.rb
14
15
  examples/calculator/lib/calculator.rb
16
+ examples/calculator_ruby_features/Rakefile
17
+ examples/calculator_ruby_features/features/addition.rb
18
+ examples/calculator_ruby_features/features/steps/calculator_steps.rb
15
19
  examples/java/README.textile
16
20
  examples/java/Rakefile
17
21
  examples/java/features/hello.feature
@@ -19,21 +23,26 @@ examples/java/features/steps/hello_steps.rb
19
23
  examples/java/features/steps/tree_steps.rb
20
24
  examples/java/features/tree.feature
21
25
  examples/java/src/cucumber/demo/Hello.java
22
- examples/pure_ruby/Rakefile
23
- examples/pure_ruby/features/addition.rb
24
- examples/pure_ruby/features/steps/addition_steps.rb
25
- examples/simple_norwegian/Rakefile
26
- examples/simple_norwegian/features/steps/matte_steg.rb.rb
27
- examples/simple_norwegian/features/summering.feature
28
- examples/web/Rakefile
29
- examples/web/features/search.feature
30
- examples/web/features/steps/stories_steps.rb
26
+ examples/norwegian_calculator/Rakefile
27
+ examples/norwegian_calculator/features/kalkulator_steps.rb
28
+ examples/norwegian_calculator/features/summering.feature
29
+ examples/watir/Rakefile
30
+ examples/watir/features/search.feature
31
+ examples/watir/features/steps/stories_steps.rb
31
32
  gem_tasks/deployment.rake
32
33
  gem_tasks/environment.rake
33
34
  gem_tasks/fix_cr_lf.rake
35
+ gem_tasks/gemspec.rake
34
36
  gem_tasks/rspec.rake
35
37
  gem_tasks/treetop.rake
36
38
  gem_tasks/website.rake
39
+ generators/cucumber/cucumber_generator.rb
40
+ generators/cucumber/templates/common_webrat.rb
41
+ generators/cucumber/templates/cucumber.rake
42
+ generators/cucumber/templates/env.rb
43
+ generators/feature/feature_generator.rb
44
+ generators/feature/templates/feature.erb
45
+ generators/feature/templates/steps.erb
37
46
  lib/cucumber.rb
38
47
  lib/cucumber/cli.rb
39
48
  lib/cucumber/core_ext/proc.rb
@@ -45,6 +54,7 @@ lib/cucumber/formatters/html_formatter.rb
45
54
  lib/cucumber/formatters/pretty_formatter.rb
46
55
  lib/cucumber/formatters/progress_formatter.rb
47
56
  lib/cucumber/languages.yml
57
+ lib/cucumber/rails/rspec.rb
48
58
  lib/cucumber/rails/world.rb
49
59
  lib/cucumber/rake/task.rb
50
60
  lib/cucumber/step_methods.rb
@@ -78,6 +88,8 @@ spec/cucumber/formatters/ansicolor_spec.rb
78
88
  spec/cucumber/formatters/features.html
79
89
  spec/cucumber/formatters/html_formatter_spec.rb
80
90
  spec/cucumber/sell_cucumbers.feature
91
+ spec/cucumber/treetop_parser/feature_parser_spec.rb
92
+ spec/cucumber/treetop_parser/spaces.feature
81
93
  spec/spec.opts
82
94
  spec/spec_helper.rb
83
95
  website/index.html
data/README.textile CHANGED
@@ -1,13 +1,19 @@
1
1
  h1. Cucumber
2
2
 
3
- "Cucumber":http://github.com/aslakhellesoy/cucumber is a tool that can execute documentation written in plain text. Cucumber targets non technical domain experts as well as
4
- programmers and QA people. Cucumber itself is written in Ruby, but it can be used to "test" code written in Ruby, Java
5
- (or web applications written in any language). When "IronRuby":http://www.ironruby.net/ matures it can be used to "test"
6
- .NET code too.
3
+ "Cucumber":http://github.com/aslakhellesoy/cucumber is a tool that can execute feature documentation written in plain text.
4
+ Cucumber targets non technical business analysts, interaction designers, domain experts, testers (for the plain text part)
5
+ and programmers (for the steps, which are written in Ruby).
7
6
 
8
- While Cucumber can be thought of as a "testing" tool, most people use it to support "BDD":http://behaviour-driven.org/, so
9
- the "tests" are typically the first thing that gets written, and the production code is then written outside-in, to make
10
- the test pass.
7
+ Cucumber itself is also written in Ruby, but it can be used to "test" code written in Ruby, Java (or web applications written
8
+ in any language). When "IronRuby":http://www.ironruby.net/ matures it can be used to "test" .NET code too.
9
+
10
+ Cucumber only requires minimal use of Ruby programming, so don't be afraid to try it out even if the code you're
11
+ developing is in a different language. Most programmers should pick up the required Ruby skills and be productive
12
+ with Cucumber in a few of days.
13
+
14
+ While Cucumber can be thought of as a "testing" tool, the intent of the tool is to support "BDD":http://behaviour-driven.org/
15
+ This means that the "tests" (plain text feature descriptions with scenarios) are typically written before anything else, and
16
+ the production code is then written outside-in, to make them pass.
11
17
 
12
18
  h2. Installation
13
19
 
@@ -25,16 +31,132 @@ jruby -S gem install aslakhellesoy-cucumber
25
31
 
26
32
  h2. Getting started
27
33
 
28
- I haven't written a tutorial yet. Take a look at the "examples":http://github.com/aslakhellesoy/cucumber/tree/master/examples.
29
- Each example directory has a Rakefile, and you can run the features with
34
+ There are several ways to get started, depending on the architecture of your application.
35
+ Take a look at the "examples":http://github.com/aslakhellesoy/cucumber/tree/master/examples.
36
+ Each example directory has a Rakefile, and you can run the features in an example directory with
37
+
38
+ <pre><code>rake features</code></pre>
39
+
40
+ The examples deliberately have errors so you can get a taste of how the error output looks like. You can get help by asking
41
+ for it:
42
+
43
+ <pre><code>cucumber --help</code></pre>
44
+
45
+ h2. Ruby on Rails
46
+
47
+ Cucumber has very nice Rails support, and I really recommend using "Webrat":http://github.com/brynary/webrat
48
+ in the step definitions. Here is how to get you started.
49
+
50
+ h3. Install Cucumber, Webrat and RSpec
51
+
52
+ <pre><code>git submodule add cucumber git://github.com/aslakhellesoy/cucumber.git vendor/plugins/cucumber
53
+ git submodule add webrat git://github.com/brynary/webrat.git vendor/plugins/webrat
54
+ git submodule add rspec git://github.com/dchelimsky/rspec.git vendor/plugins/rspec
55
+ git submodule add rspec-rails git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec-rails
56
+ </code></pre>
57
+
58
+ If your own Rails code is not in Git, just replace "submodule add" with "clone".
59
+
60
+ h3. Install Other dependencies
61
+
62
+ <pre><code>gem install hpricot cucumber</code></pre>
63
+
64
+ Yes, you did already install cucumber as a plugin, but this will install all the dependent libraries you need.
65
+
66
+ h3. Bootstrap Cucumber
67
+
68
+ You'll need a Rake task and a couple of files that configure Cucumber for use with Ruby on Rails and Webrat.
69
+ You create these with:
70
+
71
+ <pre><code>ruby script/generate cucumber</code></pre>
72
+
73
+ Check out the generated files. If you need to, you can go and tweak them later.
74
+
75
+ h3. Start a feature
76
+
77
+ It's really, really recommended that you write your features by hand - in collaboration with your
78
+ customer / business analyst / domain expert / interaction designer. However, to get you started (and so you can see how to use
79
+ Webrat), you can use the feature generator to generate the first few features:
80
+
81
+ <pre><code>ruby script/generate feature Frooble name color description</code></pre>
82
+
83
+ This will generate a simple plain text feature with associated steps. Don't get addicted to this
84
+ generator - you're better off writing these by hand in the long run. See the BDD tips section below.
85
+
86
+ h3. Run features
30
87
 
31
88
  <pre><code>rake features</code></pre>
32
89
 
90
+ This should result in failing scenarios, because you haven't written any code yet (I hope). Now you it's time
91
+ to write some code, or generate some. Try this:
92
+
93
+ <pre><code>script/generate rspec_scaffold Frooble name:string color:string description:text
94
+ rake db:migrate
95
+ rake features
96
+ </code></pre>
97
+
98
+ h3. Tips
99
+
100
+ These tips apply to Rails development in general...
101
+
102
+ * Talk to models directly in *Given* steps to set up a known state. Don't use fixtures.
103
+ * Use Webrat in *When* steps
104
+ * Use *response.should have_tag(...)* (and models) in *Then* steps to verify the *outcomes* (which are on the screen, not only in the database).
105
+ * Organise steps in files named accordingly to resources used
106
+ * Avoid keeping state in @variables in steps. It will couple your steps and make them harder to reuse.
107
+
108
+ h3. View spec redundancy
109
+
110
+ Since I recommend you verify outcomes (*Then* steps) by looking at the HTML, you might end up having some degree
111
+ of redundancy with view specs. I recommend you delete generated view specs if you run into too much maintenance
112
+ headaches and rely on the features instead of view specs. However, in some cases it can be handy to use both.
113
+
114
+ h2. BDD
115
+
116
+ If you have found a bug or want to add a feature, start by writing a new feature or scenario that describes the
117
+
118
+ Now run the features again. The one you wrote should have yellow, pending steps - or failing, red ones.
119
+ (If you don't get that you're doing something wrong, or the feature is already implemented).
120
+
121
+ This is when you start writing code. You might as well get used to doing it this way, because we won't accept
122
+ any patches unless you also have stories or specs for your code. This is because we don't want to end up with a
123
+ brittle, unmaintainable, undocumented pile of code that nobody understands. (Yes, stores and specs are *documentation* too).
124
+
125
+ If you think this sounds annoying, try it out anyway. You'll end up writing better (and less) code this way. Trust me.
126
+ Work outside-in (the outside being the story, the inside being the low level code). Do it the "BDD":http://en.wikipedia.org/wiki/Behavior_driven_development way.
127
+
128
+ h3. Business value and MMF
129
+
130
+ You should discuss the "In order to" part of the feature and pop the "why" stack max 5 times (ask why recursively)
131
+ until you end up with one of the following business values:
132
+
133
+ * Protect revenue
134
+ * Increase revenue
135
+ * Manage cost
136
+
137
+ If you're about to implement a feature that doesn't support one of those values, chances are you're about to
138
+ implement a non-valuable feature. Consider tossing it altogether or pushing it down in your backlog. Focus on
139
+ implementing the MMFs (Minimal Marketable Features) that will yield the most value.
140
+
141
+ h3. Outcomes and bottom-up scenarios.
142
+
143
+ The value provided by a system is what you can get out of it - not what you put into it. Just like the value
144
+ is expressed at the top of a feature (In order to...), the value should be in the steps of a scenarios too,
145
+ more precicely in the *Then* steps.
146
+
147
+ When you're writing a new scenario, I recommend you start with the formulation of the desired outcome. Write the
148
+ *Then* steps first. Then write the *When* step to discover the action/operation and finally write the *Given*
149
+ steps that need to be in place in order for the When/Then to make sense.
150
+
33
151
  h2. Background and Credits
34
152
 
35
153
  Cucumber is a rewrite of RSpec's "Story runner", which was originally written by Dan North. Dan's original
36
154
  implementation required that stories be written in Ruby. Shortly after, David Chelimsky added
37
- "plain text":http://blog.davidchelimsky.net/articles/2007/10/21/story-runner-in-plain-english support.
155
+ "plain text":http://blog.davidchelimsky.net/articles/2007/10/21/story-runner-in-plain-english support with
156
+ contributions from half a dozen other people.
157
+
158
+ The business value guidelines and general wording in features is based on several conversations and blog posts
159
+ by Chris Matts, Liz Keogh and Dan North.
38
160
 
39
161
  This brought executable stories a little closer to non-technical users, which is one of the target audiences
40
162
  for this kind of tool.
@@ -49,13 +171,21 @@ Some of the biggest problems with it are:
49
171
  * Limited colouring of output.
50
172
  * No simple way to execute only one scenario.
51
173
  * No command line tool to run stories.
174
+ * No easy before or after hooks.
175
+
176
+ While all of this could have been fixed in the existing codebase, I figured it would be easier to do a rewrite from scratch.
177
+ I also had some ideas for extensions of the story grammar (like FIT style tables that you can see in some of the examples),
178
+ so I decided to base it on a proper
179
+ "grammar":http://github.com/aslakhellesoy/cucumber/tree/master/lib/cucumber/treetop_parser/feature.treetop.erb using
180
+ "Treetop":http://treetop.rubyforge.org/.
52
181
 
53
- While all of this could have been fixed in the existing codebase, I figured it would be easier to do a rewrite from scratch.
54
- I also had some ideas for extensions of the story grammar, so I decided to use "Treetop":http://treetop.rubyforge.org/
55
- and base it on a proper "grammar":http://github.com/aslakhellesoy/cucumber/tree/master/lib/cucumber/treetop_parser/feature.treetop.erb
182
+ Cucumber addresses all of the above mentioned shortcomings of RSpec's Story runner.
183
+ If the community likes it, perhaps it will replace the RSpec story runner - either by
184
+ being assumed into RSpec proper, or remaining a separate tool like now.
56
185
 
57
- Cucumber addresses all of the shortcomings of RSpec's Story runner. If the community likes it, we'll consider phasing out
58
- the RSpec story runner.
186
+ The term "Feature" has been adopted in favour of "Story" because I believe it is a more
187
+ appropriate term. A feature's scenarios typically grow over time - fed by several user
188
+ stories.
59
189
 
60
- The term "Feature" has been adopted in favour of "Story" because I believe it is a more appropriate term. A feature's scenarios
61
- typically increases over time - fed by several user stories.
190
+ The name Cucumber means absolutely nothing, it was suggested by my girlfriend who was eating a cucumber sandwich
191
+ while I started to write it.
data/README.txt ADDED
@@ -0,0 +1,41 @@
1
+ = Cucumber
2
+
3
+ * http://github.com/aslakhellesoy/cucumber
4
+
5
+ == DESCRIPTION:
6
+
7
+ Cucumber executes plain text documentation of code against that code.
8
+
9
+ == REQUIREMENTS:
10
+
11
+ * FIX (list of requirements)
12
+
13
+ == INSTALL:
14
+
15
+ * gem sources --add http://gems.github.com/
16
+ * gem install aslakhellesoy-cucumber
17
+
18
+ == LICENSE:
19
+
20
+ (The MIT License)
21
+
22
+ Copyright (c) 2008 Aslak Hellesøy
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining
25
+ a copy of this software and associated documentation files (the
26
+ 'Software'), to deal in the Software without restriction, including
27
+ without limitation the rights to use, copy, modify, merge, publish,
28
+ distribute, sublicense, and/or sell copies of the Software, and to
29
+ permit persons to whom the Software is furnished to do so, subject to
30
+ the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be
33
+ included in all copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
36
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
38
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
39
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
40
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/config/hoe.rb CHANGED
@@ -34,7 +34,7 @@ VERS = Cucumber::VERSION::STRING + (REV ? ".#{REV}" : "")
34
34
  RDOC_OPTS = ['--quiet', '--title', 'Cucumber documentation',
35
35
  "--opname", "index.html",
36
36
  "--line-numbers",
37
- "--main", "README",
37
+ "--main", "README.textile",
38
38
  "--inline-source"]
39
39
 
40
40
  class Hoe
@@ -1,16 +1,16 @@
1
1
  Feature: Addition
2
+ In order to avoid silly mistakes
2
3
  As a math idiot
3
4
  I want to be told the sum of two numbers
4
- So that I don't make silly mistakes
5
5
 
6
6
  Scenario: Add two numbers
7
7
  Given I have entered 50 into the calculator
8
8
  And I have entered 70 into the calculator
9
- When I add
10
- Then the result should be 121 on the screen
9
+ When I press add
10
+ Then the result should be 130 on the screen
11
11
  And the result class should be Fixnum
12
12
 
13
- | input_1 | input_2 | output | class |
14
- | 20 | 30 | 50 | Fixnum |
15
- | 2 | 5 | 7 | Fixnum |
16
- | 20 | 40 | 80 | Number |
13
+ | input_1 | input_2 | button | output | class |
14
+ | 20 | 30 | add | 50 | Fixnum |
15
+ | 2 | 5 | add | 7 | Fixnum |
16
+ | 0 | 40 | add | 40 | Fixnum |
@@ -1,7 +1,7 @@
1
1
  Feature: Division
2
- As a math genius
3
- I want to be told the division of two floats
4
- So that I don't make silly mistakes
2
+ In order to avoid silly mistakes
3
+ As a math idiot
4
+ I want to be told the division of two numbers
5
5
 
6
6
  Scenario: Regular numbers
7
7
  Given I have entered 3 into the calculator
@@ -9,4 +9,3 @@ Feature: Division
9
9
  When I press divide
10
10
  Then the result should be 1.5 on the screen
11
11
  And the result class should be Float
12
- And it should rain on Friday
@@ -28,4 +28,3 @@ end
28
28
  Given /it should rain on (\w+)/ do |day|
29
29
  @calc.rain?(day).should == true
30
30
  end
31
-
@@ -1,5 +1,7 @@
1
1
  class Calculator
2
2
  def push(n)
3
+ n += 2 if n == 0 # a really stupiud bug
4
+
3
5
  @args ||= []
4
6
  @args << n
5
7
  end
@@ -11,8 +13,4 @@ class Calculator
11
13
  def divide
12
14
  @args[0].to_f / @args[1].to_f
13
15
  end
14
-
15
- def rain?(day)
16
- true
17
- end
18
16
  end
@@ -1,9 +1,9 @@
1
1
  require 'cucumber/cli' # Needed in order to run the feature with ruby
2
2
 
3
3
  Feature %|Addition
4
+ In order to avoid silly mistakes
4
5
  As a math idiot
5
- I want to be told the sum of two numbers
6
- So that I don't make silly mistakes| do
6
+ I want to be told the sum of two numbers| do
7
7
 
8
8
  Scenario "Add two numbers" do
9
9
  Given "I have entered 50 into the calculator"
@@ -10,6 +10,6 @@ public class Hello {
10
10
  }
11
11
 
12
12
  public String getPhoneNumber(String who) {
13
- return "99999";
13
+ throw new RuntimeException("My phone is secret!");
14
14
  }
15
15
  }
@@ -1,6 +1,6 @@
1
1
  require 'spec'
2
2
 
3
- class Calculator
3
+ class Kalkulator
4
4
  def push(n)
5
5
  @args ||= []
6
6
  @args << n
@@ -12,7 +12,7 @@ class Calculator
12
12
  end
13
13
 
14
14
  Before do
15
- @calc = Calculator.new
15
+ @calc = Kalkulator.new
16
16
  end
17
17
 
18
18
  After do
@@ -1,9 +1,9 @@
1
1
  Egenskap: Summering
2
- Som en matteidiot
3
- Vil jeg bli fortalt summen av to tall
4
- Slik at jeg ikke gjør dumme feil
2
+ For å slippe å gjøre dumme feil
3
+ Som en regnskapsfører
4
+ Vil jeg kunne legge sammen
5
5
 
6
- Scenario: 5+7
6
+ Scenario: to tall
7
7
  Gitt at jeg har tastet inn 5
8
8
  Og at jeg har tastet inn 7
9
9
  Når jeg summerer
File without changes
@@ -1,7 +1,7 @@
1
1
  Feature: Search
2
+ In order to learn more
2
3
  As an information seeker
3
4
  I want to find more information
4
- So that I can learn more
5
5
 
6
6
  Scenario: Find what I'm looking for
7
7
  Given I am on the Google search page