turnip 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 72456decf90242ed5674a042e9094c9934ff893a
4
+ data.tar.gz: 8f8bbb0a619043fbaf1a086a17c335d17f24ba9c
5
+ SHA512:
6
+ metadata.gz: ac830dc4654120f8499dd690c037a06e420f98aca282e6de2a36cf20830e1202d628ed1b1c8869e2bc069912c2731805fffde12466e7a5419c0a152061824b2f
7
+ data.tar.gz: 9e61d6909a13750d29517b6f56ff0ad971450f8efe7934bef86d05975d766d9aab3bb0fcca6d8a74557ee820c608cdb1b667b142b002a43d12d1b7397a791826
@@ -1,9 +1,5 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
- - ruby-head
5
- - rbx-19mode
6
- matrix:
7
- allow_failures:
8
- - rvm: ruby-head
9
-
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - jruby-19mode
data/README.md CHANGED
@@ -8,6 +8,11 @@ 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
+
11
16
  ## Installation
12
17
 
13
18
  Install the gem
@@ -239,7 +244,7 @@ step "the value is :num" do |num|
239
244
  @value = num
240
245
  end
241
246
 
242
- step "the value is the magic number"
247
+ step "the value is the magic number" do
243
248
  step "the value is 3"
244
249
  end
245
250
  ```
@@ -332,7 +337,7 @@ end
332
337
 
333
338
  Just require `turnip/capybara` in your `spec_helper`. You can now use the same
334
339
  tags you'd use in Cucumber to switch between drivers e.g. `@javascript` or
335
- `@selenium`. Your Turnip features will also be run with the `:type => :request`
340
+ `@selenium`. Your Turnip features will also be run with the `:type => :feature`
336
341
  metadata, so that Capybara is included and also any other extensions you might
337
342
  want to add.
338
343
 
@@ -22,9 +22,16 @@ module Turnip
22
22
  end
23
23
  end
24
24
 
25
+ module Line
26
+ def line
27
+ @raw.line
28
+ end
29
+ end
30
+
25
31
  class Feature
26
32
  include Tags
27
33
  include Name
34
+ include Line
28
35
 
29
36
  attr_reader :scenarios, :backgrounds
30
37
  attr_accessor :feature_tag
@@ -35,10 +42,6 @@ module Turnip
35
42
  @backgrounds = []
36
43
  end
37
44
 
38
- def line
39
- @raw.line
40
- end
41
-
42
45
  def metadata_hash
43
46
  super.merge(:type => Turnip.type, :turnip => true)
44
47
  end
@@ -55,6 +58,7 @@ module Turnip
55
58
  class Scenario
56
59
  include Tags
57
60
  include Name
61
+ include Line
58
62
 
59
63
  attr_accessor :steps
60
64
 
@@ -153,7 +157,8 @@ module Turnip
153
157
  if step.doc_string
154
158
  extra_args.push step.doc_string.value
155
159
  elsif step.rows
156
- extra_args.push Turnip::Table.new(step.rows.map { |row| row.cells(&:value) })
160
+ table = Turnip::Table.new(step.rows.map(&:cells).map(&:to_a))
161
+ extra_args.push(table)
157
162
  end
158
163
  @current_step_context.steps << Step.new(step.name, extra_args, step.line)
159
164
  end
@@ -42,8 +42,11 @@ module Turnip
42
42
  def run_step(feature_file, step)
43
43
  begin
44
44
  step(step)
45
- rescue Turnip::Pending
46
- pending("No such step: '#{step}'")
45
+ rescue Turnip::Pending => e
46
+ # This is kind of a hack, but it will make RSpec throw way nicer exceptions
47
+ example = Turnip::RSpec.fetch_current_example(self)
48
+ example.metadata[:line_number] = step.line
49
+ pending("No such step: '#{e}'")
47
50
  rescue StandardError => e
48
51
  e.backtrace.push "#{feature_file}:#{step.line}:in `#{step.description}'"
49
52
  raise e
@@ -52,10 +55,19 @@ module Turnip
52
55
  end
53
56
 
54
57
  class << self
