Skip to content

Commit

Permalink
Refactored cucumber features a bit so test-setup details are hidden a…
Browse files Browse the repository at this point in the history
…way from scenarios
  • Loading branch information
colszowka committed Sep 12, 2011
1 parent 7a01aa2 commit ed7ded8
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 47 deletions.
3 changes: 1 addition & 2 deletions features/config_adapters.feature
Expand Up @@ -6,8 +6,7 @@ Feature:
that can be loaded at once.

Background:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
"""
Expand Down
5 changes: 2 additions & 3 deletions features/config_autoload.feature
Expand Up @@ -12,19 +12,18 @@ Feature:
by doing a 'require "simplecov"'

Scenario:
Given I cd to "project"
Given a file named ".simplecov" with:
"""
SimpleCov.start do
add_filter 'test.rb'
add_filter 'spec.rb'
end
"""
And a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
"""
And a file named "spec/simplecov_config.rb" with:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
"""
Expand Down
5 changes: 2 additions & 3 deletions features/config_command_name.feature
Expand Up @@ -7,15 +7,14 @@ Feature: Custom names for individual test suites
config can be given a custom command name using SimpleCov.command_name.

Scenario:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
command_name "I'm in UR Unitz"
end
"""
And a file named "spec/simplecov_config.rb" with:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
3 changes: 1 addition & 2 deletions features/config_coverage_dir.feature
Expand Up @@ -7,8 +7,7 @@ Feature:
in your project's root.

Scenario:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
5 changes: 2 additions & 3 deletions features/config_deactivate_merging.feature
Expand Up @@ -9,15 +9,14 @@ Feature:
output directories instead (see SimpleCov.coverage_dir), but it is possible :)

Scenario:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
use_merging false
end
"""
And a file named "spec/simplecov_config.rb" with:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
5 changes: 2 additions & 3 deletions features/config_merge_timeout.feature
Expand Up @@ -13,15 +13,14 @@ Feature:
in the report.

Scenario:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
merge_timeout 1
end
"""
And a file named "spec/simplecov_config.rb" with:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
6 changes: 2 additions & 4 deletions features/config_project_name.feature
Expand Up @@ -5,11 +5,9 @@ Feature:
If this is not sufficient for you, you can specify a custom name using
SimpleCov.project_name('xyz')

Background:
Given I cd to "project"

Scenario: Guessed name
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start
Expand All @@ -19,7 +17,7 @@ Feature:
Then I should see "Code coverage for Project"

Scenario: Custom name
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start { project_name "Superfancy 2.0" }
Expand Down
3 changes: 1 addition & 2 deletions features/config_styles.feature
Expand Up @@ -6,8 +6,7 @@ Feature:
preference or project requirements.

Background:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
"""
Expand Down
3 changes: 1 addition & 2 deletions features/cucumber_basic.feature
Expand Up @@ -5,8 +5,7 @@ Feature:
the user a coverage report after running `cucumber features`

Scenario:
Given I cd to "project"
Given a file named "features/support/simplecov_config.rb" with:
Given SimpleCov for Cucumber is configured with:
"""
require 'simplecov'
SimpleCov.start
Expand Down
5 changes: 2 additions & 3 deletions features/merging_test_unit_and_rspec.feature
Expand Up @@ -6,16 +6,15 @@ Feature:
the joined results of all test suites that are using SimpleCov.

Scenario:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
add_filter 'spec.rb'
end
"""
And a file named "spec/simplecov_config.rb" with:
And SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
3 changes: 1 addition & 2 deletions features/rspec_basic.feature
Expand Up @@ -5,8 +5,7 @@ Feature:
the user a coverage report after running `rspec`

Scenario:
Given I cd to "project"
Given a file named "spec/simplecov_config.rb" with:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start
Expand Down
3 changes: 1 addition & 2 deletions features/rspec_groups_and_filters_basic.feature
Expand Up @@ -5,8 +5,7 @@ Feature:
coverage report that respects those settings after running rspec

Scenario:
Given I cd to "project"
Given a file named "spec/simplecov_config.rb" with:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
3 changes: 1 addition & 2 deletions features/rspec_groups_and_filters_complex.feature
Expand Up @@ -7,8 +7,7 @@ Feature: Sophisticated grouping and filtering on RSpec
to specific groups.

Scenario:
Given I cd to "project"
Given a file named "spec/simplecov_config.rb" with:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
5 changes: 1 addition & 4 deletions features/rspec_without_simplecov.feature
Expand Up @@ -3,15 +3,12 @@ Feature:

Running specs without simplecov configuration

Background:
Given I cd to "project"

Scenario: No config at all
When I successfully run `bundle exec rspec spec`
Then no coverage report should have been generated

Scenario: Configured, but not started
Given a file named "spec/simplecov_config.rb" with:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.configure do
Expand Down
23 changes: 23 additions & 0 deletions features/step_definitions/simplecov_steps.rb
@@ -1,3 +1,26 @@
# Just a shortcut to make framework setup more readable
# The test project is using separate config files to avoid specifying all of
# test/spec_helper in the features every time.
Given /^SimpleCov for (.*) is configured with:$/ do |framework, config_body|
framework_dir = case framework
when /RSpec/i
"spec"
when /Test\/Unit/i
"test"
when /Cucumber/i
"features/support"
else
raise ArgumentError, "Could not identify test framework #{framework}!"
end

steps %Q{
Given a file named "#{framework_dir}/simplecov_config.rb" with:
"""
#{config_body}
"""
}
end

When /^I open the coverage report generated with `([^`]+)`$/ do |command|
steps %Q{
When I successfully run `#{command}`
Expand Down
1 change: 1 addition & 0 deletions features/support/env.rb
Expand Up @@ -23,4 +23,5 @@
FileUtils.rm_rf 'project'
FileUtils.cp_r File.join(this_dir, '../../test/faked_project/'), 'project'
end
Given 'I cd to "project"'
end
3 changes: 1 addition & 2 deletions features/test_unit_basic.feature
Expand Up @@ -5,8 +5,7 @@ Feature:
the user a coverage report after running `rake test`

Scenario:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start
Expand Down
3 changes: 1 addition & 2 deletions features/test_unit_groups_and_filters_basic.feature
Expand Up @@ -5,8 +5,7 @@ Feature:
coverage report that respects those settings after running tests

Scenario:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
3 changes: 1 addition & 2 deletions features/test_unit_groups_and_filters_complex.feature
Expand Up @@ -7,8 +7,7 @@ Feature: Sophisticated grouping and filtering on Test/Unit
to specific groups.

Scenario:
Given I cd to "project"
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
Expand Down
5 changes: 1 addition & 4 deletions features/test_unit_without_simplecov.feature
Expand Up @@ -3,15 +3,12 @@ Feature:

Running unit tests without simplecov configuration

Background:
Given I cd to "project"

Scenario: No config at all
When I successfully run `bundle exec rake test`
Then no coverage report should have been generated

Scenario: Configured, but not started
Given a file named "test/simplecov_config.rb" with:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.configure do
Expand Down

0 comments on commit ed7ded8

Please sign in to comment.