cucumber_factory 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -0
- data/VERSION +1 -1
- data/cucumber_factory.gemspec +2 -2
- data/lib/cucumber_factory/factory.rb +18 -12
- data/spec/factory_spec.rb +10 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -37,6 +37,12 @@ You can also refer to the last created object of a kind by saying "above":
|
|
37
37
|
|
38
38
|
{Machinist blueprints}[http://github.com/notahat/machinist] and {factory_girl factories}[http://github.com/thoughtbot/factory_girl] will be used when available.
|
39
39
|
|
40
|
+
You can use named Machinist blueprint such as <tt>Movie.blueprint(:comedy)</tt> like this:
|
41
|
+
|
42
|
+
Given a movie (comedy) with the title "Groundhog Day"
|
43
|
+
|
44
|
+
Inherited factory_girl factories are not supported yet.
|
45
|
+
|
40
46
|
=== Credits
|
41
47
|
|
42
48
|
Henning Koch
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.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.4.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{2010-01-28}
|
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 = [
|
@@ -12,12 +12,12 @@ module Cucumber
|
|
12
12
|
def self.steps
|
13
13
|
[
|
14
14
|
[
|
15
|
-
/^"([^\"]*)" is an? (.+?)( with the .+?)?$/,
|
16
|
-
lambda { |name, raw_model, raw_attributes| Cucumber::Factory.parse_named_creation(self, name, raw_model, raw_attributes) }
|
15
|
+
/^"([^\"]*)" is an? (.+?)( \(.+?\))?( with the .+?)?$/,
|
16
|
+
lambda { |name, raw_model, raw_variant, raw_attributes| Cucumber::Factory.parse_named_creation(self, name, raw_model, raw_variant, raw_attributes) }
|
17
17
|
],
|
18
18
|
[
|
19
|
-
/^there is an? (.+?)( with the .+?)?$/,
|
20
|
-
lambda { |raw_model, raw_attributes| Cucumber::Factory.parse_creation(self, raw_model, raw_attributes) }
|
19
|
+
/^there is an? (.+?)( \(.+?\))?( with the .+?)?$/,
|
20
|
+
lambda { |raw_model, raw_variant, raw_attributes| Cucumber::Factory.parse_creation(self, raw_model, raw_variant, raw_attributes) }
|
21
21
|
]
|
22
22
|
]
|
23
23
|
end
|
@@ -34,13 +34,13 @@ module Cucumber
|
|
34
34
|
raise "No step definition for: #{command}"
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.parse_named_creation(world, name, raw_model, raw_attributes)
|
38
|
-
record = parse_creation(world, raw_model, raw_attributes)
|
37
|
+
def self.parse_named_creation(world, name, raw_model, raw_variant, raw_attributes)
|
38
|
+
record = parse_creation(world, raw_model, raw_variant, raw_attributes)
|
39
39
|
variable = variable_name_from_prose(name)
|
40
40
|
world.instance_variable_set variable, record
|
41
41
|
end
|
42
42
|
|
43
|
-
def self.parse_creation(world, raw_model, raw_attributes)
|
43
|
+
def self.parse_creation(world, raw_model, raw_variant, raw_attributes)
|
44
44
|
model_class = model_class_from_prose(raw_model)
|
45
45
|
attributes = {}
|
46
46
|
if raw_attributes.present? && raw_attributes.strip.present?
|
@@ -52,7 +52,8 @@ module Cucumber
|
|
52
52
|
association = model_class.reflect_on_association(attribute) if model_class.respond_to?(:reflect_on_association)
|
53
53
|
if association.present?
|
54
54
|
if value_type == "above"
|
55
|
-
|
55
|
+
# Don't use class.last, in sqlite that is not always the last inserted element
|
56
|
+
value = association.klass.find(:last, :order => "id") or raise "There is no last #{attribute}"
|
56
57
|
else
|
57
58
|
value = world.instance_variable_get(variable_name_from_prose(value))
|
58
59
|
end
|
@@ -60,7 +61,8 @@ module Cucumber
|
|
60
61
|
attributes[attribute] = value
|
61
62
|
end
|
62
63
|
end
|
63
|
-
|
64
|
+
variant = raw_variant.present? && /\((.*?)\)/.match(raw_variant)[1].downcase.gsub(" ", "_")
|
65
|
+
create_record(model_class, variant, attributes)
|
64
66
|
end
|
65
67
|
|
66
68
|
def self.model_class_from_prose(prose)
|
@@ -81,13 +83,17 @@ module Cucumber
|
|
81
83
|
def self.factory_girl_factory_name(model_class)
|
82
84
|
model_class.to_s.underscore.to_sym
|
83
85
|
end
|
84
|
-
|
85
|
-
def self.create_record(model_class, attributes)
|
86
|
+
|
87
|
+
def self.create_record(model_class, variant, attributes)
|
86
88
|
factory_name = factory_girl_factory_name(model_class)
|
87
89
|
if defined?(::Factory) && factory = ::Factory.factories[factory_name]
|
88
90
|
::Factory.create(factory_name, attributes)
|
89
91
|
elsif model_class.respond_to?(:make) # Machinist blueprint
|
90
|
-
|
92
|
+
if variant.present?
|
93
|
+
model_class.make(variant.to_sym, attributes)
|
94
|
+
else
|
95
|
+
model_class.make(attributes)
|
96
|
+
end
|
91
97
|
elsif model_class.respond_to?(:create!) # Plain ActiveRecord
|
92
98
|
model = model_class.new
|
93
99
|
model.send(:attributes=, attributes, false) # ignore attr_accessible
|
data/spec/factory_spec.rb
CHANGED
@@ -59,6 +59,16 @@ describe Cucumber::Factory do
|
|
59
59
|
Cucumber::Factory.parse(@world, 'Given there is a machinist model with the attribute "foo"')
|
60
60
|
end
|
61
61
|
|
62
|
+
it "should be able to invoke machinist blueprint variants" do
|
63
|
+
MachinistModel.should_receive(:make).with(:variant, { :attribute => "foo"})
|
64
|
+
Cucumber::Factory.parse(@world, 'Given there is a machinist model (variant) with the attribute "foo"')
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should be able to invoke machinist blueprint variants containing spaces or uppercase characters in prose" do
|
68
|
+
MachinistModel.should_receive(:make).with(:variant_mark_two, { :attribute => "foo"})
|
69
|
+
Cucumber::Factory.parse(@world, 'Given there is a machinist model (Variant Mark Two) with the attribute "foo"')
|
70
|
+
end
|
71
|
+
|
62
72
|
it "should create models that have a factory_girl factory by calling #Factory.make(:model_name)" do
|
63
73
|
Factory.should_receive(:factories).with().and_return({ :job_offer => :job_offer_factory }) # Fake factory look up in factory_girl
|
64
74
|
Factory.should_receive(:create).with(:job_offer, { :title => "Awesome job" })
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-28 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|