58
+ def fetch_current_example(context)
59
+ if ::RSpec.respond_to?(:current_example)
60
+ ::RSpec.current_example
61
+ else
62
+ context.example
63
+ end
64
+ end
65
+
55
66
  def run(feature_file)
56
67
  Turnip::Builder.build(feature_file).features.each do |feature|
57
68
  describe feature.name, feature.metadata_hash do
58
69
  before do
70
+ example = Turnip::RSpec.fetch_current_example(self)
59
71
  # This is kind of a hack, but it will make RSpec throw way nicer exceptions
60
72
  example.metadata[:file_path] = feature_file
61
73
 
@@ -64,13 +76,14 @@ module Turnip
64
76
  end
65
77
  end
66
78
  feature.scenarios.each do |scenario|
67
- describe scenario.name, scenario.metadata_hash do
68
- it scenario.steps.map(&:description).join(' -> ') do
69
- scenario.steps.each do |step|
70
- run_step(feature_file, step)
79
+ instance_eval <<-EOS, feature_file, scenario.line
80
+ describe scenario.name, scenario.metadata_hash do it(scenario.steps.map(&:description).join(' -> ')) do
81
+ scenario.steps.each do |step|
82
+ run_step(feature_file, step)
83
+ end
71
84
  end
72
85
  end
73
- end
86
+ EOS
74
87
  end
75
88
  end
76
89
  end
@@ -1,5 +1,17 @@
1
1
  module Turnip
2
2
  class Table
3
+ class WidthMismatch < StandardError
4
+ def initialize(expected, actual)
5
+ super("Expected the table to be #{expected} columns wide, got #{actual}")
6
+ end
7
+ end
8
+
9
+ class ColumnNotExist < StandardError
10
+ def initialize(column_name)
11
+ super("The column named \"#{column_name}\" does not exist")
12
+ end
13
+ end
14
+
3
15
  attr_reader :raw
4
16
  alias_method :to_a, :raw
5
17
 
@@ -34,16 +46,19 @@ module Turnip
34
46
  raw.each { |row| yield(row) }
35
47
  end
36
48
 
49
+ def map_column!(name, strict = true)
50
+ index = headers.index(name.to_s)
51
+ if index.nil?
52
+ raise ColumnNotExist.new(name) if strict
53
+ else
54
+ rows.each { |row| row[index] = yield(row[index]) }
55
+ end
56
+ end
57
+
37
58
  private
38
59
 
39
60
  def width
40
61
  raw[0].size
41
62
  end
42
-
43
- class WidthMismatch < StandardError
44
- def initialize(expected, actual)
45
- super("Expected the table to be #{expected} columns wide, got #{actual}")
46
- end
47
- end
48
63
  end
49
64
  end
@@ -1,3 +1,3 @@
1
1
  module Turnip
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -41,13 +41,13 @@ describe Turnip::Execute do
41
41
  end
42
42
 
43
43
  it "can be executed with a builder step" do
44
- builder_step = stub(:to_s => "a cool step", :extra_args => [])
44
+ builder_step = double(:to_s => "a cool step", :extra_args => [])
45
45
  mod.step("a :test step") { |test| test.upcase }
46
46
  obj.step(builder_step).should == "COOL"
47
47
  end
48
48
 
49
49
  it "sends in extra arg from a builder step" do
50
- builder_step = stub(:to_s => "a cool step", :extra_args => ["foo"])
50
+ builder_step = double(:to_s => "a cool step", :extra_args => ["foo"])
51
51
  mod.step("a :test step") { |test, foo| test.upcase + foo }
52
52
  obj.step(builder_step).should == "COOLfoo"
53
53
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Turnip::DSL do
4
- let(:context) { stub.tap { |s| s.extend(Turnip::DSL) }}
4
+ let(:context) { double.tap { |s| s.extend(Turnip::DSL) }}
5
5
  let(:an_object) { Object.new.tap { |o| o.extend(Turnip::Execute) }}
6
6
  describe '.steps_for' do
7
7
  before do
@@ -22,7 +22,7 @@ describe Turnip::DSL do
22
22
  end
23
23
 
24
24
  it 'tells RSpec to include the module' do
