cucumber_priority 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ doc
2
+ pkg
3
+ *.gem
4
+ .bundle
5
+ .idea
6
+ .rvmrc
7
+ log/*.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Henning Koch
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ cucumber_priority - overridable step definitions for Cucumber
2
+ =============================================================
3
+
4
+ [Cucumber](https://github.com/cucumber/cucumber-ruby) raises an error if more than one step definitions match a step.
5
+
6
+ This gem provides a way to mark step definitions as *overridable*, meaning that they can always be overshadowed by a more specific version without raising an error.
7
+
8
+
9
+ Examples
10
+ --------
11
+
12
+ ### Marking step definitions as overridable
13
+
14
+ To mark a step definition as overridable, call `#overridable` on the definition object:
15
+
16
+ Given /^there is a movie with a (.*?) tone$/ do
17
+ ...
18
+ end.overridable
19
+
20
+ Given there is a movie with a funny tone do
21
+ ...
22
+ end
23
+
24
+ The following step will now **no longer raise `Cucumber::Ambiguous`**:
25
+
26
+ Given there is a movie with a funny tone
27
+
28
+ If a step matches more than one non-overridable steps, Cucumber will still raise `Cucumber::Ambiguous`.
29
+
30
+
31
+ ### Defining priorities
32
+
33
+ You can define priorities for overridable steps by passing an numeric `:priority` option to `#overridable:`
34
+
35
+ Given /^there is a movie with a (.*?) tone$/ do
36
+ ...
37
+ end.overridable(priority: 1)
38
+
39
+ Given /^there is a movie with a (sad|upbeat|disturbing) tone$/ do
40
+ ...
41
+ end.overridable(priority: 5)
42
+
43
+ A higher priority wins the match.
44
+
45
+ A non-overridable step will always win over an overridable step regardless of its priority.
46
+
47
+
48
+ Supported Cucumber versions
49
+ ----------------------------
50
+
51
+ cucumber_priority is tested against Cucumber 1.2, 1.3 and 2.1.
52
+
53
+
54
+ Installation
55
+ ------------
56
+
57
+ In your `Gemfile` say:
58
+
59
+ gem 'cucumber_priority'
60
+
61
+ Now run `bundle install` and restart your server.
62
+
63
+
64
+ Development
65
+ -----------
66
+
67
+ - We run tests against several Cucumber versions.
68
+ - You can bundle all versions with `rake all:install`.
69
+ - You can run specs against all versions with `rake all:spec`.
70
+ See `spec/support/database.sample.yml` for an example.
71
+
72
+ If you would like to contribute:
73
+
74
+ - Fork the repository.
75
+ - Push your changes **with passing specs**.
76
+ - Send us a pull request.
77
+
78
+ I'm very eager to keep this gem leightweight and on topic. If you're unsure whether a change would make it into the gem [talk to me beforehand](mailto:henning.koch@makandra.de).
79
+
80
+
81
+ Credits
82
+ -------
83
+
84
+ Henning Koch from [makandra](http://www.makandra.com/)
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require 'rake'
2
+ require 'bundler/gem_tasks'
3
+
4
+ desc 'Default: Run all specs.'
5
+ task :default => 'all:spec'
6
+
7
+ namespace :all do
8
+
9
+ desc "Run specs on all versions"
10
+ task :spec do
11
+ success = true
12
+ for_each_gemfile do |gemfile|
13
+ rspec_binary = gemfile.include?('cucumber-1') ? 'spec' : 'rspec'
14
+ success &= system("bundle exec #{rspec_binary} spec")
15
+ end
16
+ fail "Tests failed" unless success
17
+ end
18
+
19
+ desc "Bundle all versions"
20
+ task :install do
21
+ for_each_gemfile do |gemfile|
22
+ system('bundle install')
23
+ end
24
+ end
25
+
26
+ desc "Update all versions"
27
+ task :update do
28
+ for_each_gemfile do |gemfile|
29
+ system('bundle update')
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ def for_each_gemfile
36
+ version = ENV['VERSION'] || '*'
37
+ Dir["gemfiles/Gemfile.#{version}"].sort.each do |gemfile|
38
+ next if gemfile =~ /.lock/
39
+ puts '', "\033[44m#{gemfile}\033[0m", ''
40
+ ENV['BUNDLE_GEMFILE'] = gemfile
41
+ yield(gemfile)
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cucumber_priority/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{cucumber_priority}
7
+ s.version = CucumberPriority::VERSION
8
+ s.authors = ["Henning Koch"]
9
+ s.email = %q{github@makandra.de}
10
+ s.homepage = %q{http://github.com/makandra/cucumber_priority}
11
+ s.summary = %q{Create records from Cucumber features without writing step definitions.}
12
+ s.description = %q{Cucumber Factory allows you to create ActiveRecord models from your Cucumber features without writing step definitions for each model.}
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency('cucumber')
21
+ s.add_dependency('activesupport')
22
+
23
+ end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'cucumber', '~> 1.2.0'
4
+ gem 'activesupport', '~> 2.3.0'
5
+ gem 'rspec', '~> 1.0'
@@ -0,0 +1,27 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (2.3.18)
5
+ builder (3.2.2)
6
+ cucumber (1.2.3)
7
+ builder (>= 2.1.2)
8
+ diff-lcs (>= 1.1.3)
9
+ gherkin (~> 2.11.6)
10
+ multi_json (~> 1.3)
11
+ diff-lcs (1.2.5)
12
+ gherkin (2.11.6)
13
+ json (>= 1.7.6)
14
+ json (1.8.3)
15
+ multi_json (1.11.2)
16
+ rspec (1.3.2)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ activesupport (~> 2.3.0)
23
+ cucumber (~> 1.2.0)
24
+ rspec (~> 1.0)
25
+
26
+ BUNDLED WITH
27
+ 1.10.6
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'cucumber', '~> 1.3.0'
4
+ gem 'activesupport', '~> 2.3.0'
5
+ gem 'rspec', '~> 1.0'
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (2.3.18)
5
+ builder (3.2.2)
6
+ cucumber (1.3.20)
7
+ builder (>= 2.1.2)
8
+ diff-lcs (>= 1.1.3)
9
+ gherkin (~> 2.12)
10
+ multi_json (>= 1.7.5, < 2.0)
11
+ multi_test (>= 0.1.2)
12
+ diff-lcs (1.2.5)
13
+ gherkin (2.12.2)
14
+ multi_json (~> 1.3)
15
+ multi_json (1.11.2)
16
+ multi_test (0.1.2)
17
+ rspec (1.3.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ activesupport (~> 2.3.0)
24
+ cucumber (~> 1.3.0)
25
+ rspec (~> 1.0)
26
+
27
+ BUNDLED WITH
28
+ 1.10.6
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'cucumber', '~> 2.1.0'
4
+ gem 'activesupport', '~> 4.2.0'
5
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,53 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.5)
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.1.0)
12
+ builder (>= 2.1.2)
13
+ cucumber-core (~> 1.3.0)
14
+ diff-lcs (>= 1.1.3)
15
+ gherkin3 (~> 3.1.0)
16
+ multi_json (>= 1.7.5, < 2.0)
17
+ multi_test (>= 0.1.2)
18
+ cucumber-core (1.3.0)
19
+ gherkin3 (~> 3.1.0)
20
+ diff-lcs (1.2.5)
21
+ gherkin3 (3.1.2)
22
+ i18n (0.7.0)
23
+ json (1.8.3)
24
+ minitest (5.8.3)
25
+ multi_json (1.11.2)
26
+ multi_test (0.1.2)
27
+ rspec (3.4.0)
28
+ rspec-core (~> 3.4.0)
29
+ rspec-expectations (~> 3.4.0)
30
+ rspec-mocks (~> 3.4.0)
31
+ rspec-core (3.4.1)
32
+ rspec-support (~> 3.4.0)
33
+ rspec-expectations (3.4.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.4.0)
36
+ rspec-mocks (3.4.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.4.0)
39
+ rspec-support (3.4.1)
40
+ thread_safe (0.3.5)
41
+ tzinfo (1.2.2)
42
+ thread_safe (~> 0.1)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ activesupport (~> 4.2.0)
49
+ cucumber (~> 2.1.0)
50
+ rspec (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 1.10.6
@@ -0,0 +1,14 @@
1
+ module Cucumber
2
+ class Ambiguous
3
+
4
+ attr_reader :matches
5
+
6
+ def initialize_with_storing_matches(step_name, matches, *args)
7
+ @matches = matches
8
+ initialize_without_storing_matches(step_name, matches, *args)
9
+ end
10
+
11
+ alias_method_chain :initialize, :storing_matches
12
+
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ module Cucumber
2
+ module RbSupport
3
+ class RbStepDefinition
4
+
5
+ def overridable(options = {})
6
+ @overridable = true
7
+ @priority = options[:priority]
8
+ self
9
+ end
10
+
11
+ def overridable?
12
+ !!@overridable
13
+ end
14
+
15
+ def priority
16
+ @priority ||= 0
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ module Cucumber
2
+ class Runtime
3
+ class SupportCode
4
+
5
+ def step_match_with_priority(*args)
6
+ step_match_without_priority(*args)
7
+ rescue Ambiguous => e
8
+ overridable, overriding = e.matches.partition { |match|
9
+ match.step_definition.overridable?
10
+ }
11
+ if overriding.size > 1
12
+ # If we have more than one overriding step definitions,
13
+ # this is an ambiguity error
14
+ raise
15
+ elsif overriding.size == 1
16
+ # If our ambiguity is due to another overridable step,
17
+ # we can use the overriding step
18
+ overriding.first
19
+ elsif overriding.size == 0
20
+ # If we have multiple overridable steps, we use the one
21
+ # with the highest priority.
22
+ overridable.sort_by { |match|
23
+ match.step_definition.priority
24
+ }.last
25
+ end
26
+ end
27
+
28
+ alias_method_chain :step_match, :priority
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module CucumberPriority
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'cucumber'
2
+ require 'cucumber/rb_support/rb_language'
3
+ require 'active_support/all' # for alias_method_chain
4
+
5
+ require 'cucumber_priority/ambiguous_error_ext'
6
+ require 'cucumber_priority/rb_step_definition_ext'
7
+ require 'cucumber_priority/support_code_ext'
8
+
@@ -0,0 +1,18 @@
1
+ def prepare_cucumber_example
2
+ @runtime = Cucumber::Runtime.new
3
+ language = @runtime.load_programming_language('rb')
4
+ scenario = double('scenario', :language => 'en', :accept_hook? => true)
5
+ language.send(:begin_scenario, scenario)
6
+ @world = language.current_world
7
+ @main = Object.new
8
+ @main.extend(Cucumber::RbSupport::RbDsl)
9
+ # @runtime.before(scenario)
10
+ end
11
+
12
+ def invoke_cucumber_step(step)
13
+ support_code.step_match(step).invoke(nil) # nil means no multiline args
14
+ end
15
+
16
+ def support_code
17
+ @runtime.instance_variable_get(:@support_code)
18
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ require_relative 'cucumber_helper'
4
+
5
+ describe Cucumber::Runtime, 'extended with cucumber_priority' do
6
+
7
+ before(:each) do
8
+ prepare_cucumber_example
9
+ end
10
+
11
+ describe '#step_match' do
12
+
13
+ it 'returns an overriding step if the only other match is a overridable step' do
14
+ overridable_step = @main.Given(/^there is a movie with a (.*?) tone$/){ }.overridable
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')
17
+ match.step_definition.should == overriding_step
18
+ match.should be_a(Cucumber::StepMatch)
19
+ end
20
+
21
+ it 'raises Cucumber::Ambiguous if more than two overriding steps match' do
22
+ @main.Given(/^there is a movie with (.*?) tone$/){}.overridable(:priority => 1000)
23
+ @main.Given(/^there is a movie with a [^ ]+ tone$/){}
24
+ @main.Given(/^there is a movie with a funny tone$/){}
25
+ expect do
26
+ support_code.step_match('there is a movie with a funny tone')
27
+ end.to raise_error(Cucumber::Ambiguous)
28
+ end
29
+
30
+ it 'returns the overridable step with the highest priority if no overriding steps match' do
31
+ overridable_step = @main.Given(/^there is a movie with a (.*?) tone$/){ }.overridable
32
+ higher_overridable_step = @main.Given(/^there is a movie with a [^ ]+ tone$/){ }.overridable(:priority => 5)
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')
35
+ match.step_definition.should == higher_overridable_step
36
+ match.should be_a(Cucumber::StepMatch)
37
+ end
38
+
39
+ end
40
+
41
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+
3
+ $: << File.join(File.dirname(__FILE__), "/../../lib" )
4
+ require 'cucumber_priority'
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber_priority
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Henning Koch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-11-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cucumber
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Cucumber Factory allows you to create ActiveRecord models from your Cucumber
47
+ features without writing step definitions for each model.
48
+ email: github@makandra.de
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - .ruby-version
56
+ - MIT-LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - cucumber_priority.gemspec
60
+ - gemfiles/Gemfile.cucumber-1.2
61
+ - gemfiles/Gemfile.cucumber-1.2.lock
62
+ - gemfiles/Gemfile.cucumber-1.3
63
+ - gemfiles/Gemfile.cucumber-1.3.lock
64
+ - gemfiles/Gemfile.cucumber-2.1
65
+ - gemfiles/Gemfile.cucumber-2.1.lock
66
+ - lib/cucumber_priority.rb
67
+ - lib/cucumber_priority/ambiguous_error_ext.rb
68
+ - lib/cucumber_priority/rb_step_definition_ext.rb
69
+ - lib/cucumber_priority/support_code_ext.rb
70
+ - lib/cucumber_priority/version.rb
71
+ - spec/cucumber_priority/cucumber_helper.rb
72
+ - spec/cucumber_priority/support_code_ext_spec.rb
73
+ - spec/spec.opts
74
+ - spec/spec_helper.rb
75
+ homepage: http://github.com/makandra/cucumber_priority
76
+ licenses:
77
+ - MIT
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.30
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Create records from Cucumber features without writing step definitions.
100
+ test_files: []