rutabaga 2.0.2 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -14
- data/examples/pattern/test_pattern_spec.rb +7 -0
- data/lib/rutabaga/no_turnip.rb +27 -0
- data/lib/rutabaga/turnip.rb +35 -0
- data/lib/rutabaga/util.rb +5 -1
- data/lib/rutabaga/version.rb +1 -1
- data/lib/rutabaga.rb +1 -0
- data/spec/features/fixture.feature +7 -0
- data/spec/no_turnip_spec.rb +58 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc9f8613aa7909bb48702020985d606fb913714f
|
4
|
+
data.tar.gz: 8e729b8b2db01db9412101f6d992dff950b995aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9bfd33defd258d57e80832cbded5661362a6e171e141ada65b806d22dece3e001fdcf94c98a0bdd6c80769912f27cefe0b46c073a51bb0c2b3ed03dee14835f
|
7
|
+
data.tar.gz: 9fc5f56fbeb390ac53a749879e84285e82774d4aa302e444b742dbe59d206b7fb9f0bee80c59db1e36f0ba2e7dd387776e56f9eabe7942722a02d2a7c7272964
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
![image](rutabaga-vs-turnip.jpg)
|
4
4
|
|
5
|
-
[Turnip](https://github.com/jnicklas/turnip)
|
5
|
+
[Turnip](https://github.com/jnicklas/turnip) extension to enable running turnip features from inside spec files, rather than outside.
|
6
6
|
|
7
7
|
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. The steps are then scoped to that particular test.
|
8
8
|
|
@@ -27,21 +27,28 @@ group :test do
|
|
27
27
|
end
|
28
28
|
```
|
29
29
|
|
30
|
-
|
30
|
+
Choose which mode you want to use: __Turnip compatibility mode__ or __No Turnip mode__.
|
31
|
+
|
32
|
+
### Turnip compatibility mode
|
33
|
+
|
34
|
+
In this mode, you can still have and call classic Turnip features directly, as long
|
35
|
+
as they are situated under the `spec/features` directory.
|
36
|
+
|
37
|
+
Edit the `.rspec` file in your project directory (create it if doesn't
|
31
38
|
exist), and add the following:
|
32
39
|
|
33
40
|
```
|
34
41
|
-r rutabaga
|
35
42
|
```
|
36
43
|
|
37
|
-
Add the
|
44
|
+
Add the following line to the bottom of your `spec_helper.rb` in order to use
|
45
|
+
Turnip global step definitions:
|
38
46
|
|
39
47
|
```ruby
|
40
|
-
require 'turnip/capybara'
|
41
48
|
Dir.glob("spec/features/step_definitions/**/*_steps.rb") { |f| load f, true }
|
42
49
|
```
|
43
50
|
|
44
|
-
In order to get `rake` or `bundle exec rake` to work properly
|
51
|
+
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).
|
45
52
|
|
46
53
|
```ruby
|
47
54
|
if defined? RSpec # otherwise fails on non-live environments
|
@@ -52,6 +59,22 @@ if defined? RSpec # otherwise fails on non-live environments
|
|
52
59
|
end
|
53
60
|
```
|
54
61
|
|
62
|
+
### No Turnip Mode
|
63
|
+
|
64
|
+
If you do not want to use Turnip features then you can disable turnip by adding the following to you `.rspec` file instead of `-r rutabaga`:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
-r rutabaga/no_turnip
|
68
|
+
```
|
69
|
+
|
70
|
+
### Capybara support
|
71
|
+
|
72
|
+
Add the following line to the bottom of your `spec_helper.rb` in order to use Capybara javascript driver (when features are tagged with `@javascript`):
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
require 'turnip/capybara'
|
76
|
+
```
|
77
|
+
|
55
78
|
## Usage
|
56
79
|
|
57
80
|
### Running a feature file from a spec file
|
@@ -100,14 +123,12 @@ Steps are defined in the same way as in Turnip, however, steps can be defined wi
|
|
100
123
|
|
101
124
|
```ruby
|
102
125
|
feature "step will only be in this context" do
|
103
|
-
|
104
126
|
step "action :named" do |named| do
|
105
127
|
expect(named).to eq("a name")
|
106
128
|
end
|
107
129
|
end
|
108
130
|
|
109
131
|
feature "step 'action :named' is not available here" do
|
110
|
-
|
111
132
|
# missing step will cause tests to be marked as pending"
|
112
133
|
end
|
113
134
|
```
|
@@ -120,9 +141,9 @@ Other than these differences, Rutabaga is a tiny shim over Turnip and all featur
|
|
120
141
|
|
121
142
|
## Why?
|
122
143
|
|
123
|
-
*
|
124
|
-
* Test those rules
|
125
|
-
* Use the full power of RSpec (
|
144
|
+
* Allows you to document business rules in Gherkin/Turnip/Cucumber human readable language
|
145
|
+
* Test those rules wherever/however appropriate (not just through Capybara/black box)
|
146
|
+
* Use the full power of RSpec (being able to describe a class and then test it)
|
126
147
|
|
127
148
|
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 to test premium changes when a customer changes their insurance coverage.
|
128
149
|
|
@@ -130,12 +151,15 @@ These rules are often implemented in a Model, a lib class, or some other specifi
|
|
130
151
|
|
131
152
|
In any case, business rules are usually implemented somewhere inside a class tested by a unit test. Those business rules should be tested in Cucumber/Turnip without having to go through the whole system, and without having to have duplicate tests, one inside rspec and another inside features.
|
132
153
|
|
133
|
-
The goal is to test just the business rule
|
154
|
+
The goal is to test just the business rule in Rutabaga, and not the login, the html, the steps to get there, etc. That way, when the rule changes, only the feature, the test code and the class in question need to change. The test is not affected by wider ranging changes, and is therefore less brittle. The features run at the unit code level, but are acceptance tests.
|
134
155
|
|
135
156
|
## Notes/Issues
|
136
157
|
|
137
|
-
1. Capybara's rspec extension also redefines feature, so rutabaga will block
|
138
|
-
from working.
|
158
|
+
1. Capybara's rspec extension also redefines feature, so rutabaga will block
|
159
|
+
capaybara's feature example groups from working.
|
160
|
+
1. In order to call a specific scenario, you can use `rspec`'s filtering. Here is an example:
|
161
|
+
`$ rspec spec/test_file_spec.rb -e "Title of my scenario"`.
|
162
|
+
This will only call the Scenario titled `Title of my scenario` in file `spec/test_file_spec.rb`
|
139
163
|
|
140
164
|
## Contributing
|
141
165
|
|
@@ -157,7 +181,7 @@ Put the following (example in a `Gemfile_for_xxx`) to test other versions of gem
|
|
157
181
|
# Use global Gemfile and customize
|
158
182
|
eval(IO.read('Gemfile'), binding)
|
159
183
|
|
160
|
-
gem 'turnip', '
|
184
|
+
gem 'turnip', '2.0.0'
|
161
185
|
```
|
162
186
|
|
163
187
|
## Copyright
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rutabaga
|
2
|
+
NO_TURNIP = true
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'rutabaga'
|
6
|
+
##
|
7
|
+
#
|
8
|
+
# Disables turnip completely
|
9
|
+
#
|
10
|
+
module Turnip
|
11
|
+
module RSpec
|
12
|
+
module Loader
|
13
|
+
def load(*a, &b)
|
14
|
+
if a.first.end_with?('.feature')
|
15
|
+
::RSpec.warning "Calling features directly has been disabled by rutabaga. To re-enable, do not require rutabaga/no_turnip."
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
::RSpec.configure do |c|
|
25
|
+
# Blow away rutabaga's pattern if still there
|
26
|
+
c.pattern.gsub!(",features/**/*.feature", "")
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rutabaga'
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Enables turnip in the spec/features
|
5
|
+
#
|
6
|
+
module Turnip
|
7
|
+
module RSpec
|
8
|
+
module Loader
|
9
|
+
def load(*a, &b)
|
10
|
+
if a.first.end_with?('.feature')
|
11
|
+
if legal_directories.none? {|d| a.first.end_with? d }
|
12
|
+
::RSpec.warning "Features can only be called from turnip enable directories. These are configured " \
|
13
|
+
"in RSpec.configuration.pattern which is currently '#{::RSpec.configuration.pattern}'"
|
14
|
+
else
|
15
|
+
require_if_exists 'turnip_helper'
|
16
|
+
require_if_exists 'spec_helper'
|
17
|
+
|
18
|
+
Turnip::RSpec.run(a.first)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def legal_directories
|
28
|
+
@legal_directories ||= ::RSpec.configuration.pattern.split(',')
|
29
|
+
.select {|p| /\.feature\Z/ =~ p}
|
30
|
+
.map {|d| Dir.glob(File.join(::RSpec.configuration.default_path,d)) }
|
31
|
+
.flatten
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rutabaga/util.rb
CHANGED
@@ -64,5 +64,9 @@ end
|
|
64
64
|
::RSpec.configure do |c|
|
65
65
|
c.include Rutabaga::Feature
|
66
66
|
# Blow away turnip's pattern, and focus just on features directory
|
67
|
-
|
67
|
+
if defined?(Rutabaga::NO_TURNIP)
|
68
|
+
c.pattern.gsub!(",**/*.feature", "")
|
69
|
+
else
|
70
|
+
c.pattern.gsub!(",**/*.feature", ",features/**/*.feature")
|
71
|
+
end
|
68
72
|
end
|
data/lib/rutabaga/version.rb
CHANGED
data/lib/rutabaga.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'no_turnip', :type => :integration do
|
4
|
+
describe 'turnip disabled' do
|
5
|
+
before(:all) do
|
6
|
+
@result = %x(rspec -r rutabaga -r rutabaga/no_turnip examples/test.feature 2>&1)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should raise an error when trying to call turnip features directly" do
|
10
|
+
expect(@result).to include("Calling features directly has been disabled by rutabaga")
|
11
|
+
expect(@result).to include("rutabaga/no_turnip")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has the correct file pattern" do
|
15
|
+
result = %x(rspec -r rutabaga/no_turnip -r rutabaga examples/pattern/test_pattern_spec.rb)
|
16
|
+
expect(result).to include("RSpec.configuration.pattern: **{,/*/**}/*_spec.rb\n")
|
17
|
+
result = %x(rspec -r rutabaga -r rutabaga/no_turnip -r rutabaga examples/pattern/test_pattern_spec.rb)
|
18
|
+
expect(result).to include("RSpec.configuration.pattern: **{,/*/**}/*_spec.rb\n")
|
19
|
+
result = %x(rspec -r rutabaga/no_turnip examples/pattern/test_pattern_spec.rb)
|
20
|
+
expect(result).to include("RSpec.configuration.pattern: **{,/*/**}/*_spec.rb\n")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'turnip enabled' do
|
25
|
+
describe "in correct directory" do
|
26
|
+
it "should be able to call features directly" do
|
27
|
+
@result = %x(rspec -r rutabaga/turnip spec/features/fixture.feature 2>&1)
|
28
|
+
expect(@result).to include("No such step")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "rutabaga turnip is the default" do
|
32
|
+
@result = %x(rspec -r rutabaga spec/features/fixture.feature 2>&1)
|
33
|
+
expect(@result).to include("No such step")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "outside of the correct directory" do
|
38
|
+
before(:all) do
|
39
|
+
@result = %x(rspec -r rutabaga examples/test.feature 2>&1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "warns about the directory" do
|
43
|
+
expect(@result).to include("WARNING: Features can only be called from turnip enable directories")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "has the correct file pattern" do
|
48
|
+
result = %x(rspec -r rutabaga examples/pattern/test_pattern_spec.rb)
|
49
|
+
expect(result).to include("RSpec.configuration.pattern: **{,/*/**}/*_spec.rb,features/**/*.feature\n")
|
50
|
+
result = %x(rspec -r rutabaga/turnip -r rutabaga examples/pattern/test_pattern_spec.rb)
|
51
|
+
expect(result).to include("RSpec.configuration.pattern: **{,/*/**}/*_spec.rb,features/**/*.feature\n")
|
52
|
+
result = %x(rspec -r rutabaga -r rutabaga/turnip -r rutabaga examples/pattern/test_pattern_spec.rb)
|
53
|
+
expect(result).to include("RSpec.configuration.pattern: **{,/*/**}/*_spec.rb,features/**/*.feature\n")
|
54
|
+
result = %x(rspec -r rutabaga/turnip examples/pattern/test_pattern_spec.rb)
|
55
|
+
expect(result).to include("RSpec.configuration.pattern: **{,/*/**}/*_spec.rb,features/**/*.feature\n")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rutabaga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Oberhuber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: turnip
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- README.md
|
110
110
|
- Rakefile
|
111
111
|
- examples/compatibility/compatibility_spec.rb
|
112
|
+
- examples/pattern/test_pattern_spec.rb
|
112
113
|
- examples/spec_helper.rb
|
113
114
|
- examples/test.feature
|
114
115
|
- examples/test2.feature
|
@@ -120,11 +121,15 @@ files:
|
|
120
121
|
- lib/rutabaga.rb
|
121
122
|
- lib/rutabaga/example_group/feature.rb
|
122
123
|
- lib/rutabaga/feature.rb
|
124
|
+
- lib/rutabaga/no_turnip.rb
|
125
|
+
- lib/rutabaga/turnip.rb
|
123
126
|
- lib/rutabaga/util.rb
|
124
127
|
- lib/rutabaga/version.rb
|
125
128
|
- rutabaga-vs-turnip.jpg
|
126
129
|
- rutabaga.gemspec
|
127
130
|
- spec/feature_spec.rb
|
131
|
+
- spec/features/fixture.feature
|
132
|
+
- spec/no_turnip_spec.rb
|
128
133
|
- spec/rutabaga/util_spec.rb
|
129
134
|
- spec/spec_helper.rb
|
130
135
|
homepage: https://github.com/simplybusiness/rutabaga
|
@@ -154,6 +159,8 @@ summary: Calling Turnip feature files from RSpec, which allows encapsulating a f
|
|
154
159
|
inside a describe block
|
155
160
|
test_files:
|
156
161
|
- spec/feature_spec.rb
|
162
|
+
- spec/features/fixture.feature
|
163
|
+
- spec/no_turnip_spec.rb
|
157
164
|
- spec/rutabaga/util_spec.rb
|
158
165
|
- spec/spec_helper.rb
|
159
166
|
has_rdoc:
|