cuke-test 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jarrett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,74 @@
1
+ CukeTest
2
+ =========
3
+
4
+ It can be useful to package commonly-used Cucumber steps as a gem. And every gem needs tests, right? Enter CukeTest.
5
+
6
+ CukeTest helps you test individual Cucumber steps with RSpec, verifying that they pass and fail under the right conditions.
7
+
8
+ Installation
9
+ ============
10
+
11
+ sudo gem install cuke-test
12
+
13
+ Usage
14
+ =====
15
+
16
+ Suppose you've packaged your Cucumber steps into a gem, and the file structure looks like this:
17
+
18
+ my-cuke-steps
19
+ lib
20
+ my-cuke-steps
21
+ steps.rb
22
+ spec
23
+ steps_spec.rb
24
+
25
+ You want to test your custom Cucumber steps in `steps_spec.rb`. Here's how:
26
+
27
+ describe 'My Cuke Steps' do
28
+ before :all do
29
+ CukeTest.config.features_path = File.expand_path(File.dirname(__FILE__)) + '/features'
30
+ end
31
+
32
+ it 'passes when the expectation is met' do
33
+ # Run an entire feature file
34
+ feature('success.feature').should pass_cuke
35
+ # Run just one scenario in a feature file
36
+ scenario('some_successes_and_some_failures.feature', 'successful scenario').should pass_cuke
37
+ end
38
+
39
+ it 'fails when the expectation is not met' do
40
+ feature('failure.feature').should fail_cuke('Text of failing step')
41
+ end
42
+ end
43
+
44
+ Now you need to create the feature files against which the above tests will be run. Put them in `spec/features`. Your new file structure should look like this:
45
+
46
+ my-cuke-steps
47
+ lib
48
+ my-cuke-steps
49
+ steps.rb
50
+ spec
51
+ steps_spec.rb
52
+ features
53
+ failure.feature
54
+ some_successes_and_some_failures.feature
55
+ success.feature
56
+
57
+ The last thing you need to do is tell your specs where to find your custom steps. (Otherwise, the steps you're testing will be undefined.) Fortunately, Cucumber automatically loads `.rb` files in the `features` directory. So we just need to require our step library from a new file within `features`:
58
+
59
+ # in spec/features/steps.rb
60
+ require File.expand_path(File.dirname(__FILE__)) + '../../lib/my-cuke-steps/steps.rb')
61
+
62
+ That's about it for the basic setup. If you're developing a gem where your custom matchers require other code from the same gem (e.g. custom matchers), you'll need to modify `spec/features/steps.rb`:
63
+
64
+ # in spec/features/steps.rb
65
+ require File.expand_path(File.dirname(__FILE__)) + '../../lib/my-cuke-steps/steps.rb')
66
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
67
+ require 'your_gem_name'
68
+
69
+ You have to do this even if you require the gem files from within your specs, because CukeTest spawns a new process for Cucumber. (The spawned process will not inherit the `require` statements from your spec.)
70
+
71
+ Copyright
72
+ =========
73
+
74
+ Copyright (c) 2010 Jarrett Colby. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "cuke-test"
8
+ gem.summary = %Q{Testing for custom Cucumber steps}
9
+ gem.description = %Q{Packaging some Cucumber steps as a gem? Test them with Cuke Test.}
10
+ gem.email = "jarrett@uchicago.edu"
11
+ gem.homepage = "http://github.com/jarrett/cuke-test"
12
+ gem.authors = ["jarrett"]
13
+ gem.add_dependency "rspec", ">= 1.3.0"
14
+ gem.add_dependency "cucumber", ">= 0.6.3"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "cuke-test #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/cuke-test.gemspec ADDED
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cuke-test}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jarrett"]
12
+ s.date = %q{2010-03-14}
13
+ s.description = %q{Packaging some Cucumber steps as a gem? Test them with Cuke Test.}
14
+ s.email = %q{jarrett@uchicago.edu}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "cuke-test.gemspec",
27
+ "lib/cuke-test.rb",
28
+ "lib/cuke-test/config.rb",
29
+ "lib/cuke-test/cucumber_matchers.rb",
30
+ "lib/cuke-test/helpers.rb",
31
+ "spec/cuke-test_spec.rb",
32
+ "spec/features/failure.feature",
33
+ "spec/features/failure_on_wrong_step.feature",
34
+ "spec/features/require_mock_steps.rb",
35
+ "spec/features/success.feature",
36
+ "spec/features/success_and_failure.feature",
37
+ "spec/spec.opts",
38
+ "spec/spec_helper.rb",
39
+ "spec/step_definitions/mock_steps.rb"
40
+ ]
41
+ s.homepage = %q{http://github.com/jarrett/cuke-test}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.6}
45
+ s.summary = %q{Testing for custom Cucumber steps}
46
+ s.test_files = [
47
+ "spec/cuke-test_spec.rb",
48
+ "spec/features/require_mock_steps.rb",
49
+ "spec/spec_helper.rb",
50
+ "spec/step_definitions/mock_steps.rb"
51
+ ]
52
+
53
+ if s.respond_to? :specification_version then
54
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
58
+ s.add_runtime_dependency(%q<rspec>, [">= 1.3.0"])
59
+ s.add_runtime_dependency(%q<cucumber>, [">= 0.6.3"])
60
+ else
61
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
62
+ s.add_dependency(%q<cucumber>, [">= 0.6.3"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
66
+ s.add_dependency(%q<cucumber>, [">= 0.6.3"])
67
+ end
68
+ end
69
+
data/lib/cuke-test.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'cucumber'
2
+ require 'ostruct'
3
+ require 'cuke-test/config'
4
+ require 'cuke-test/cucumber_matchers'
5
+ require 'cuke-test/helpers'
6
+
7
+ module CukeTest
8
+ def self.included(base)
9
+ base.instance_eval do
10
+ include ::CukeTest::CucumberMatchers
11
+ include ::CukeTest::Helpers
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module CukeTest
2
+ def self.config
3
+ @config ||= OpenStruct.new
4
+ yield @config if block_given?
5
+ @config
6
+ end
7
+ end
@@ -0,0 +1,62 @@
1
+ module CukeTest
2
+ module CucumberMatchers
3
+ class PassCuke
4
+ def matches?(target)
5
+ @target = target
6
+ !!target.match(/[0-9]+ scenarios? \([0-9]+ passed\)/)
7
+ end
8
+
9
+ def failure_message
10
+ message('to pass')
11
+ end
12
+
13
+ def negative_failure_message
14
+ message('not to pass')
15
+ end
16
+
17
+ private
18
+
19
+ def message(infinitive)
20
+ "Expected Cucumber scenario(s) #{infinitive}. Cucumber output:\n\n" + @target
21
+ end
22
+ end
23
+
24
+ def pass_cuke
25
+ PassCuke.new
26
+ end
27
+
28
+ class FailCuke
29
+ def initialize(step = nil)
30
+ @step = step
31
+ end
32
+
33
+ def matches?(target)
34
+ @target = target
35
+ target.match(/[0-9]+ scenarios? \([0-9]+ failed(, [0-9]+ passed)?\)/) and
36
+ (@step.nil? or target.match(/in `#{@step}'/))
37
+ end
38
+
39
+ def failure_message
40
+ message('to fail')
41
+ end
42
+
43
+ def negative_failure_message
44
+ message('not to fail')
45
+ end
46
+
47
+ private
48
+
49
+ def message(infinitive)
50
+ "Expected Cucumber scenario(s) #{infinitive}#{step_message}. Cucumber output:\n\n" + @target
51
+ end
52
+
53
+ def step_message
54
+ @step ? %Q{ on step "#{@step}"} : nil
55
+ end
56
+ end
57
+
58
+ def fail_cuke(step = nil)
59
+ FailCuke.new(step)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,24 @@
1
+ module CukeTest
2
+ module Helpers
3
+ # Runs the feature file (and optionally just one scenario therein) through Cucumber.
4
+ # Returns Cucumber's output as a string.
5
+ def feature(feature_file, scenario = nil)
6
+ out = StringIO.new
7
+ errors = StringIO.new
8
+ if features_path = CukeTest.config.features_path
9
+ feature_file = File.join(features_path, feature_file)
10
+ end
11
+ cli_args = [feature_file, '--no-color']
12
+ if scenario
13
+ cli_args += ['--name', '"' + scenario + '"']
14
+ end
15
+ `cucumber #{cli_args.join(' ')}` # This works
16
+ end
17
+
18
+ # Runs the one scenario in the feature file through Cucumber.
19
+ # Returns Cucumber's output as a string.
20
+ def scenario(feature_file, scenario)
21
+ feature(feature_file, scenario)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe CukeTest do
4
+ include CukeTest
5
+
6
+ def spec_dir
7
+ File.expand_path(File.dirname(__FILE__))
8
+ end
9
+
10
+ def features_path(filename)
11
+ File.join(spec_dir, 'features', filename)
12
+ end
13
+
14
+ describe '#feature and #pass_cuke' do
15
+ it 'matches a passing feature' do
16
+ feature(features_path('success.feature')).should pass_cuke
17
+ end
18
+
19
+ it 'does not match a failing feature' do
20
+ feature(features_path('failure.feature')).should_not pass_cuke
21
+ end
22
+ end
23
+
24
+ describe '#feature and #fail_cuke' do
25
+ it 'matches a failing feature' do
26
+ feature(features_path('failure.feature')).should fail_cuke('And the test fails')
27
+ end
28
+
29
+ it 'does not match a passing feature' do
30
+ feature(features_path('success.feature')).should_not fail_cuke
31
+ end
32
+
33
+ it 'does not match a feature that fails on the wrong step' do
34
+ feature(features_path('failure_on_wrong_step.feature')).should_not fail_cuke('And the test fails')
35
+ end
36
+ end
37
+
38
+ describe '#scenario and #pass_cuke' do
39
+ it 'matches a passing scenario' do
40
+ scenario(features_path('success_and_failure.feature'), 'success').should pass_cuke
41
+ end
42
+
43
+ it 'does not match a failing scenario' do
44
+ scenario(features_path('success_and_failure.feature'), 'failure').should_not pass_cuke
45
+ end
46
+ end
47
+
48
+ describe '#scenario and #fail_cuke' do
49
+ it 'matches a failing scenario' do
50
+ scenario(features_path('success_and_failure.feature'), 'failure').should fail_cuke('And the test fails')
51
+ end
52
+
53
+ it 'does not match a passing scenario' do
54
+ scenario(features_path('success_and_failure.feature'), 'success').should_not fail_cuke
55
+ end
56
+
57
+ it 'does not match a scenario that fails on the wrong step' do
58
+ scenario(features_path('success_and_failure.feature'), 'failure on wrong step').should_not fail_cuke('And the test fails')
59
+ end
60
+ end
61
+
62
+ describe '.config' do
63
+ it 'can set the features path' do
64
+ CukeTest.config.features_path = File.join(File.expand_path(File.dirname(__FILE__)), 'features')
65
+ feature('success.feature').should pass_cuke
66
+ end
67
+ end
68
+
69
+ it 'can handle Cucumber args with spaces' do
70
+ scenario(features_path('success_and_failure.feature'), 'failure on wrong step').should fail_cuke('And the test fails on the wrong step')
71
+ end
72
+ end
@@ -0,0 +1,4 @@
1
+ Feature: failure
2
+ Scenario: failure
3
+ Given nothing happens
4
+ And the test fails
@@ -0,0 +1,4 @@
1
+ Feature: failure on wrong step
2
+ Scenario: failure on wrong step
3
+ Given nothing happens
4
+ And the test fails on the wrong step
@@ -0,0 +1,3 @@
1
+ # Why put the steps in a different file and require it from here? Because this is the approach
2
+ # that authors of step libraries will have to take, so we must verify that it works.
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'step_definitions', 'mock_steps.rb')
@@ -0,0 +1,3 @@
1
+ Feature: success
2
+ Scenario: success
3
+ Given the test passes
@@ -0,0 +1,11 @@
1
+ Feature: success and failure
2
+ Scenario: success
3
+ Given the test passes
4
+
5
+ Scenario: failure
6
+ Given nothing happens
7
+ And the test fails
8
+
9
+ Scenario: failure on wrong step
10
+ Given nothing happens
11
+ And the test fails on the wrong step
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'cuke-test'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,13 @@
1
+ # Required by spec/features/require_mock_steps.rb
2
+
3
+ Given /^nothing happens$/ do; end
4
+
5
+ Given /^the test passes$/ do; end
6
+
7
+ Given /^the test fails$/ do
8
+ flunk('The test failed!')
9
+ end
10
+
11
+ Given /^the test fails on the wrong step$/ do
12
+ flunk('The test failed on the wrong step!!')
13
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuke-test
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - jarrett
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-14 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 3
30
+ - 0
31
+ version: 1.3.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: cucumber
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 6
44
+ - 3
45
+ version: 0.6.3
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: Packaging some Cucumber steps as a gem? Test them with Cuke Test.
49
+ email: jarrett@uchicago.edu
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.markdown
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.markdown
62
+ - Rakefile
63
+ - VERSION
64
+ - cuke-test.gemspec
65
+ - lib/cuke-test.rb
66
+ - lib/cuke-test/config.rb
67
+ - lib/cuke-test/cucumber_matchers.rb
68
+ - lib/cuke-test/helpers.rb
69
+ - spec/cuke-test_spec.rb
70
+ - spec/features/failure.feature
71
+ - spec/features/failure_on_wrong_step.feature
72
+ - spec/features/require_mock_steps.rb
73
+ - spec/features/success.feature
74
+ - spec/features/success_and_failure.feature
75
+ - spec/spec.opts
76
+ - spec/spec_helper.rb
77
+ - spec/step_definitions/mock_steps.rb
78
+ has_rdoc: true
79
+ homepage: http://github.com/jarrett/cuke-test
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --charset=UTF-8
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.6
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Testing for custom Cucumber steps
108
+ test_files:
109
+ - spec/cuke-test_spec.rb
110
+ - spec/features/require_mock_steps.rb
111
+ - spec/spec_helper.rb
112
+ - spec/step_definitions/mock_steps.rb