Skip to content

Commit

Permalink
Make core features pass again
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jun 20, 2011
1 parent 7f3fbb0 commit e198713
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
1 change: 0 additions & 1 deletion features/bootstrap.feature
Expand Up @@ -3,7 +3,6 @@ Feature: Bootstrapping a new project
As a new cucumber user
I want cucumber to give helpful error messages in basic situations

@announce
Scenario: running cucumber against a non-existing feature file
Given a directory without standard Cucumber project directory structure
When I run `cucumber`
Expand Down
2 changes: 1 addition & 1 deletion features/cucumber-features
64 changes: 45 additions & 19 deletions features/step_definitions/cucumber-features/core_steps.rb
Expand Up @@ -16,24 +16,39 @@ def write_feature(feature)
write_file("features/a_feature.feature", feature)
end

def write_mappings(mappings)
mapping_code = mappings.raw.map do |pattern, result|
erb = ERB.new(<<-EOF, nil, '-')
Given /<%= pattern -%>/ do
<% if result == 'passing' -%>
File.open("<%= step_file(pattern) %>", "w")
<% elsif result == 'pending' -%>
File.open("<%= step_file(pattern) %>", "w")
pending
<% else -%>
File.open("<%= step_file(pattern) %>", "w")
raise "bang!"
<% end -%>
end
def write_passing_mapping(step_name)
erb = ERB.new(<<-EOF, nil, '-')
Given /<%= step_name -%>/ do
# ARUBA_IGNORE_START
File.open("<%= step_file(step_name) %>", "w")
# ARUBA_IGNORE_END
end
EOF
append_to_file("features/step_definitions/some_stepdefs.rb", erb.result(binding))
end

def write_pending_mapping(step_name)
erb = ERB.new(<<-EOF, nil, '-')
Given /<%= step_name -%>/ do
# ARUBA_IGNORE_START
File.open("<%= step_file(step_name) %>", "w")
# ARUBA_IGNORE_END
pending
end
EOF
append_to_file("features/step_definitions/some_stepdefs.rb", erb.result(binding))
end

def write_failing_mapping(step_name)
erb = ERB.new(<<-EOF, nil, '-')
Given /<%= step_name -%>/ do
# ARUBA_IGNORE_START
File.open("<%= step_file(step_name) %>", "w")
# ARUBA_IGNORE_END
raise "bang!"
end
EOF
erb.result(binding)
end.join("\n")
write_file("features/step_definitions/some_stepdefs.rb", mapping_code)
append_to_file("features/step_definitions/some_stepdefs.rb", erb.result(binding))
end

def write_calculator_code
Expand Down Expand Up @@ -153,8 +168,19 @@ def assert_skipped(pattern)
write_feature(feature)
end

When /^Cucumber executes "([^"]*)" with these step mappings:$/ do |scenario_name, mappings|
write_mappings(mappings)
Given /^the step "([^"]*)" has a passing mapping$/ do |step_name|
write_passing_mapping(step_name)
end

Given /^the step "([^"]*)" has a pending mapping$/ do |step_name|
write_pending_mapping(step_name)
end

Given /^the step "([^"]*)" has a failing mapping$/ do |step_name|
write_failing_mapping(step_name)
end

When /^Cucumber executes the scenario "([^"]*)"$/ do |scenario_name|
run_scenario(scenario_name)
end

Expand Down

0 comments on commit e198713

Please sign in to comment.