cucumber-usual_suspects 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use @cucumber-identify --create
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ GIT
2
+ remote: git://github.com/mattwynne/cucumber.git
3
+ revision: 988338135ba093be502919db0ba81e2dad5598f6
4
+ specs:
5
+ cucumber (0.10.0)
6
+ builder (>= 2.1.2)
7
+ diff-lcs (~> 1.1.2)
8
+ gherkin (~> 2.3.4)
9
+ json (~> 1.4.6)
10
+ term-ansicolor (~> 1.0.5)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ aruba (0.3.3)
16
+ childprocess (~> 0.1.7)
17
+ cucumber (~> 0.10)
18
+ rspec (~> 2.5)
19
+ builder (3.0.0)
20
+ childprocess (0.1.7)
21
+ ffi (~> 0.6.3)
22
+ diff-lcs (1.1.2)
23
+ ffi (0.6.3)
24
+ rake (>= 0.8.7)
25
+ gherkin (2.3.4)
26
+ json (~> 1.4.6)
27
+ json (1.4.6)
28
+ rake (0.8.7)
29
+ rspec (2.5.0)
30
+ rspec-core (~> 2.5.0)
31
+ rspec-expectations (~> 2.5.0)
32
+ rspec-mocks (~> 2.5.0)
33
+ rspec-core (2.5.1)
34
+ rspec-expectations (2.5.0)
35
+ diff-lcs (~> 1.1.2)
36
+ rspec-mocks (2.5.0)
37
+ term-ansicolor (1.0.5)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ aruba
44
+ cucumber!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008,2009 Aslak Hellesøy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ See the features
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'cucumber/rake/task'
2
+ Cucumber::Rake::Task.new do |task|
3
+ task.cucumber_opts = '--color --format progress'
4
+ end
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new do |task|
8
+ task.rspec_opts = '--color'
9
+ end
10
+
11
+ task :default => [:spec, :cucumber]
@@ -0,0 +1,44 @@
1
+ Feature: Identify an entity
2
+ In order to make step definitions more maintainable
3
+ As a cucumber test developer
4
+ I want a way to abstract out all the different ways of identifying domain entities
5
+
6
+ Scenario:
7
+ Given a file named "features/step_definitions/steps.rb" with:
8
+ """
9
+ $: << File.dirname(__FILE__) + '/../../../../lib'
10
+ require 'cucumber/usual_suspects'
11
+
12
+ class Person < Struct.new(:age, :name)
13
+ def to_s
14
+ 'I am a Person'.tap do |result|
15
+ result << " aged #{age}" unless age.nil?
16
+ result << " named #{name}" unless name.nil?
17
+ end
18
+ end
19
+ end
20
+
21
+ Identify 'a Person' do
22
+ as /a Person aged (\d+)/ do |age|
23
+ Person.new(age.to_i)
24
+ end
25
+
26
+ as /a Person named (\w+)/ do |name|
27
+ Person.new(nil, name)
28
+ end
29
+ end
30
+
31
+ Given /<a Person> with blonde hair/ do |person|
32
+ announce "#{person} and I have blonde hair"
33
+ end
34
+ """
35
+ And a file named "features/test.feature" with:
36
+ """
37
+ Feature:
38
+ Scenario:
39
+ Given a Person aged 5 with blonde hair
40
+ And a Person named Dave with blonde hair
41
+ """
42
+ When I successfully run "cucumber"
43
+ Then the output should contain "I am a Person aged 5 and I have blonde hair"
44
+ Then the output should contain "I am a Person named Dave and I have blonde hair"
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
File without changes
@@ -0,0 +1,32 @@
1
+ require 'cucumber/usual_suspects/identity'
2
+
3
+ module Cucumber
4
+ module UsualSuspects
5
+ module Api
6
+ # this tells UsualSuspects how to send Transforms to Cucumber
7
+ def transforms_registry=(value)
8
+ @transforms_registry = value
9
+ end
10
+
11
+ # expands the given regular expression according to any identities that have
12
+ # been remembered
13
+ def expand(regexp)
14
+ result = regexp.to_s
15
+ identities.each do |id|
16
+ result.gsub!("<#{id}>", "(#{id.regexp_string})")
17
+ end
18
+ Regexp.new result
19
+ end
20
+
21
+ def remember(description, definition)
22
+ identities << Identity.new(@transforms_registry, description, definition)
23
+ end
24
+
25
+ private
26
+
27
+ def identities
28
+ @identities ||= []
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module Cucumber
2
+ module RbSupport
3
+ module RbDsl
4
+ class << self
5
+ def extend_rb_language_with(extension_module)
6
+ @rb_language.extend(extension_module)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Cucumber
2
+ module UsualSuspects
3
+ module Dsl
4
+ def Identify(thing, &block)
5
+ UsualSuspects.remember(thing, block)
6
+ end
7
+ end
8
+ end
9
+ end
10
+ extend(Cucumber::UsualSuspects::Dsl)
@@ -0,0 +1,10 @@
1
+ module Cucumber
2
+ module UsualSuspects
3
+ module ExpandsStepDefinitionRegexps
4
+ def register_rb_step_definition(regexp, proc)
5
+ expanded_regexp = Cucumber::UsualSuspects.expand(regexp)
6
+ super expanded_regexp, proc
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module Cucumber
2
+ module UsualSuspects
3
+ class Identity
4
+ def initialize(transforms_registry, description, definition)
5
+ @transforms_registry, @description = transforms_registry, description
6
+ instance_exec(&definition)
7
+ end
8
+
9
+ def as(regexp, &block)
10
+ transforms << @transforms_registry.register_rb_transform(regexp, block)
11
+ end
12
+
13
+ def to_s
14
+ @description
15
+ end
16
+
17
+ def regexp_string
18
+ @transforms.map{ |t| t.to_s }.join("|")
19
+ end
20
+ private
21
+
22
+ def transforms
23
+ @transforms ||= []
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'cucumber/usual_suspects/api'
2
+ require 'cucumber/usual_suspects/cucumber_patches'
3
+ require 'cucumber/usual_suspects/dsl'
4
+
5
+ module Cucumber
6
+ module UsualSuspects
7
+ extend Api
8
+ self.transforms_registry = Cucumber::RbSupport::RbDsl
9
+
10
+ module ExpandsStepDefinitionRegexps
11
+ def register_rb_step_definition(regexp, proc)
12
+ expanded_regexp = Cucumber::UsualSuspects.expand(regexp)
13
+ super expanded_regexp, proc
14
+ end
15
+ end
16
+
17
+ Cucumber::RbSupport::RbDsl.extend_rb_language_with(ExpandsStepDefinitionRegexps)
18
+ end
19
+ end
20
+
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'cucumber/usual_suspects/api'
3
+
4
+ module Cucumber
5
+ describe UsualSuspects do
6
+ let(:subject) { Object.new.extend(UsualSuspects::Api) }
7
+ let(:transforms_registry) do
8
+ double('Cucumber Runtume', :register_rb_transform => '(?-mix:a friendly Badger)' )
9
+ end
10
+
11
+ before(:each) do
12
+ subject.transforms_registry = transforms_registry
13
+ end
14
+
15
+ describe ".expand" do
16
+ before(:each) do
17
+ subject.remember 'badger', lambda {
18
+ as /a friendly Badger/ do;end
19
+ }
20
+ end
21
+
22
+ context "with a matching identifier" do
23
+ it "expands to include the identifier's regular expression" do
24
+ new_regexp = subject.expand(/<badger> with trousers on/)
25
+ match = new_regexp.match("a friendly Badger with trousers on")
26
+ match.should_not be_nil
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-usual_suspects
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Matt Wynne
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-22 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: cucumber
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 51
30
+ segments:
31
+ - 0
32
+ - 10
33
+ - 2
34
+ version: 0.10.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: aruba
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: Identities for Cucumber step definitions
52
+ email: matt@mattwynne.net
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - LICENSE
59
+ - README.md
60
+ files:
61
+ - .bundle/config
62
+ - .gitignore
63
+ - .rvmrc
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - Rakefile
67
+ - features/identify_an_entity.feature
68
+ - features/step_definitions/aruba.rb
69
+ - features/support/env.rb
70
+ - lib/cucumber/usual_suspects.rb
71
+ - lib/cucumber/usual_suspects/api.rb
72
+ - lib/cucumber/usual_suspects/cucumber_patches.rb
73
+ - lib/cucumber/usual_suspects/dsl.rb
74
+ - lib/cucumber/usual_suspects/expands_step_definition_regexps.rb
75
+ - lib/cucumber/usual_suspects/identity.rb
76
+ - spec/cucumber/usual_suspects_spec.rb
77
+ - spec/spec_helper.rb
78
+ - LICENSE
79
+ - README.md
80
+ has_rdoc: true
81
+ homepage: http://github.com/mattwynne/cucumber-usual_suspects
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --charset=UTF-8
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.4.2
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: cucumber-usual_suspects-0.0.1
114
+ test_files:
115
+ - features/identify_an_entity.feature
116
+ - features/step_definitions/aruba.rb
117
+ - features/support/env.rb
118
+ - spec/cucumber/usual_suspects_spec.rb
119
+ - spec/spec_helper.rb