cucumber_priority 0.1.1 → 0.1.2

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/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg
5
5
  .idea
6
6
  .rvmrc
7
7
  log/*.log
8
+ .byebug_history
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'cucumber', '~> 2.3.0'
4
+ gem 'activesupport', '~> 4.2.0'
5
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,55 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.5.1)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
10
+ builder (3.2.2)
11
+ cucumber (2.3.2)
12
+ builder (>= 2.1.2)
13
+ cucumber-core (~> 1.4.0)
14
+ cucumber-wire (~> 0.0.1)
15
+ diff-lcs (>= 1.1.3)
16
+ gherkin (~> 3.2.0)
17
+ multi_json (>= 1.7.5, < 2.0)
18
+ multi_test (>= 0.1.2)
19
+ cucumber-core (1.4.0)
20
+ gherkin (~> 3.2.0)
21
+ cucumber-wire (0.0.1)
22
+ diff-lcs (1.2.5)
23
+ gherkin (3.2.0)
24
+ i18n (0.7.0)
25
+ json (1.8.3)
26
+ minitest (5.8.4)
27
+ multi_json (1.11.2)
28
+ multi_test (0.1.2)
29
+ rspec (3.4.0)
30
+ rspec-core (~> 3.4.0)
31
+ rspec-expectations (~> 3.4.0)
32
+ rspec-mocks (~> 3.4.0)
33
+ rspec-core (3.4.3)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-expectations (3.4.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.4.0)
38
+ rspec-mocks (3.4.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.4.0)
41
+ rspec-support (3.4.1)
42
+ thread_safe (0.3.5)
43
+ tzinfo (1.2.2)
44
+ thread_safe (~> 0.1)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ activesupport (~> 4.2.0)
51
+ cucumber (~> 2.3.0)
52
+ rspec (~> 3.0)
53
+
54
+ BUNDLED WITH
55
+ 1.11.2
@@ -2,31 +2,63 @@ module Cucumber
2
2
  class Runtime
3
3
  class SupportCode
4
4
 
5
- def step_match_with_priority(*args)
6
- step_match_without_priority(*args)
7
- rescue Ambiguous => e
5
+ if method_defined?(:step_matches) || private_method_defined?(:step_matches)
6
+ # Cucumber 2.3 or higher has a single method #step_matches which returns an
7
+ # array of Cucumber::StepMatch objects.
8
+ # This method raises Cucumber::Ambiguous if the array has more than one element.
9
+
10
+ def step_matches_with_priority(*args)
11
+ step_matches_without_priority(*args)
12
+ rescue Ambiguous => e
13
+ resolve_ambiguity_through_priority(e)
14
+ end
15
+
16
+ alias_method_chain :step_matches, :priority
17
+
18
+ else
19
+ # Cucumber 2.1 or lower has a single method #step_match which returns a
20
+ # single Cucumber::StepMatch.
21
+ # This method raises Cucumber::Ambigiuous if there are two or more matches.
22
+
23
+ def step_match_with_priority(*args)
24
+ step_match_without_priority(*args)
25
+ rescue Ambiguous => e
26
+ resolve_ambiguity_through_priority(e).first
27
+ end
28
+
29
+ alias_method_chain :step_match, :priority
30
+
31
+ # This method doesn't exist in old Cucumbers.
32
+ # We define it so our specs have a unified API to match steps.
33
+ def step_matches(*args)
34
+ [step_match(*args)]
35
+ end
36
+
37
+ end
38
+
39
+ private
40
+
41
+ def resolve_ambiguity_through_priority(e)
8
42
  overridable, overriding = e.matches.partition { |match|
9
43
  match.step_definition.overridable?
10
44
  }
11
45
  if overriding.size > 1
12
46
  # If we have more than one overriding step definitions,
13
47
  # this is an ambiguity error
14
- raise
48
+ raise e
15
49
  elsif overriding.size == 1
16
50
  # If our ambiguity is due to another overridable step,
17
51
  # we can use the overriding step
18
- overriding.first
52
+ overriding
19
53
  elsif overriding.size == 0
20
54
  # If we have multiple overridable steps, we use the one
21
55
  # with the highest priority.
22
56
  overridable.sort_by { |match|
23
- match.step_definition.priority
24
- }.last
57
+ - match.step_definition.priority
58
+ }
25
59
  end
26
60
  end
27
61
 
28
- alias_method_chain :step_match, :priority
29
-
30
62
  end
31
63
  end
32
64
  end
@@ -1,3 +1,3 @@
1
1
  module CucumberPriority
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  def prepare_cucumber_example
2
2
  @runtime = Cucumber::Runtime.new
3
- language = @runtime.load_programming_language('rb')
3
+ language = load_ruby_language
4
4
  scenario = double('scenario', :language => 'en', :accept_hook? => true)
5
5
  language.send(:begin_scenario, scenario)
6
6
  @world = language.current_world
@@ -9,6 +9,12 @@ def prepare_cucumber_example
9
9
  # @runtime.before(scenario)
10
10
  end
11
11
 
12
+ def load_ruby_language
13
+ language = support_code.ruby if support_code.respond_to?(:ruby)
14
+ language ||= support_code.load_programming_language('rb')
15
+ language
16
+ end
17
+
12
18
  def invoke_cucumber_step(step)
13
19
  support_code.step_match(step).invoke(nil) # nil means no multiline args
14
20
  end
@@ -16,3 +22,7 @@ end
16
22
  def support_code
17
23
  @runtime.instance_variable_get(:@support_code)
18
24
  end
25
+
26
+ def first_step_match(*args)
27
+ support_code.send(:step_matches, *args).first
28
+ end
@@ -8,12 +8,12 @@ describe Cucumber::Runtime, 'extended with cucumber_priority' do
8
8
  prepare_cucumber_example
9
9
  end
10
10
 
11
- describe '#step_match' do
11
+ describe '#step_matches' do
12
12
 
13
13
  it 'returns an overriding step if the only other match is a overridable step' do
14
14
  overridable_step = @main.Given(/^there is a movie with a (.*?) tone$/){ }.overridable
15
15
  overriding_step = @main.Given(/^there is a movie with a funny tone$/){ }
16
- match = support_code.step_match('there is a movie with a funny tone')
16
+ match = first_step_match('there is a movie with a funny tone')
17
17
  match.step_definition.should == overriding_step
18
18
  match.should be_a(Cucumber::StepMatch)
19
19
  end
@@ -23,7 +23,7 @@ describe Cucumber::Runtime, 'extended with cucumber_priority' do
23
23
  @main.Given(/^there is a movie with a [^ ]+ tone$/){}
24
24
  @main.Given(/^there is a movie with a funny tone$/){}
25
25
  expect do
26
- support_code.step_match('there is a movie with a funny tone')
26
+ first_step_match('there is a movie with a funny tone')
27
27
  end.to raise_error(Cucumber::Ambiguous)
28
28
  end
29
29
 
@@ -31,7 +31,7 @@ describe Cucumber::Runtime, 'extended with cucumber_priority' do
31
31
  overridable_step = @main.Given(/^there is a movie with a (.*?) tone$/){ }.overridable
32
32
  higher_overridable_step = @main.Given(/^there is a movie with a [^ ]+ tone$/){ }.overridable(:priority => 5)
33
33
  lower_overridable_step = @main.Given(/^there is a movie with a [^ ]+ tone$/){ }.overridable(:priority => -5)
34
- match = support_code.step_match('there is a movie with a funny tone')
34
+ match = first_step_match('there is a movie with a funny tone')
35
35
  match.step_definition.should == higher_overridable_step
36
36
  match.should be_a(Cucumber::StepMatch)
37
37
  end
data/spec/spec_helper.rb CHANGED
@@ -2,3 +2,13 @@
2
2
 
3
3
  $: << File.join(File.dirname(__FILE__), "/../../lib" )
4
4
  require 'cucumber_priority'
5
+
6
+ if defined?(RSpec)
7
+ RSpec.configure do |config|
8
+ if config.respond_to?(:expect_with)
9
+ config.expect_with(:rspec) do |c|
10
+ c.syntax = [:expect, :should]
11
+ end
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber_priority
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-26 00:00:00.000000000 Z
12
+ date: 2016-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -64,6 +64,8 @@ files:
64
64
  - gemfiles/Gemfile.cucumber-1.3.lock
65
65
  - gemfiles/Gemfile.cucumber-2.1
66
66
  - gemfiles/Gemfile.cucumber-2.1.lock
67
+ - gemfiles/Gemfile.cucumber-2.3
68
+ - gemfiles/Gemfile.cucumber-2.3.lock
67
69
  - lib/cucumber_priority.rb
68
70
  - lib/cucumber_priority/ambiguous_error_ext.rb
69
71
  - lib/cucumber_priority/rb_step_definition_ext.rb