Skip to content

Commit

Permalink
Merge pull request codegram#74 from codegram/refactor/c_gherkin_must_die
Browse files Browse the repository at this point in the history
Use gherkin-ruby and an abstract object layer rather than C-Gherkin
  • Loading branch information
Josep M. Bach committed Nov 11, 2011
2 parents 4a543cb + 0b18f64 commit bb0f055
Show file tree
Hide file tree
Showing 52 changed files with 828 additions and 578 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ source 'http://rubygems.org'
# Specify your gem's dependencies in spinach.gemspec
gemspec

gem 'rake'

group :test do
gem 'guard'
gem 'guard-minitest'
Expand Down
17 changes: 7 additions & 10 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ use it with RSpec as well if you put the following in `features/support/env.rb`:
Now create a `features` folder in your app or library and write your first
feature:

## features/test_how_spinach_works.feature

Feature: Test how spinach works
In order to know what the heck is spinach
As a developer
Expand All @@ -62,7 +60,7 @@ scaffolding for you:

Spinach will detect your features and generate the following class:

## features/steps/test_how_spinach_works.rb
## features/steps/test_how_spinach_works.rb

class TestHowSpinachWorks < Spinach::FeatureSteps
Given 'I have an empty array' do
Expand Down Expand Up @@ -131,7 +129,7 @@ use private methods, mix in modules or whatever!
if name.length > 1
puts "Hello, mr. #{name.join(' ')}"
else
puts "Yo, #{name.first}! Whassup?"
puts "Yo, #{name.first}! Whassup?"
end
end
end
Expand All @@ -145,12 +143,12 @@ after any feature, scenario or step execution.

So, for example, you could:

Spinach.hooks.before_scenario do |data|
Spinach.hooks.before_scenario do |scenario|
clear_database
end

Spinach.hooks.on_successful_step do |step_data, location|
count_steps(step_data)
Spinach.hooks.on_successful_step do |step, location|
count_steps(step.scenario.steps)
end

Spinach.hooks.after_run do |status|
Expand All @@ -161,7 +159,6 @@ Full hook documentation is here:

