cucumber_factory 1.5.0 → 1.6.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/README.rdoc +72 -62
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/cucumber_factory.gemspec +2 -2
- data/lib/cucumber/factory.rb +4 -2
- data/spec/spec_helper.rb +7 -4
- data/spec/step_mother_ext_spec.rb +3 -3
- data/spec/steps_spec.rb +10 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,62 +1,72 @@
|
|
1
|
-
= Cucumber Factory - create ActiveRecord objects without step definitions
|
2
|
-
|
3
|
-
Cucumber Factory allows you to create ActiveRecord objects directly from your {Cucumber}[http://cukes.info/] features. No step definitions required.
|
4
|
-
|
5
|
-
==
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
==
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
1
|
+
= Cucumber Factory - create ActiveRecord objects without step definitions
|
2
|
+
|
3
|
+
Cucumber Factory allows you to create ActiveRecord objects directly from your {Cucumber}[http://cukes.info/] features. No step definitions required.
|
4
|
+
|
5
|
+
== Example
|
6
|
+
|
7
|
+
The following will call {Movie.make}[http://github.com/notahat/machinist], {Factory.create(:movie)}[http://github.com/thoughtbot/factory_girl], Movie.create! or Movie.new, depending on what's available:
|
8
|
+
Given there is a movie
|
9
|
+
|
10
|
+
To create a new record with attributes set, you can say:
|
11
|
+
Given there is a movie with the title "Sunshine" and the year "2007"
|
12
|
+
|
13
|
+
The following will also store the created record in <tt>@sunshine</tt>:
|
14
|
+
Given "Sunshine" is a movie with the title "Sunshine" and the year "2007"
|
15
|
+
|
16
|
+
To set associations you can refer to other records by name:
|
17
|
+
Given "Before Sunrise" is a movie
|
18
|
+
And "Before Sunset" is a movie with the prequel "Before Sunrise"
|
19
|
+
|
20
|
+
You can also refer to the last created object of a kind by saying "above":
|
21
|
+
Given there is a movie with the title "Before Sunrise"
|
22
|
+
And "Before Sunset" is a movie with the prequel above
|
23
|
+
|
24
|
+
== Factory support
|
25
|
+
|
26
|
+
{Machinist blueprints}[http://github.com/notahat/machinist] and {factory_girl factories}[http://github.com/thoughtbot/factory_girl] will be used when available.
|
27
|
+
|
28
|
+
You can use named Machinist blueprint such as <tt>Movie.blueprint(:comedy)</tt> like this:
|
29
|
+
|
30
|
+
Given a movie (comedy) with the title "Groundhog Day"
|
31
|
+
|
32
|
+
Inherited factory_girl factories are not supported yet.
|
33
|
+
|
34
|
+
== Overriding factory steps
|
35
|
+
|
36
|
+
If you want to override a factory step with your own version, just do so:
|
37
|
+
|
38
|
+
Given /^there is a movie with good actors$/ do
|
39
|
+
movie = Movie.make
|
40
|
+
movie.actors << Actor.make(:name => 'Clive Owen')
|
41
|
+
movie.actors << Actor.make(:name => 'Denzel Washington')
|
42
|
+
end
|
43
|
+
|
44
|
+
Custom steps will always be preferred over factory steps. Also Cucumber will not raise a warning about ambiguous steps if the only other matching step is a factory step.
|
45
|
+
|
46
|
+
== Installation and setup
|
47
|
+
|
48
|
+
Cucumber Factory is a gem, which you can install with
|
49
|
+
sudo gem install cucumber_factory
|
50
|
+
|
51
|
+
In Rails 2, add the following to your <tt>environment.rb</tt>:
|
52
|
+
config.gem 'cucumber_factory'
|
53
|
+
|
54
|
+
In Rails 3, add the following to your <tt>Gemfile</tt>:
|
55
|
+
gem 'cucumber_factory'
|
56
|
+
|
57
|
+
Finally, create a file <tt>features/step_definitions/factory_steps.rb</tt>, which just says
|
58
|
+
Cucumber::Factory.add_steps(self)
|
59
|
+
|
60
|
+
|
61
|
+
== Rails 3 compatibility
|
62
|
+
|
63
|
+
We cannot guarantee Rails 3 compatibility at this point, but we will upgrade the gem when Rails 3 is released.
|
64
|
+
|
65
|
+
|
66
|
+
=== Credits
|
67
|
+
|
68
|
+
Henning Koch
|
69
|
+
|
70
|
+
{makandra.com}[http://makandra.com/]
|
71
|
+
|
72
|
+
{gem-session.com}[http://gem-session.com/]
|
data/Rakefile
CHANGED
@@ -12,10 +12,10 @@ Spec::Rake::SpecTask.new() do |t|
|
|
12
12
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
13
13
|
end
|
14
14
|
|
15
|
-
desc 'Generate documentation for the
|
15
|
+
desc 'Generate documentation for the cucumber_factory gem.'
|
16
16
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
17
|
rdoc.rdoc_dir = 'rdoc'
|
18
|
-
rdoc.title = '
|
18
|
+
rdoc.title = 'cucumber_factory'
|
19
19
|
rdoc.options << '--line-numbers' << '--inline-source'
|
20
20
|
rdoc.rdoc_files.include('README')
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
@@ -32,6 +32,6 @@ begin
|
|
32
32
|
gemspec.authors = ["Henning Koch"]
|
33
33
|
end
|
34
34
|
rescue LoadError
|
35
|
-
puts "Jeweler not available. Install it with: sudo gem install
|
35
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
36
36
|
end
|
37
37
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.6.0
|
data/cucumber_factory.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cucumber_factory}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Henning Koch"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-17}
|
13
13
|
s.description = %q{Cucumber Factory allows you to create ActiveRecord models from your Cucumber features without writing step definitions for each model.}
|
14
14
|
s.email = %q{github@makandra.de}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/cucumber/factory.rb
CHANGED
@@ -5,10 +5,10 @@ module Cucumber
|
|
5
5
|
# List of Cucumber step definitions created by #add_steps
|
6
6
|
attr_reader :step_definitions
|
7
7
|
|
8
|
-
def add_steps(
|
8
|
+
def add_steps(main)
|
9
9
|
@step_definitions = []
|
10
10
|
steps.each do |step|
|
11
|
-
@step_definitions << (
|
11
|
+
@step_definitions << (main.instance_eval do
|
12
12
|
Given(step[:pattern], &step[:action])
|
13
13
|
end)
|
14
14
|
end
|
@@ -57,6 +57,8 @@ module Cucumber
|
|
57
57
|
else
|
58
58
|
value = world.instance_variable_get(variable_name_from_prose(value))
|
59
59
|
end
|
60
|
+
else
|
61
|
+
value = world.Transform(value)
|
60
62
|
end
|
61
63
|
attributes[attribute] = value
|
62
64
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,8 +21,11 @@ end
|
|
21
21
|
|
22
22
|
def prepare_cucumber_example
|
23
23
|
@step_mother = Cucumber::StepMother.new
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
language = @step_mother.load_programming_language('rb')
|
25
|
+
scenario = stub('scenario', :language => 'en')
|
26
|
+
language.send(:begin_scenario, scenario)
|
27
|
+
@world = language.current_world
|
28
|
+
@main = Object.new
|
29
|
+
@main.extend(Cucumber::RbSupport::RbDsl)
|
30
|
+
Cucumber::Factory.add_steps(@main)
|
28
31
|
end
|
@@ -12,13 +12,13 @@ describe Cucumber::StepMother, 'extended with cucumber_factory' do
|
|
12
12
|
describe 'step_match' do
|
13
13
|
|
14
14
|
it "should not raise an ambiguous step error and return the user step if the only other matching step is a factory step" do
|
15
|
-
user_step = @
|
15
|
+
user_step = @main.Given(/^there is a movie with a funny tone/){}
|
16
16
|
@step_mother.step_match('there is a movie with a funny tone').should == user_step
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should still raise an ambiguous step error if more than two non-factory steps match" do
|
20
|
-
@
|
21
|
-
@
|
20
|
+
@main.Given(/^there is a movie with (.*?) tone/){}
|
21
|
+
@main.Given(/^there is a movie with a funny tone/){}
|
22
22
|
expect do
|
23
23
|
@step_mother.step_match('there is a movie with a funny tone')
|
24
24
|
end.to raise_error(Cucumber::Ambiguous)
|
data/spec/steps_spec.rb
CHANGED
@@ -71,6 +71,14 @@ describe 'steps provided by cucumber_factory' do
|
|
71
71
|
@step_mother.invoke('there is a movie with the title "Sunshine" and the year "2007"')
|
72
72
|
end
|
73
73
|
|
74
|
+
it "should apply Cucumber transforms to attribute values" do
|
75
|
+
movie = Movie.new
|
76
|
+
Movie.stub(:new => movie)
|
77
|
+
@world.should_receive(:Transform).with("value").and_return("transformed value")
|
78
|
+
movie.should_receive(:"attributes=").with({ :title => "transformed value" }, false)
|
79
|
+
@step_mother.invoke('there is a movie with the title "value"')
|
80
|
+
end
|
81
|
+
|
74
82
|
it "should create records with attributes containing spaces" do
|
75
83
|
movie = Movie.new
|
76
84
|
Movie.stub(:new => movie)
|
@@ -94,13 +102,13 @@ describe 'steps provided by cucumber_factory' do
|
|
94
102
|
|
95
103
|
it "should set instance variables in the world" do
|
96
104
|
@step_mother.invoke('"Sunshine" is a movie with the title "Sunshine" and the year "2007"')
|
97
|
-
@
|
105
|
+
@world.instance_variable_get(:'@sunshine').title.should == "Sunshine"
|
98
106
|
end
|
99
107
|
|
100
108
|
it "should understand pointers to instance variables" do
|
101
109
|
@step_mother.invoke('"Before Sunrise" is a movie with the title "Before Sunrise"')
|
102
110
|
@step_mother.invoke('"Before Sunset" is a movie with the title "Before Sunset" and the prequel "Before Sunrise"')
|
103
|
-
@
|
111
|
+
@world.instance_variable_get(:'@before_sunset').prequel.title.should == "Before Sunrise"
|
104
112
|
end
|
105
113
|
|
106
114
|
it "should allow to point to a previously created record through 'above'" do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
7
|
+
- 6
|
8
8
|
- 0
|
9
|
-
version: 1.
|
9
|
+
version: 1.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Henning Koch
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-08-17 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|