cucumber_factory 1.7.4 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +5 -5
- data/README.rdoc +38 -13
- data/VERSION +1 -1
- data/cucumber_factory.gemspec +19 -19
- data/lib/cucumber/factory.rb +139 -115
- data/spec/factory_spec.rb +5 -27
- data/spec/spec_helper.rb +2 -1
- data/spec/steps_spec.rb +23 -14
- metadata +22 -22
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -39,10 +39,10 @@ GEM
|
|
39
39
|
activesupport (= 2.3.8)
|
40
40
|
rake (>= 0.8.3)
|
41
41
|
rake (0.8.7)
|
42
|
-
rspec (1.2
|
43
|
-
rspec-rails (1.2
|
42
|
+
rspec (1.3.2)
|
43
|
+
rspec-rails (1.3.2)
|
44
44
|
rack (>= 1.0.0)
|
45
|
-
rspec (>= 1.
|
45
|
+
rspec (>= 1.3.0)
|
46
46
|
rubyforge (2.0.4)
|
47
47
|
json_pure (>= 1.1.7)
|
48
48
|
term-ansicolor (1.0.5)
|
@@ -54,5 +54,5 @@ DEPENDENCIES
|
|
54
54
|
cucumber (= 0.9.3)
|
55
55
|
jeweler
|
56
56
|
rails (= 2.3.8)
|
57
|
-
rspec (= 1.2
|
58
|
-
rspec-rails (= 1.2
|
57
|
+
rspec (= 1.3.2)
|
58
|
+
rspec-rails (= 1.3.2)
|
data/README.rdoc
CHANGED
@@ -2,41 +2,61 @@
|
|
2
2
|
|
3
3
|
Cucumber Factory allows you to create ActiveRecord objects directly from your {Cucumber}[http://cukes.info/] features. No step definitions required.
|
4
4
|
|
5
|
+
|
5
6
|
== Examples
|
6
7
|
|
7
8
|
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:
|
9
|
+
|
8
10
|
Given there is a movie
|
9
11
|
|
10
12
|
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
13
|
|
16
|
-
|
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
|
14
|
+
Given there is a movie with the title "Sunshine" and the year "2007"
|
23
15
|
|
24
16
|
Boolean attributes can be set by appending "which", "that" or "who" at the end:
|
17
|
+
|
25
18
|
Given there is a movie which is awesome
|
26
19
|
And there is a movie with the name "Sunshine" that is not a comedy
|
27
20
|
And there is a director who is popular
|
28
21
|
|
29
22
|
Instead of "and" you can also use "but" and commas to join sentences:
|
23
|
+
|
30
24
|
Given there is a movie which is awesome, popular and successful but not science fiction
|
31
25
|
And there is a director with the income "500000" but with the account balance "-30000"
|
32
26
|
|
33
|
-
|
27
|
+
|
28
|
+
== Setting associations
|
29
|
+
|
30
|
+
You can set <tt>belongs_to</tt> associations by referring to the last created record of a kind by saying "above":
|
31
|
+
|
32
|
+
Given there is a movie with the title "Before Sunrise"
|
33
|
+
And there is a movie with the prequel above
|
34
|
+
|
35
|
+
The example above also shows how to set <tt>has_many</tt> associations - you simply set the <tt>belongs_to</tt> association on the other side.
|
36
|
+
|
37
|
+
You can also set associations by referring to any string attribute used previously:
|
38
|
+
|
39
|
+
Given there is a movie with the title "Before Sunrise"
|
40
|
+
And there is a movie with the title "Limitless"
|
41
|
+
And there is a movie with the prequel "Before Sunrise"
|
42
|
+
|
43
|
+
You can also explicitly give a record a name and use it to set a <tt>belongs_to</tt> association below:
|
44
|
+
|
45
|
+
Given "Before Sunrise" is a movie
|
46
|
+
And there is a movie with the title "Limitless"
|
47
|
+
And there is a movie with the prequel "Before Sunrise"
|
48
|
+
|
49
|
+
Note that in the example above, "Before Sunrise" is only a name you can use to refer to the record. The name is not actually used for the movie title, or any other attribute value.
|
50
|
+
|
51
|
+
|
52
|
+
== Fixture factory support
|
34
53
|
|
35
54
|
{Machinist blueprints}[http://github.com/notahat/machinist] and {factory_girl factories}[http://github.com/thoughtbot/factory_girl] will be used when available.
|
36
55
|
|
37
56
|
You can use named Machinist blueprint such as <tt>Movie.blueprint(:comedy)</tt> like this:
|
38
57
|
|
39
|
-
Given a movie (comedy) with the title "Groundhog Day"
|
58
|
+
Given there is a movie (comedy) with the title "Groundhog Day"
|
59
|
+
|
40
60
|
|
41
61
|
== Overriding factory steps
|
42
62
|
|
@@ -50,18 +70,23 @@ If you want to override a factory step with your own version, just do so:
|
|
50
70
|
|
51
71
|
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.
|
52
72
|
|
73
|
+
|
53
74
|
== Installation and setup
|
54
75
|
|
55
76
|
Cucumber Factory is a gem, which you can install with
|
77
|
+
|
56
78
|
sudo gem install cucumber_factory
|
57
79
|
|
58
80
|
In Rails 2, add the following to your <tt>environment.rb</tt>:
|
81
|
+
|
59
82
|
config.gem 'cucumber_factory'
|
60
83
|
|
61
84
|
In Rails 3, add the following to your <tt>Gemfile</tt>:
|
85
|
+
|
62
86
|
gem 'cucumber_factory'
|
63
87
|
|
64
88
|
Finally, create a file <tt>features/step_definitions/factory_steps.rb</tt>, which just says
|
89
|
+
|
65
90
|
Cucumber::Factory.add_steps(self)
|
66
91
|
|
67
92
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.8.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.8.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{
|
12
|
+
s.date = %q{2011-06-12}
|
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 = [
|
@@ -65,32 +65,32 @@ Gem::Specification.new do |s|
|
|
65
65
|
s.rubygems_version = %q{1.3.7}
|
66
66
|
s.summary = %q{Create records from Cucumber features without writing step definitions.}
|
67
67
|
s.test_files = [
|
68
|
-
"spec/
|
69
|
-
"spec/
|
70
|
-
"spec/
|
68
|
+
"spec/runtime_ext_spec.rb",
|
69
|
+
"spec/steps_spec.rb",
|
70
|
+
"spec/spec_helper.rb",
|
71
|
+
"spec/factory_spec.rb",
|
72
|
+
"spec/app_root/db/migrate/003_create_payments.rb",
|
73
|
+
"spec/app_root/db/migrate/001_create_movies.rb",
|
74
|
+
"spec/app_root/db/migrate/004_create_actors.rb",
|
75
|
+
"spec/app_root/db/migrate/002_create_users.rb",
|
71
76
|
"spec/app_root/app/models/movie.rb",
|
77
|
+
"spec/app_root/app/models/machinist_model.rb",
|
72
78
|
"spec/app_root/app/models/opera.rb",
|
73
|
-
"spec/app_root/app/models/
|
74
|
-
"spec/app_root/app/models/plain_ruby_class.rb",
|
79
|
+
"spec/app_root/app/models/job_offer.rb",
|
75
80
|
"spec/app_root/app/models/user.rb",
|
76
81
|
"spec/app_root/app/models/people/actor.rb",
|
82
|
+
"spec/app_root/app/models/payment.rb",
|
83
|
+
"spec/app_root/app/models/plain_ruby_class.rb",
|
84
|
+
"spec/app_root/app/controllers/application_controller.rb",
|
85
|
+
"spec/app_root/lib/console_with_fixtures.rb",
|
77
86
|
"spec/app_root/config/boot.rb",
|
78
87
|
"spec/app_root/config/environment.rb",
|
88
|
+
"spec/app_root/config/routes.rb",
|
79
89
|
"spec/app_root/config/environments/in_memory.rb",
|
80
|
-
"spec/app_root/config/environments/mysql.rb",
|
81
|
-
"spec/app_root/config/environments/postgresql.rb",
|
82
90
|
"spec/app_root/config/environments/sqlite.rb",
|
91
|
+
"spec/app_root/config/environments/postgresql.rb",
|
83
92
|
"spec/app_root/config/environments/sqlite3.rb",
|
84
|
-
"spec/app_root/config/
|
85
|
-
"spec/app_root/db/migrate/001_create_movies.rb",
|
86
|
-
"spec/app_root/db/migrate/002_create_users.rb",
|
87
|
-
"spec/app_root/db/migrate/003_create_payments.rb",
|
88
|
-
"spec/app_root/db/migrate/004_create_actors.rb",
|
89
|
-
"spec/app_root/lib/console_with_fixtures.rb",
|
90
|
-
"spec/spec_helper.rb",
|
91
|
-
"spec/factory_spec.rb",
|
92
|
-
"spec/runtime_ext_spec.rb",
|
93
|
-
"spec/steps_spec.rb"
|
93
|
+
"spec/app_root/config/environments/mysql.rb"
|
94
94
|
]
|
95
95
|
|
96
96
|
if s.respond_to? :specification_version then
|
data/lib/cucumber/factory.rb
CHANGED
@@ -1,115 +1,139 @@
|
|
1
|
-
module Cucumber
|
2
|
-
|
3
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
1
|
+
module Cucumber
|
2
|
+
class Factory
|
3
|
+
|
4
|
+
ATTRIBUTES_PATTERN = '( with the .+?)?( (?:which|who|that) is .+?)?'
|
5
|
+
|
6
|
+
NAMED_RECORDS_VARIABLE = :'@named_cucumber_factory_records'
|
7
|
+
|
8
|
+
CLEAR_NAMED_RECORDS_STEP_DESCRIPTOR = {
|
9
|
+
:kind => :Before,
|
10
|
+
:block => lambda { instance_variable_set(NAMED_RECORDS_VARIABLE, {}) }
|
11
|
+
}
|
12
|
+
|
13
|
+
NAMED_CREATION_STEP_DESCRIPTOR = {
|
14
|
+
:kind => :Given,
|
15
|
+
:pattern => /^"([^\"]*)" is an? (.+?)( \(.+?\))?#{ATTRIBUTES_PATTERN}?$/,
|
16
|
+
# we cannot use vararg blocks here in Ruby 1.8, as explained by Aslak: http://www.ruby-forum.com/topic/182927
|
17
|
+
:block => lambda { |a1, a2, a3, a4, a5| Cucumber::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5) }
|
18
|
+
}
|
19
|
+
|
20
|
+
CREATION_STEP_DESCRIPTOR = {
|
21
|
+
:kind => :Given,
|
22
|
+
:pattern => /^there is an? (.+?)( \(.+?\))?#{ATTRIBUTES_PATTERN}$/,
|
23
|
+
# we cannot use vararg blocks here in Ruby 1.8, as explained by Aslak: http://www.ruby-forum.com/topic/182927
|
24
|
+
:block => lambda { |a1, a2, a3, a4| Cucumber::Factory.send(:parse_creation, self, a1, a2, a3, a4) }
|
25
|
+
}
|
26
|
+
|
27
|
+
class << self
|
28
|
+
|
29
|
+
attr_reader :step_definitions
|
30
|
+
|
31
|
+
def add_steps(main)
|
32
|
+
add_step(main, CREATION_STEP_DESCRIPTOR)
|
33
|
+
add_step(main, NAMED_CREATION_STEP_DESCRIPTOR)
|
34
|
+
add_step(main, CLEAR_NAMED_RECORDS_STEP_DESCRIPTOR)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def add_step(main, descriptor)
|
40
|
+
@step_definitions ||= []
|
41
|
+
step_definition = main.instance_eval { send(descriptor[:kind], *[descriptor[:pattern]].compact, &descriptor[:block]) }
|
42
|
+
@step_definitions << step_definition
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_named_record(world, name)
|
46
|
+
world.instance_variable_get(NAMED_RECORDS_VARIABLE)[name]
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_named_record(world, name, record)
|
50
|
+
world.instance_variable_get(NAMED_RECORDS_VARIABLE)[name] = record
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_named_creation(world, name, raw_model, raw_variant, raw_attributes, raw_boolean_attributes)
|
54
|
+
record = parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_attributes)
|
55
|
+
set_named_record(world, name, record)
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_attributes)
|
59
|
+
model_class = model_class_from_prose(raw_model)
|
60
|
+
attributes = {}
|
61
|
+
if raw_attributes.try(:strip).present?
|
62
|
+
raw_attributes.scan(/(?:the|and|with|but|,| )+(.*?) ("([^\"]*)"|above)/).each do |fragment|
|
63
|
+
attribute = attribute_name_from_prose(fragment[0])
|
64
|
+
value_type = fragment[1] # 'above' or a quoted string
|
65
|
+
value = fragment[2] # the value string without quotes
|
66
|
+
attributes[attribute] = attribute_value(world, model_class, attribute, value_type, value)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
if raw_boolean_attributes.try(:strip).present?
|
70
|
+
raw_boolean_attributes.scan(/(?:which|who|that|is| )*(not )?(.+?)(?: and | but |,|$)+/).each do |fragment|
|
71
|
+
flag = !fragment[0] # if the word 'not' didn't match above, this expression is true
|
72
|
+
attribute = attribute_name_from_prose(fragment[1])
|
73
|
+
attributes[attribute] = flag
|
74
|
+
end
|
75
|
+
end
|
76
|
+
variant = raw_variant.present? && /\((.*?)\)/.match(raw_variant)[1].downcase.gsub(" ", "_")
|
77
|
+
record = create_record(model_class, variant, attributes)
|
78
|
+
remember_record_names(world, record, attributes)
|
79
|
+
record
|
80
|
+
end
|
81
|
+
|
82
|
+
def attribute_value(world, model_class, attribute, value_type, value)
|
83
|
+
association = model_class.respond_to?(:reflect_on_association) ? model_class.reflect_on_association(attribute) : nil
|
84
|
+
if association.present?
|
85
|
+
if value_type == "above"
|
86
|
+
# Don't use class.last, in sqlite that is not always the last inserted element
|
87
|
+
value = association.klass.find(:last, :order => "id") or raise "There is no last #{attribute}"
|
88
|
+
else
|
89
|
+
value = get_named_record(world, value)
|
90
|
+
end
|
91
|
+
else
|
92
|
+
value = world.Transform(value)
|
93
|
+
end
|
94
|
+
value
|
95
|
+
end
|
96
|
+
|
97
|
+
def attribute_name_from_prose(prose)
|
98
|
+
prose.downcase.gsub(" ", "_").to_sym
|
99
|
+
end
|
100
|
+
|
101
|
+
def model_class_from_prose(prose)
|
102
|
+
# don't use \w which depends on the system locale
|
103
|
+
prose.gsub(/[^A-Za-z0-9_\/]+/, "_").camelize.constantize
|
104
|
+
end
|
105
|
+
|
106
|
+
def factory_girl_factory_name(name)
|
107
|
+
name.to_s.underscore.to_sym
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_record(model_class, variant, attributes)
|
111
|
+
fg_factory_name = factory_girl_factory_name(variant || model_class)
|
112
|
+
if defined?(::Factory) && factory = ::Factory.factories[fg_factory_name]
|
113
|
+
::Factory.create(fg_factory_name, attributes)
|
114
|
+
elsif model_class.respond_to?(:make) # Machinist blueprint
|
115
|
+
if variant.present?
|
116
|
+
model_class.make(variant.to_sym, attributes)
|
117
|
+
else
|
118
|
+
model_class.make(attributes)
|
119
|
+
end
|
120
|
+
elsif model_class.respond_to?(:create!) # Plain ActiveRecord
|
121
|
+
model = model_class.new
|
122
|
+
model.send(:attributes=, attributes, false) # ignore attr_accessible
|
123
|
+
model.save!
|
124
|
+
model
|
125
|
+
else
|
126
|
+
model_class.new(attributes)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def remember_record_names(world, record, attributes)
|
131
|
+
string_values = attributes.values.select { |v| v.is_a?(String) }
|
132
|
+
for string_value in string_values
|
133
|
+
set_named_record(world, string_value, record)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/spec/factory_spec.rb
CHANGED
@@ -2,41 +2,19 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
|
3
3
|
describe Cucumber::Factory do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
it "should add Given rules to the world" do
|
8
|
-
world = mock('world').as_null_object
|
9
|
-
world.should_receive(:Given).exactly(2).times
|
10
|
-
Cucumber::Factory.add_steps(world)
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
5
|
+
subject { Cucumber::Factory }
|
6
|
+
|
15
7
|
describe 'model_class_from_prose' do
|
16
8
|
|
17
9
|
it "should return the class matching a natural language expression" do
|
18
|
-
|
19
|
-
|
10
|
+
subject.send(:model_class_from_prose, "movie").should == Movie
|
11
|
+
subject.send(:model_class_from_prose, "job offer").should == JobOffer
|
20
12
|
end
|
21
13
|
|
22
14
|
it "should allow namespaced models" do
|
23
|
-
|
15
|
+
subject.send(:model_class_from_prose, "people/actor").should == People::Actor
|
24
16
|
end
|
25
17
|
|
26
18
|
end
|
27
19
|
|
28
|
-
describe 'variable_name_from_prose' do
|
29
|
-
|
30
|
-
it "should translate natural language to instance variable names" do
|
31
|
-
Cucumber::Factory.send(:variable_name_from_prose, "movie").should == :'@movie'
|
32
|
-
Cucumber::Factory.send(:variable_name_from_prose, "Some Movie").should == :'@some_movie'
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should make sure the generated instance variable names are legal" do
|
36
|
-
Cucumber::Factory.send(:variable_name_from_prose, "1973").should == :'@_1973'
|
37
|
-
Cucumber::Factory.send(:variable_name_from_prose, "%$§").should == :'@_'
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
20
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -22,12 +22,13 @@ end
|
|
22
22
|
def prepare_cucumber_example
|
23
23
|
@runtime = Cucumber::Runtime.new
|
24
24
|
language = @runtime.load_programming_language('rb')
|
25
|
-
scenario = stub('scenario', :language => 'en')
|
25
|
+
scenario = stub('scenario', :language => 'en', :accept_hook? => true)
|
26
26
|
language.send(:begin_scenario, scenario)
|
27
27
|
@world = language.current_world
|
28
28
|
@main = Object.new
|
29
29
|
@main.extend(Cucumber::RbSupport::RbDsl)
|
30
30
|
Cucumber::Factory.add_steps(@main)
|
31
|
+
@runtime.before(scenario)
|
31
32
|
end
|
32
33
|
|
33
34
|
def invoke_cucumber_step(step)
|
data/spec/steps_spec.rb
CHANGED
@@ -79,36 +79,40 @@ describe 'steps provided by cucumber_factory' do
|
|
79
79
|
it "should create records with attributes" do
|
80
80
|
movie = Movie.new
|
81
81
|
Movie.stub(:new => movie)
|
82
|
-
movie.should_receive(:
|
82
|
+
movie.should_receive(:attributes=).with({ :title => "Sunshine", :year => "2007" }, false)
|
83
83
|
invoke_cucumber_step('there is a movie with the title "Sunshine" and the year "2007"')
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should allow to join attribute lists with 'and's, commas and 'but's" do
|
87
87
|
movie = Movie.new
|
88
88
|
Movie.stub(:new => movie)
|
89
|
-
movie.should_receive(:
|
89
|
+
movie.should_receive(:attributes=).with({ :title => "Sunshine", :year => "2007", :box_office_result => "32000000" }, false)
|
90
90
|
invoke_cucumber_step('there is a movie with the title "Sunshine", the year "2007" but with the box office result "32000000"')
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should apply Cucumber transforms to attribute values" do
|
94
94
|
movie = Movie.new
|
95
95
|
Movie.stub(:new => movie)
|
96
|
-
@
|
97
|
-
|
96
|
+
@main.instance_eval do
|
97
|
+
Transform /^(value)$/ do |value|
|
98
|
+
'transformed value'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
movie.should_receive(:attributes=).with({ :title => "transformed value" }, false)
|
98
102
|
invoke_cucumber_step('there is a movie with the title "value"')
|
99
103
|
end
|
100
104
|
|
101
105
|
it "should create records with attributes containing spaces" do
|
102
106
|
movie = Movie.new
|
103
107
|
Movie.stub(:new => movie)
|
104
|
-
movie.should_receive(:
|
108
|
+
movie.should_receive(:attributes=).with({ :box_office_result => "99999999" }, false)
|
105
109
|
invoke_cucumber_step('there is a movie with the box office result "99999999"')
|
106
110
|
end
|
107
111
|
|
108
112
|
it "should create records with attributes containing uppercase characters" do
|
109
113
|
user = User.new
|
110
114
|
User.stub(:new => user)
|
111
|
-
user.should_receive(:
|
115
|
+
user.should_receive(:attributes=).with({ :name => "Susanne" }, false)
|
112
116
|
invoke_cucumber_step('there is a User with the Name "Susanne"')
|
113
117
|
end
|
114
118
|
|
@@ -119,18 +123,23 @@ describe 'steps provided by cucumber_factory' do
|
|
119
123
|
payment.comment.should == 'Thanks for lending'
|
120
124
|
end
|
121
125
|
|
122
|
-
it "should set
|
123
|
-
invoke_cucumber_step('"
|
124
|
-
|
126
|
+
it "should allow to name records and set a belongs_to association to that record by refering to that name" do
|
127
|
+
invoke_cucumber_step('"Some Prequel" is a movie with the title "Before Sunrise"')
|
128
|
+
invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Some Prequel"')
|
129
|
+
movie = Movie.find_by_title!('Before Sunset')
|
130
|
+
prequel = Movie.find_by_title!('Before Sunrise')
|
131
|
+
movie.prequel.should == prequel
|
125
132
|
end
|
126
133
|
|
127
|
-
it "should
|
128
|
-
invoke_cucumber_step('
|
129
|
-
invoke_cucumber_step('
|
130
|
-
|
134
|
+
it "should allow to set a belongs_to association to a previously created record by refering to any string attribute of that record" do
|
135
|
+
invoke_cucumber_step('there is a movie with the title "Before Sunrise"')
|
136
|
+
invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Before Sunrise"')
|
137
|
+
movie = Movie.find_by_title!('Before Sunset')
|
138
|
+
prequel = Movie.find_by_title!('Before Sunrise')
|
139
|
+
movie.prequel.should == prequel
|
131
140
|
end
|
132
141
|
|
133
|
-
it "should allow to
|
142
|
+
it "should allow to set a belongs_to association to a previously created record by saying 'above'" do
|
134
143
|
invoke_cucumber_step('there is a user with the name "Jane"')
|
135
144
|
invoke_cucumber_step('there is a movie with the title "Before Sunrise"')
|
136
145
|
invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer above and the prequel above')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 1.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-06-12 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -105,29 +105,29 @@ signing_key:
|
|
105
105
|
specification_version: 3
|
106
106
|
summary: Create records from Cucumber features without writing step definitions.
|
107
107
|
test_files:
|
108
|
-
- spec/
|
109
|
-
- spec/
|
110
|
-
- spec/
|
108
|
+
- spec/runtime_ext_spec.rb
|
109
|
+
- spec/steps_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/factory_spec.rb
|
112
|
+
- spec/app_root/db/migrate/003_create_payments.rb
|
113
|
+
- spec/app_root/db/migrate/001_create_movies.rb
|
114
|
+
- spec/app_root/db/migrate/004_create_actors.rb
|
115
|
+
- spec/app_root/db/migrate/002_create_users.rb
|
111
116
|
- spec/app_root/app/models/movie.rb
|
117
|
+
- spec/app_root/app/models/machinist_model.rb
|
112
118
|
- spec/app_root/app/models/opera.rb
|
113
|
-
- spec/app_root/app/models/
|
114
|
-
- spec/app_root/app/models/plain_ruby_class.rb
|
119
|
+
- spec/app_root/app/models/job_offer.rb
|
115
120
|
- spec/app_root/app/models/user.rb
|
116
121
|
- spec/app_root/app/models/people/actor.rb
|
122
|
+
- spec/app_root/app/models/payment.rb
|
123
|
+
- spec/app_root/app/models/plain_ruby_class.rb
|
124
|
+
- spec/app_root/app/controllers/application_controller.rb
|
125
|
+
- spec/app_root/lib/console_with_fixtures.rb
|
117
126
|
- spec/app_root/config/boot.rb
|
118
127
|
- spec/app_root/config/environment.rb
|
128
|
+
- spec/app_root/config/routes.rb
|
119
129
|
- spec/app_root/config/environments/in_memory.rb
|
120
|
-
- spec/app_root/config/environments/mysql.rb
|
121
|
-
- spec/app_root/config/environments/postgresql.rb
|
122
130
|
- spec/app_root/config/environments/sqlite.rb
|
131
|
+
- spec/app_root/config/environments/postgresql.rb
|
123
132
|
- spec/app_root/config/environments/sqlite3.rb
|
124
|
-
- spec/app_root/config/
|
125
|
-
- spec/app_root/db/migrate/001_create_movies.rb
|
126
|
-
- spec/app_root/db/migrate/002_create_users.rb
|
127
|
-
- spec/app_root/db/migrate/003_create_payments.rb
|
128
|
-
- spec/app_root/db/migrate/004_create_actors.rb
|
129
|
-
- spec/app_root/lib/console_with_fixtures.rb
|
130
|
-
- spec/spec_helper.rb
|
131
|
-
- spec/factory_spec.rb
|
132
|
-
- spec/runtime_ext_spec.rb
|
133
|
-
- spec/steps_spec.rb
|
133
|
+
- spec/app_root/config/environments/mysql.rb
|