rutabaga 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +112 -0
- data/Rakefile +2 -0
- data/examples/spec_helper.rb +0 -0
- data/examples/test.feature +5 -0
- data/examples/test2.feature +5 -0
- data/examples/test_spec.rb +48 -0
- data/lib/.DS_Store +0 -0
- data/lib/rutabaga/feature.rb +49 -0
- data/lib/rutabaga/version.rb +3 -0
- data/lib/rutabaga.rb +3 -0
- data/rutabaga.gemspec +20 -0
- data/spec/feature_spec.rb +31 -0
- data/spec/spec_helper.rb +0 -0
- metadata +82 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Xbridge Ltd, trading as Simply Business
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Rutabaga
|
2
|
+
|
3
|
+
Turnip hacks to enable running turnips from inside spec files, rather than outside.
|
4
|
+
|
5
|
+
Rutabaga allows you to invert the control of feature files, so that features are called from your `_spec.rb` files rather than the other way around. Step definitions are then put into the `_spec.rb` files as well.
|
6
|
+
|
7
|
+
This means that it is simple to create tests that are described by a class (such as controller tests in rspec-rails).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Install the gem
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install rutabaga
|
15
|
+
```
|
16
|
+
|
17
|
+
Or add it to your Gemfile and run `bundle`.
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
group :test do
|
21
|
+
gem "rutabaga", :git => 'git://github.com/simplybusiness/rutabaga.git'
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
Now edit the `.rspec` file in your project directory (create it if doesn't
|
26
|
+
exist), and add the following line:
|
27
|
+
|
28
|
+
```
|
29
|
+
-r rutabaga
|
30
|
+
```
|
31
|
+
|
32
|
+
Add the follwing lines to the bottom of your `spec_helper.rb` (assuming you want to use Capybara and the final one if you wish to have step definitions outside of your spec files:
|
33
|
+
|
34
|
+
```
|
35
|
+
require 'turnip/capybara'
|
36
|
+
Dir.glob("spec/features/step_definitions/**/*_steps.rb") { |f| load f, true }
|
37
|
+
```
|
38
|
+
|
39
|
+
In order to get `rake` or `bundle exec rake` to work properly, you might need to add this in the file `lib/tasks/rspec.rake` (at least for rails)
|
40
|
+
|
41
|
+
```
|
42
|
+
if defined? RSpec # otherwise fails on non-live environments
|
43
|
+
desc "Run all specs/features in spec directory"
|
44
|
+
RSpec::Core::RakeTask.new(:spec => 'db:test:prepare') do |t|
|
45
|
+
t.pattern = './spec/{**/*_spec.rb,features/**/*.feature}'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
### Running a feature file from a spec file
|
53
|
+
|
54
|
+
Please look in `spec/controllers/feature_test_spec.rb` and `spec/controllers/feature_test.feature` for more.
|
55
|
+
|
56
|
+
For file `spec/controllers/test_feature_spec.rb`
|
57
|
+
|
58
|
+
```
|
59
|
+
it "should run feature" do
|
60
|
+
feature
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
Will run `spec/controllers/test_feature.feature`.
|
65
|
+
|
66
|
+
Features are found either with the same name as the spec file, or as specified in the example name `it "/path/to/feature/file.feature"`. So, if you have:
|
67
|
+
|
68
|
+
`spec/controllers/feature_test_spec.rb`
|
69
|
+
|
70
|
+
Then the feature will be:
|
71
|
+
|
72
|
+
`spec/controllers/feature_test.feature`
|
73
|
+
|
74
|
+
Alternatively, if the feature is specified in the `it`, that takes precedence:
|
75
|
+
|
76
|
+
```
|
77
|
+
it "spec/features/test.feature" do
|
78
|
+
feature
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
Will run `spec/features/test.feature`.
|
83
|
+
|
84
|
+
### Differences from Turnip
|
85
|
+
|
86
|
+
Other than these differences, Rutabaga is a tiny shim over Turnip and all features will work as expected.
|
87
|
+
|
88
|
+
* Turnip looks anywhere below the `spec` directory for `.feature` files. Rutabaga will only load `.feature` files from below the `spec/features` directory in the old way. This is to avoid conflicts with `.feature` files that are loaded from `_spec.rb` files.
|
89
|
+
|
90
|
+
## Why?
|
91
|
+
|
92
|
+
The fundamental purpose of Turnip/Cucumber is to document the system in end-user readable form.
|
93
|
+
|
94
|
+
The most important functionality in a system is the business rules. These range from what appears on a page, to complex rules around when emails should be sent to who. For example, we've written Gherkin tests for what amount to charge a customer when they change what's covered on their insurance policy.
|
95
|
+
|
96
|
+
Those rules are often implemented in a Model, a lib class, or some other specific class in the system, especially if the application is well modularized.
|
97
|
+
|
98
|
+
In any case, business rules are usually implemented somewhere inside a class tested by a unit test. I want to get those business rules tested in Cucumber/Turnip without having to go through the whole system, and without having to have duplicate tests, one inside my rspec and another inside my features.
|
99
|
+
|
100
|
+
My goal is to test just the business rule, in Turnip, and not the login, the html, the steps to get there, etc. That way, when the rule changes, I change the Turnip, the test code and the class in question. My test is not affected by wider ranging changes, and therefore less brittle. (This should all be familiar territory.) I guess, in that sense, the code runs at the unit code level, but is an acceptance test.
|
101
|
+
|
102
|
+
## Contributing
|
103
|
+
|
104
|
+
1. Fork it
|
105
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
106
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
107
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
108
|
+
5. Create new Pull Request
|
109
|
+
|
110
|
+
## Copyright
|
111
|
+
|
112
|
+
Copyright © 2012 SimplyBusiness. See LICENSE for details.
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "test" do
|
4
|
+
it "should run feature" do
|
5
|
+
feature
|
6
|
+
end
|
7
|
+
|
8
|
+
step "that :first + :second is calculated" do |first, second|
|
9
|
+
@first = first
|
10
|
+
@second = second
|
11
|
+
end
|
12
|
+
|
13
|
+
step "my result is :result" do |result|
|
14
|
+
result.to_i.should == @first.to_i + @second.to_i
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "should find the feature file using the root (and monkey patching the result)" do
|
19
|
+
it "examples/test2.feature" do
|
20
|
+
feature
|
21
|
+
end
|
22
|
+
|
23
|
+
step "that :first + :second is calculated" do |first, second|
|
24
|
+
@first = first
|
25
|
+
@second = second
|
26
|
+
end
|
27
|
+
|
28
|
+
step "my result is :result" do |result|
|
29
|
+
result.to_i.should == @first.to_i + @second.to_i - 1
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "causes a failing test" do
|
35
|
+
it "examples/test2.feature" do
|
36
|
+
feature
|
37
|
+
end
|
38
|
+
|
39
|
+
step "that :first + :second is calculated" do |first, second|
|
40
|
+
@first = first
|
41
|
+
@second = second
|
42
|
+
end
|
43
|
+
|
44
|
+
step "my result is :result" do |result|
|
45
|
+
result.to_i.should == @first.to_i + @second.to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'turnip'
|
2
|
+
|
3
|
+
module Rutabaga
|
4
|
+
module Feature
|
5
|
+
def feature
|
6
|
+
feature_file = find_feature
|
7
|
+
|
8
|
+
rspec_class = self.class
|
9
|
+
builder = Turnip::Builder.build(feature_file)
|
10
|
+
builder.features.each do |feature|
|
11
|
+
rspec_class.describe(feature.name, feature.metadata_hash) do
|
12
|
+
rspec_class.before do
|
13
|
+
# This is kind of a hack, but it will make RSpec throw way nicer exceptions
|
14
|
+
example.metadata[:file_path] = feature_file
|
15
|
+
|
16
|
+
feature.backgrounds.map(&:steps).flatten.each do |step|
|
17
|
+
run_step(feature_file, step)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
feature.scenarios.each do |scenario|
|
21
|
+
rspec_class.describe(scenario.name, scenario.metadata_hash) do
|
22
|
+
it scenario.steps.map(&:description).join(' -> ') do
|
23
|
+
scenario.steps.each do |step|
|
24
|
+
run_step(feature_file, step)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_feature
|
34
|
+
return example.description if File.exists?(example.description)
|
35
|
+
|
36
|
+
spec_file = caller(2).first.split(':').first
|
37
|
+
feature_file = spec_file.gsub(/_spec.rb\Z/, '.feature')
|
38
|
+
return feature_file if File.exists?(feature_file)
|
39
|
+
|
40
|
+
raise "Feature file not found. Tried: #{example.description} and #{feature_file}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
::RSpec.configure do |c|
|
46
|
+
c.include Rutabaga::Feature
|
47
|
+
# Blow away turnip's pattern, and focus just on features directory
|
48
|
+
c.pattern.gsub!(",**/*.feature", ",features/**/*.feature")
|
49
|
+
end
|
data/lib/rutabaga.rb
ADDED
data/rutabaga.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/rutabaga/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Lukas Oberhuber']
|
6
|
+
gem.email = ['lukas.oberhuber@simplybusiness.co.uk']
|
7
|
+
gem.description = %q{Allows using feature from within RSpec and is built on top of Turnip}
|
8
|
+
gem.summary = %q{Calling Turnip feature files from RSpec, which allows encapsulating a feature inside a describe block}
|
9
|
+
gem.homepage = 'https://github.com/simplybusiness/rutabaga'
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = 'rutabaga'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = Rutabaga::VERSION
|
17
|
+
gem.license = 'MIT'
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'turnip', '>= 1.0.0'
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'integration', :type => :integration do
|
4
|
+
before do
|
5
|
+
@result = %x(rspec -r rutabaga -fs examples/*_spec.rb)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "shows the correct description" do
|
9
|
+
@result.should include('ensures the feature is called')
|
10
|
+
@result.should include('that 2 + 2 is calculated')
|
11
|
+
@result.should include('my result is 4')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not show any pending steps" do
|
15
|
+
@result.should_not include('PENDING')
|
16
|
+
@result.should_not include('No such step')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "prints out failures and successes" do
|
20
|
+
@result.should include('6 examples, 1 failure')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should find features relative to the root" do
|
24
|
+
@result.should_not include('Feature file not found')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should scope steps to describe blocks" do
|
28
|
+
@result.should_not include('Turnip::Ambiguous')
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rutabaga
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lukas Oberhuber
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: turnip
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
description: Allows using feature from within RSpec and is built on top of Turnip
|
31
|
+
email:
|
32
|
+
- lukas.oberhuber@simplybusiness.co.uk
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .travis.yml
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- examples/spec_helper.rb
|
44
|
+
- examples/test.feature
|
45
|
+
- examples/test2.feature
|
46
|
+
- examples/test_spec.rb
|
47
|
+
- lib/.DS_Store
|
48
|
+
- lib/rutabaga.rb
|
49
|
+
- lib/rutabaga/feature.rb
|
50
|
+
- lib/rutabaga/version.rb
|
51
|
+
- rutabaga.gemspec
|
52
|
+
- spec/feature_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/simplybusiness/rutabaga
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.24
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Calling Turnip feature files from RSpec, which allows encapsulating a feature
|
79
|
+
inside a describe block
|
80
|
+
test_files:
|
81
|
+
- spec/feature_spec.rb
|
82
|
+
- spec/spec_helper.rb
|