[Spinach's hook documentation on rubydoc](http://rubydoc.info/github/codegram/spinach/master/Spinach/Hooks)


## Wanna use it with Rails 3?

Use [spinach-rails](http://github.com/codegram/spinach-rails)
Expand All @@ -188,7 +185,6 @@ Check out our [spinach-sinatra demo](https://github.com/codegram/spinach-sinatra
* [spinach rails demo](https://github.com/codegram/spinach-rails-demo)
* [spinach sinatra demo](https://github.com/codegram/spinach-sinatra-demo)


## Contributing

* [List of spinach contributors](https://github.com/codegram/spinach/contributors)
Expand All @@ -205,10 +201,11 @@ You can easily contribute to Spinach. Its codebase is simple and
in a commit by itself I can ignore when I pull.
* Send me a pull request. Bonus points for topic branches.

[gherkin]: http://github.com/cucumber/gherkin
[gherkin]: http://github.com/codegram/gherkin-ruby
[cucumber]: http://github.com/cucumber/cucumber
[documentation]: http://rubydoc.info/github/codegram/spinach/master/frames

## License

MIT License. Copyright 2011 [Codegram Technologies](http://codegram.com)

13 changes: 7 additions & 6 deletions features/steps/automatic_feature_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ class AutomaticFeatureGeneration < Spinach::FeatureSteps

include Integration::SpinachRunner
Given 'I have defined a "Cheezburger can I has" feature' do
write_file('features/cheezburger_can_i_has.feature',
'Feature: Cheezburger can I has
Scenario: Some Lulz
Given I haz a sad
When I get some lulz
Then I haz a happy')
write_file('features/cheezburger_can_i_has.feature', """
Feature: Cheezburger can I has
Scenario: Some Lulz
Given I haz a sad
When I get some lulz
Then I haz a happy
""")
end

When 'I run spinach with "--generate"' do
Expand Down
20 changes: 10 additions & 10 deletions features/steps/exit_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class ExitStatus < Spinach::FeatureSteps
include Integration::SpinachRunner

Given "I have a feature that has no error or failure" do
write_file('features/success_feature.feature',
'Feature: A success feature
write_file('features/success_feature.feature', """
Feature: A success feature
Scenario: This is scenario will succeed
Then I succeed
')
Scenario: This is scenario will succeed
Then I succeed
""")
write_file('features/steps/success_feature.rb',
'class ASuccessFeature < Spinach::FeatureSteps
feature "A success feature"
Expand All @@ -21,12 +21,12 @@ class ExitStatus < Spinach::FeatureSteps
end

Given "I have a feature that has a failure" do
write_file('features/failure_feature.feature',
'Feature: A failure feature
write_file('features/failure_feature.feature', """
Feature: A failure feature
Scenario: This is scenario will fail
Then I fail
')
Scenario: This is scenario will fail
Then I fail
""")
write_file('features/steps/failure_feature.rb',
'class AFailureFeature < Spinach::FeatureSteps
feature "A failure feature"
Expand Down
12 changes: 6 additions & 6 deletions features/steps/feature_name_guessing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class FeatureNameGuessing < Spinach::FeatureSteps
include Integration::SpinachRunner

Given 'I am writing a feature called "My cool feature"' do
write_file('features/my_cool_feature.feature',
'Feature: My cool feature
write_file('features/my_cool_feature.feature', """
Feature: My cool feature
Scenario: This is scenario is cool
When this is so meta
Then the world is crazy
')
Scenario: This is scenario is cool
When this is so meta
Then the world is crazy
""")
end

And 'I write a class named "MyCoolFeature"' do
Expand Down
40 changes: 21 additions & 19 deletions features/steps/reporting/display_run_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ class DisplayRunSummary < Spinach::FeatureSteps
include Integration::SpinachRunner

Given "I have a feature that has some successful, undefined, failed and error steps" do
write_file('features/test_feature.feature',
'Feature: A test feature
Scenario: Undefined scenario
Given I am a fool
When I jump from Codegrams roof
Then I must be pwned by floor
Scenario: Failed scenario
Given I love risk
When I jump from Codegrams roof
Then my parachute must open
Then I must not be pwned by floor
Scenario: Error scenario
Given I am not a fool
When I go downstairs
Then I must succeed
')
write_file('features/test_feature.feature', """
Feature: A test feature
Scenario: Undefined scenario
Given I am a fool
When I jump from Codegrams roof
Then I must be pwned by floor
Scenario: Failed scenario
Given I love risk
When I jump from Codegrams roof
Then my parachute must open
Then I must not be pwned by floor
Scenario: Error scenario
Given I am not a fool
When I go downstairs
Then I must succeed
""")

write_file('features/steps/test_feature.rb',
'class ATestFeature < Spinach::FeatureSteps
feature "A test feature"
Expand Down
12 changes: 6 additions & 6 deletions features/steps/reporting/error_reporting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class ErrorReporting < Spinach::FeatureSteps
include Integration::ErrorReporting

Given "I have a feature with some failures" do
write_file('features/feature_with_failures.feature',
'Feature: Feature with failures
write_file('features/feature_with_failures.feature', """
Feature: Feature with failures
Scenario: This scenario will fail
Given true is false
Then remove all the files in my hard drive
')
Scenario: This scenario will fail
Given true is false
Then remove all the files in my hard drive
""")

write_file('features/steps/failure_feature.rb',
'class FeatureWithFailures < Spinach::FeatureSteps
Expand Down
44 changes: 24 additions & 20 deletions features/steps/reporting/show_step_source_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class ShowStepSourceLocation < Spinach::FeatureSteps
include Integration::SpinachRunner

Given "I have a feature that has no error or failure" do
write_file('features/success_feature.feature',
'Feature: A success feature
write_file('features/success_feature.feature', """
Feature: A success feature
Scenario: This is scenario will succeed
Then I succeed
""")

Scenario: This is scenario will succeed
Then I succeed
')
write_file('features/steps/success_feature.rb',
'class ASuccessFeature < Spinach::FeatureSteps
feature "A success feature"
Expand All @@ -31,12 +32,13 @@ class ShowStepSourceLocation < Spinach::FeatureSteps
end

Given "I have a feature that has no error or failure and use external steps" do
write_file('features/success_feature.feature',
'Feature: A feature that uses external steps
write_file('features/success_feature.feature', """
Feature: A feature that uses external steps
Scenario: This is scenario will succeed
Given this is a external step
""")

Scenario: This is scenario will succeed
Given this is a external step
')
write_file('features/steps/success_feature.rb',
'class AFeatureThatUsesExternalSteps < Spinach::FeatureSteps
feature "A feature that uses external steps"
Expand All @@ -58,12 +60,13 @@ class ShowStepSourceLocation < Spinach::FeatureSteps
end

Given "I have a feature that has an error" do
write_file('features/error_feature.feature',
'Feature: An error feature
write_file('features/error_feature.feature', """
Feature: An error feature
Scenario: This is scenario will not succeed
Then I do not succeed
""")

Scenario: This is scenario will not succeed
Then I do not succeed
')
write_file('features/steps/error_feature.rb',
'class AnErrorFeature < Spinach::FeatureSteps
feature "An error feature"
Expand All @@ -81,12 +84,13 @@ class ShowStepSourceLocation < Spinach::FeatureSteps
end

Given "I have a feature that has a failure" do
write_file('features/failure_feature.feature',
'Feature: A failure feature
write_file('features/failure_feature.feature', """
Feature: A failure feature
Scenario: This is scenario will not succeed
Then I do not succeed
""")

Scenario: This is scenario will not succeed
Then I do not succeed
')
write_file('features/steps/failure_feature.rb',
'class AFailureFeature < Spinach::FeatureSteps
feature "A failure feature"
Expand Down
12 changes: 6 additions & 6 deletions features/steps/reporting/undefined_feature_reporting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class UndefinedFeatureReporting < Spinach::FeatureSteps
include Integration::SpinachRunner

Given "I've written a feature but not its steps" do
write_file('features/feature_without_steps.feature',
'Feature: Feature without steps
write_file('features/feature_without_steps.feature', """
Feature: Feature without steps
Scenario: A scenario without steps
Given I have no steps
Then I should do nothing
')
Scenario: A scenario without steps
Given I have no steps
Then I should do nothing
""")
end

When "I run spinach" do
Expand Down
26 changes: 13 additions & 13 deletions features/steps/rspec_compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class RSpecCompatibility < Spinach::FeatureSteps
include Integration::ErrorReporting

Given "I have a feature with some failed expectations" do
write_file('features/feature_with_failures.feature',
'Feature: Feature with failures
write_file('features/feature_with_failures.feature', """
Feature: Feature with failures
Scenario: This scenario will fail
Given true is false
Then remove all the files in my hard drive
')
Scenario: This scenario will fail
Given true is false
Then remove all the files in my hard drive
""")

write_file('features/steps/failure_feature.rb',
'class FeatureWithFailures < Spinach::FeatureSteps
Expand All @@ -30,7 +30,7 @@ class RSpecCompatibility < Spinach::FeatureSteps

When "I run \"spinach\" with rspec" do
@feature =
run_feature "features/#{@feature}.feature", suite: :rspec
run_feature "features/#{@feature}.feature", framework: :rspec
end

Then "I should see the failure count along with their messages" do
Expand All @@ -49,13 +49,13 @@ class RSpecCompatibility < Spinach::FeatureSteps
Capybara.app = app
')

write_file('features/greeting.feature',
'Feature: Greeting
write_file('features/greeting.feature', """
Feature: Greeting
Scenario: Greeting
Given I am on the front page
Then I should see hello world
')
Scenario: Greeting
Given I am on the front page
Then I should see hello world
""")

write_file('features/steps/greeting.rb',
'require "spinach/capybara"
Expand Down
6 changes: 3 additions & 3 deletions features/support/spinach_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def self.included(base)
end

def run_feature(command, options={})
options[:suite] ||= :minitest
use_minitest if options[:suite] == :minitest
use_rspec if options[:suite] == :rspec
options[:framework] ||= :minitest
use_minitest if options[:framework] == :minitest
use_rspec if options[:framework] == :rspec
run "../../bin/spinach #{command} #{options[:append]}"
end

Expand Down
Loading

0 comments on commit bb0f055

Please sign in to comment.