25
- config = stub
25
+ config = double
26
26
  RSpec.should_receive(:configure).and_yield(config)
27
27
  config.should_receive(:include)
28
28
 
@@ -17,4 +17,21 @@ describe 'The CLI', :type => :integration do
17
17
  it "includes features in backtraces" do
18
18
  @result.should include('examples/errors.feature:5:in `raise error')
19
19
  end
20
+
21
+ it "includes the right step name when steps call steps" do
22
+ @result.should include("No such step: 'this is an unimplemented step'")
23
+ end
24
+
25
+ it 'prints line numbers of pending/failure scenario' do
26
+ @result.should include('./examples/pending.feature:3')
27
+ @result.should include('./examples/errors.feature:4')
28
+ end
29
+
30
+ it 'conforms to line-number option' do
31
+ @result.should include('rspec ./examples/errors.feature:4')
32
+ @result.should include('rspec ./examples/errors.feature:6')
33
+ result_with_line_number = %x(rspec -fs ./examples/errors.feature:4)
34
+ result_with_line_number.should include('rspec ./examples/errors.feature:4')
35
+ result_with_line_number.should_not include('rspec ./examples/errors.feature:6')
36
+ end
20
37
  end
@@ -1 +1,9 @@
1
- Dir.glob("examples/**/*steps.rb") { |f| load f, true }
1
+ require "pry"
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ c.syntax = [:should, :expect]
6
+ end
7
+ end
8
+
9
+ Dir.glob(File.expand_path("../examples/**/*steps.rb", File.dirname(__FILE__))) { |f| require f }
@@ -77,4 +77,22 @@ describe Turnip::Table do
77
77
  end
78
78
  end
79
79
 
80
+ describe '#map_column!' do
81
+ let(:raw) { [['name', 'age'], ['Dave', '31'], ['John', '45']] }
82
+ it 'iterates through the column value and assigns it the value returned by the block' do
83
+ table.map_column!(:age) { |age| age.to_i }
84
+ table.rows.should == [['Dave', 31], ['John', 45]]
85
+ end
86
+
87
+ context 'with undefined column' do
88
+
89
+ it 'raies an error' do
90
+ expect { table.map_column!(:undefined){} }.to raise_error Turnip::Table::ColumnNotExist
91
+ end
92
+ it 'not raises an error when the strict param is false' do
93
+ expect { table.map_column!(:undefined, false){} }.to_not raise_error
94
+ end
95
+ end
96
+ end
97
+
80
98
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.add_runtime_dependency "rspec", "~>2.0"
22
22
  s.add_runtime_dependency "gherkin", ">= 2.5"
23
23
  s.add_development_dependency "rake"
24
+ s.add_development_dependency "pry"
24
25
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jonas Nicklas
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-26 00:00:00.000000000 Z
11
+ date: 2014-01-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,33 +27,43 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: gherkin
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '2.5'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '2.5'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  description: Provides the ability to define steps and run Gherkin files from with
@@ -121,27 +128,26 @@ files:
121
128
  - turnip.gemspec
122
129
  homepage: ''
123
130
  licenses: []
131
+ metadata: {}
124
132
  post_install_message:
125
133
  rdoc_options: []
126
134
  require_paths:
127
135
  - lib
128
136
  required_ruby_version: !ruby/object:Gem::Requirement
129
- none: false
130
137
  requirements:
131
- - - ! '>='
138
+ - - '>='
132
139
  - !ruby/object:Gem::Version
133
140
  version: '0'
134
141
  required_rubygems_version: !ruby/object:Gem::Requirement
135
- none: false
136
142
  requirements:
137
- - - ! '>='
143
+ - - '>='
138
144
  - !ruby/object:Gem::Version
139
145
  version: '0'
140
146
  requirements: []
141
147
  rubyforge_project: turnip
142
- rubygems_version: 1.8.24
148
+ rubygems_version: 2.0.6
143
149
  signing_key:
144
- specification_version: 3
150
+ specification_version: 4
145
151
  summary: Gherkin extension for RSpec
146
152
  test_files:
147
153
  - spec/builder_spec.rb