Skip to content

Commit

Permalink
Fix moar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Divins and Josep M. Bach authored and Josep M. Bach committed Nov 11, 2011
1 parent 63849db commit 82b8344
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 194 deletions.
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
24 changes: 12 additions & 12 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 Down Expand Up @@ -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
28 changes: 6 additions & 22 deletions lib/spinach/generators/feature_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,23 @@ module Generators
# given the parsed feture data
class FeatureGenerator

# @param [Hash] data
# the parsed feature data returned from the {Parser}
def initialize(data)
@data = data
# @param [Feature] feature
# The feature returned from the {Parser}
def initialize(feature)
@feature = feature
end

# @return [Array<Hash>]
# an array of unique steps found in this scenario, avoiding name
# repetition
def steps
return @steps if @steps
@steps = []
if scenarios = @data['elements']
scenarios.each do |scenario|
if scenario_steps = scenario['steps']
scenario_steps.each do |step|
unless @steps.any?{|s| s['name'] == step['name']}
@steps << {
'keyword' => step['keyword'].strip,
'name' => step['name'].strip
}
end
end
end
end
end
@steps
@feature.scenarios.map(&:steps).flatten.uniq(&:name)
end

# @return [String]
# this feature's name
def name
@data['name'].strip if @data['name']
@feature.name
end

# @return [String]
Expand Down
10 changes: 5 additions & 5 deletions lib/spinach/generators/step_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ module Spinach
#
class Generators::StepGenerator

# @param [Hash] data
# the parsed step data returned from the {Parser}
def initialize(data)
@data = data
# @param [Step] step
# The step.
def initialize(step)
@step = step
end

# @return [String]
# an example step definition
def generate
result = StringIO.new
result.puts "#{@data['keyword']} '#{Spinach::Support.escape_single_commas @data['name']}' do"
result.puts "Given '#{Spinach::Support.escape_single_commas @step.name}' do"
result.puts " raise 'step not implemented'"
result.puts "end"
result.string
Expand Down
6 changes: 3 additions & 3 deletions lib/spinach/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class Scenario
attr_accessor :name, :steps, :tags, :feature

def initialize(feature)
@feature = feature
@scenarios = []
@tags = []
@feature = feature
@steps = []
@tags = []
end
end
end
18 changes: 9 additions & 9 deletions test/spinach/capybara_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def go_home
@feature_runner = Spinach::Runner::FeatureRunner.new(
'a_feature.feature')

@feature_runner.stubs(data: Spinach::Parser.new('
Feature: A test feature
Scenario: A test scenario
Given Hello
Then Goodbye
Scenario: Another test scenario
Given Hello
Then Goodbye
').parse).at_least_once
@feature_runner.stubs(data: Spinach::Parser.new("""
Feature: A test feature
Scenario: A test scenario
Given Hello
Then Goodbye
Scenario: Another test scenario
Given Hello
Then Goodbye
""").parse).at_least_once

Spinach::Runner::ScenarioRunner.any_instance.stubs(feature_steps: @feature)

Expand Down
Loading

0 comments on commit 82b8344

Please sign in to comment.