turnip 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 244b05edd98a840b930b2ead6b49bb2054cc84e8
4
- data.tar.gz: c116ea751e8f8c443e24d731b25f2d8f0faf70d4
3
+ metadata.gz: bdb367c9acc76b2fb0f4abbbedf8730ce97f3d33
4
+ data.tar.gz: 69314b7771dfcd5a645b4a41b01d1c99c84ae5e6
5
5
  SHA512:
6
- metadata.gz: a55c0893be54b1858157e288965ae6e33e50296c5ff53e817a68330f3c53162631f05aa69fba8b3889339997115ae15044c7e6c433ee1c3b6cb0b4141fbc9a61
7
- data.tar.gz: 6e438b7cc2c80cc96437ef557b72cf0bab46ce829ffd5e209ae9bbced49d872146b8c739d612b5db07e2a20bc7a404ad9913427314ed42f61ff5eeab23ae4de8
6
+ metadata.gz: 0ba3f6f9153835411c293efb95224f4e3a0a22e6f896a2df4ab52739c9ae66a661658c10e214a7a06bb6bb625c16c8bb4105739c93d0abcf8b2d3b63ea190e8b
7
+ data.tar.gz: 2305ebaeee98b1da8a8f599fc3a94c51c27487732e9af2d5762f56260cebf186665a38e1123249860f6330f8ca7865276d974d00c116bf33455c6be2ac20ce8b
data/README.md CHANGED
@@ -1,18 +1,13 @@
1
1
  # Turnip
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/jnicklas/turnip.png)](http://travis-ci.org/jnicklas/turnip)
4
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/jnicklas/turnip)
4
+ [![Code Climate](https://codeclimate.com/github/jnicklas/turnip.png)](https://codeclimate.com/github/jnicklas/turnip)
5
5
 
6
6
  Turnip is a [Gherkin](https://github.com/cucumber/cucumber/wiki/Gherkin)
7
7
  extension for RSpec. It allows you to write tests in Gherkin and run them
8
8
  through your RSpec environment. Basically you can write cucumber features in
9
9
  RSpec.
10
10
 
11
- ## Maintainer wanted!
12
-
13
- Are you interested in maintaining Turnip's code base? Please get in touch with
14
- [me](http://github.com/jnicklas).
15
-
16
11
  ## Installation
17
12
 
18
13
  Install the gem
@@ -98,6 +93,30 @@ RSpec.configure { |c| c.include MonsterSteps }
98
93
  Steps are implemented as regular Ruby methods under the hood, so you can
99
94
  use Ruby's normal inheritance chain to mix and match steps.
100
95
 
96
+ ### Before/After Hooks
97
+
98
+ Since Turnip runs atop RSpec, it can utilize RSpec's built-in before and after
99
+ hooks. To run a hook for all features, specify a global hook with `type` set
100
+ to `:feature`:
101
+
102
+ ```ruby
103
+ config.before(:type => :feature) do
104
+ do_something
105
+ end
106
+ config.after(:type => :feature) do
107
+ do_something_else
108
+ end
109
+ ```
110
+
111
+ You can also limit this to a tag by specifying the tag in the argument to
112
+ `before` or `after`:
113
+
114
+ ```ruby
115
+ config.before(:some_tag => true) do
116
+ do_something
117
+ end
118
+ ```
119
+
101
120
  ### Global steps
102
121
 
103
122
  Turnip has a special module called `Turnip::Steps`, which is automatically
@@ -217,6 +236,14 @@ Before loading your `spec_helper`, Turnip also tries to load a file called
217
236
  You might find it beneficial to load your steps from this file so that they
218
237
  don't have to be loaded when you run your other tests.
219
238
 
239
+ If you use Turnip with [rspec-rails](https://github.com/rspec/rspec-rails) v3.x, most configuration written to `rails_helper.rb` but not `spec_helper.rb`. So you should write to `turnip_helper` like this:
240
+
241
+ ```ruby
242
+ require 'rails_helper'
243
+ ```
244
+
245
+ Then you can write configuration to `rails_helper` to load your steps.
246
+
220
247
  ### Calling steps from other steps
221
248
 
222
249
  Since steps are Ruby methods you can call them like other Ruby methods.
@@ -333,6 +360,26 @@ step "there are the following monsters:" do |table|
333
360
  end
334
361
  ```
335
362
 
363
+ ## Substitution in Scenario Outlines
364
+
365
+ You would be able to use substitution that can be used to DocString and Table arguments in Scenario Outline like [Cucumber](http://cukes.info/step-definitions.html#substitution_in_scenario_outlines):
366
+
367
+ ```cucumber
368
+ Scenario Outline: Email confirmation
369
+ Given I have a user account with my name "Jojo Binks"
370
+ When an Admin grants me <Role> rights
371
+ Then I should receive an email with the body:
372
+ """
373
+ Dear Jojo Binks,
374
+ You have been granted <Role> rights. You are <details>. Please be responsible.
375
+ -The Admins
376
+ """
377
+ Examples:
378
+ | Role | details |
379
+ | Manager | now able to manage your employee accounts |
380
+ | Admin | able to manage any user account on the system |
381
+ ```
382
+
336
383
  ## Using with Capybara
337
384
 
338
385
  Just require `turnip/capybara` in your `spec_helper`. You can now use the same
@@ -0,0 +1,13 @@
1
+ Feature: using scenario outlines
2
+ Scenario Outline: a simple outline
3
+ Given there is a monster called <name>
4
+ Then the monster introduced himself:
5
+ """
6
+ Ahhhhhhh! i'm <name>!
7
+ """
8
+
9
+ Examples:
10
+ | name |
11
+ | John |
12
+ | "John Smith" |
13
+ | "O'Flannahan" |
@@ -44,6 +44,10 @@ step "it should be nameless" do
44
44
  @monster_name.should == ""
45
45
  end
46
46
 
47
+ step "the monster introduced himself:" do |self_introduction|
48
+ self_introduction.should include @monster_name
49
+ end
50
+
47
51
  step "there is a monster with :count hitpoints" do |count|
48
52
  @monster = count
49
53
  end
@@ -87,10 +87,16 @@ module Turnip
87
87
  scenario.steps = steps.map do |step|
88
88
  new_description = substitute(step.description, headers, row)
89
89
  new_extra_args = step.extra_args.map do |ea|
90
- next ea unless ea.instance_of?(Turnip::Table)
91
- Turnip::Table.new(ea.map {|t_row| t_row.map {|t_col| substitute(t_col, headers, row) } })
90
+ case ea
91
+ when String
92
+ substitute(ea, headers, row)
93
+ when Turnip::Table
94
+ Turnip::Table.new(ea.map {|t_row| t_row.map {|t_col| substitute(t_col, headers, row) } })
95
+ else
96
+ ea
97
+ end
92
98
  end
93
- Step.new(new_description, new_extra_args, step.line)
99
+ Step.new(new_description, new_extra_args, step.line, step.keyword)
94
100
  end
95
101
  end
96
102
  end
@@ -103,7 +109,7 @@ module Turnip
103
109
  end
104
110
  end
105
111
 
106
- class Step < Struct.new(:description, :extra_args, :line)
112
+ class Step < Struct.new(:description, :extra_args, :line, :keyword)
107
113
  # 1.9.2 support hack
108
114
  def split(*args)
109
115
  self.to_s.split(*args)
@@ -160,7 +166,7 @@ module Turnip
160
166
  table = Turnip::Table.new(step.rows.map(&:cells).map(&:to_a))
161
167
  extra_args.push(table)
162
168
  end
163
- @current_step_context.steps << Step.new(step.name, extra_args, step.line)
169
+ @current_step_context.steps << Step.new(step.name, extra_args, step.line, step.keyword)
164
170
  end
165
171
 
166
172
  def uri(*)
@@ -2,9 +2,12 @@ require 'capybara/rspec'
2
2
 
3
3
  RSpec.configure do |config|
4
4
  config.before do
5
- if self.class.include?(Capybara::DSL) and example.metadata[:turnip]
6
- Capybara.current_driver = Capybara.javascript_driver if example.metadata.has_key?(:javascript)
7
- example.metadata.each do |tag, value|
5
+ current_example = example if respond_to?(:example)
6
+ current_example ||= RSpec.current_example
7
+
8
+ if self.class.include?(Capybara::DSL) and current_example.metadata[:turnip]
9
+ Capybara.current_driver = Capybara.javascript_driver if current_example.metadata.has_key?(:javascript)
10
+ current_example.metadata.each do |tag, value|
8
11
  if Capybara.drivers.has_key?(tag)
9
12
  Capybara.current_driver = tag
10
13
  end
@@ -27,7 +27,7 @@ module Turnip
27
27
 
28
28
  def default
29
29
  @default ||= new(:default) do
30
- match %r((?:"([^"]*)"|'([^']*)'|([a-zA-Z0-9_-]+))) do |first, second, third|
30
+ match %r((?:"([^"]*)"|'([^']*)'|([[:alnum:]_-]+))) do |first, second, third|
31
31
  first or second or third
32
32
  end
33
33
  end
data/lib/turnip/rspec.rb CHANGED
@@ -46,7 +46,13 @@ module Turnip
46
46
  # This is kind of a hack, but it will make RSpec throw way nicer exceptions
47
47
  example = Turnip::RSpec.fetch_current_example(self)
48
48
  example.metadata[:line_number] = step.line
49
- pending("No such step: '#{e}'")
49
+ example.metadata[:location] = "#{example.metadata[:file_path]}:#{step.line}"
50
+
51
+ if ::RSpec::Version::STRING >= '2.99.0'
52
+ skip("No such step: '#{e}'")
53
+ else
54
+ pending("No such step: '#{e}'")
55
+ end
50
56
  rescue StandardError => e
51
57
  e.backtrace.push "#{feature_file}:#{step.line}:in `#{step.description}'"
52
58
  raise e
@@ -65,7 +71,7 @@ module Turnip
65
71
 
66
72
  def run(feature_file)
67
73
  Turnip::Builder.build(feature_file).features.each do |feature|
68
- describe feature.name, feature.metadata_hash do
74
+ ::RSpec.describe feature.name, feature.metadata_hash do
69
75
  before do
70
76
  example = Turnip::RSpec.fetch_current_example(self)
71
77
  # This is kind of a hack, but it will make RSpec throw way nicer exceptions
@@ -38,7 +38,7 @@ module Turnip
38
38
 
39
39
  OPTIONAL_WORD_REGEXP = /(\\\s)?\\\(([^)]+)\\\)(\\\s)?/
40
40
  PLACEHOLDER_REGEXP = /:([\w]+)/
41
- ALTERNATIVE_WORD_REGEXP = /(\w+)((\/\w+)+)/
41
+ ALTERNATIVE_WORD_REGEXP = /([[:alpha:]]+)((\/[[:alpha:]]+)+)/
42
42
 
43
43
  def compile_regexp
44
44
  @placeholder_names = []
@@ -1,3 +1,3 @@
1
1
  module Turnip
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -1,11 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Turnip::Builder do
4
+ let(:builder) { Turnip::Builder.build(feature_file) }
5
+ let(:feature) { builder.features.first }
6
+
7
+ context 'simple scenarios' do
8
+ let(:feature_file) { File.expand_path('../examples/simple_feature.feature', File.dirname(__FILE__)) }
9
+ let(:steps) { feature.scenarios.first.steps }
10
+
11
+ it 'extracts step description' do
12
+ steps.map(&:description).should eq([
13
+ 'there is a monster',
14
+ 'I attack it',
15
+ 'it should die'
16
+ ])
17
+ end
18
+
19
+ it 'extracts step line' do
20
+ steps.map(&:line).should eq([3, 4, 5])
21
+ end
22
+
23
+ it 'extracts step keyword' do
24
+ steps.map(&:keyword).should eq(['Given ', 'When ', 'Then '])
25
+ end
26
+ end
27
+
4
28
  context "with scenario outlines" do
5
29
  let(:feature_file) { File.expand_path('../examples/scenario_outline.feature', File.dirname(__FILE__)) }
6
- let(:builder) { Turnip::Builder.build(feature_file) }
7
- let(:feature) { builder.features.first }
8
-
9
30
 
10
31
  it "extracts scenarios" do
11
32
  feature.scenarios.map(&:name).should eq([
@@ -30,8 +51,6 @@ describe Turnip::Builder do
30
51
 
31
52
  context "with example tables in scenario outlines" do
32
53
  let(:feature_file) { File.expand_path('../examples/scenario_outline_table_substitution.feature', File.dirname(__FILE__)) }
33
- let(:builder) { Turnip::Builder.build(feature_file) }
34
- let(:feature) { builder.features.first }
35
54
 
36
55
  it "replaces placeholders in tables in steps" do
37
56
  feature.scenarios[0].steps.map(&:description).should eq([
@@ -44,6 +63,20 @@ describe Turnip::Builder do
44
63
  table = feature.scenarios[1].steps[0].extra_args.find {|a| a.instance_of?(Turnip::Table)}
45
64
  table.hashes[0]['hit_points'].should == '8'
46
65
  end
66
+ end
47
67
 
68
+ context 'with example multiline in scenario outlines' do
69
+ let(:feature_file) { File.expand_path('../examples/scenario_outline_multiline_string_substitution.feature', File.dirname(__FILE__)) }
70
+ let(:steps) { feature.scenarios[1].steps }
71
+
72
+ it 'replaces placeholders in multiline in steps' do
73
+ steps.map(&:description).should eq([
74
+ 'there is a monster called "John Smith"',
75
+ 'the monster introduced himself:'
76
+ ])
77
+
78
+ multiline = steps[1].extra_args.first
79
+ multiline.should eq %q(Ahhhhhhh! i'm "John Smith"!)
80
+ end
48
81
  end
49
82
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe 'The CLI', :type => :integration do
4
4
  before do
5
- @result = %x(rspec -fs examples/*.feature)
5
+ @result = %x(rspec -fd examples/*.feature)
6
6
  end
7
7
 
8
8
  it "shows the correct description" do
@@ -11,7 +11,7 @@ describe 'The CLI', :type => :integration do
11
11
  end
12
12
 
13
13
  it "prints out failures and successes" do
14
- @result.should include('35 examples, 3 failures, 5 pending')
14
+ @result.should include('38 examples, 3 failures, 5 pending')
15
15
  end
16
16
 
17
17
  it "includes features in backtraces" do
@@ -30,7 +30,7 @@ describe 'The CLI', :type => :integration do
30
30
  it 'conforms to line-number option' do
31
31
  @result.should include('rspec ./examples/errors.feature:4')
32
32
  @result.should include('rspec ./examples/errors.feature:6')
33
- result_with_line_number = %x(rspec -fs ./examples/errors.feature:4)
33
+ result_with_line_number = %x(rspec -fd ./examples/errors.feature:4)
34
34
  result_with_line_number.should include('rspec ./examples/errors.feature:4')
35
35
  result_with_line_number.should_not include('rspec ./examples/errors.feature:6')
36
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -94,6 +94,7 @@ files:
94
94
  - examples/multiline_string.feature
95
95
  - examples/pending.feature
96
96
  - examples/scenario_outline.feature
97
+ - examples/scenario_outline_multiline_string_substitution.feature
97
98
  - examples/scenario_outline_table_substitution.feature
98
99
  - examples/simple_feature.feature
99
100
  - examples/step_calling.feature
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  requirements: []
153
154
  rubyforge_project: turnip
154
- rubygems_version: 2.2.1
155
+ rubygems_version: 2.2.2
155
156
  signing_key:
156
157
  specification_version: 4
157
158
  summary: Gherkin extension for RSpec
@@ -164,4 +165,3 @@ test_files:
164
165
  - spec/spec_helper.rb
165
166
  - spec/step_definition_spec.rb
166
167
  - spec/table_spec.rb
167
- has_rdoc: