cucumber_factory 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cucumber_factory}
8
- s.version = "1.2.1"
8
+ s.version = "1.3.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{2009-11-16}
12
+ s.date = %q{2009-12-10}
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 = [
@@ -25,10 +25,11 @@ Gem::Specification.new do |s|
25
25
  "lib/cucumber_factory.rb",
26
26
  "lib/cucumber_factory/factory.rb",
27
27
  "spec/app_root/app/controllers/application_controller.rb",
28
- "spec/app_root/app/models/benutzer.rb",
29
28
  "spec/app_root/app/models/job_offer.rb",
30
29
  "spec/app_root/app/models/machinist_model.rb",
31
30
  "spec/app_root/app/models/movie.rb",
31
+ "spec/app_root/app/models/opera.rb",
32
+ "spec/app_root/app/models/payment.rb",
32
33
  "spec/app_root/app/models/plain_ruby_class.rb",
33
34
  "spec/app_root/app/models/user.rb",
34
35
  "spec/app_root/config/boot.rb",
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
42
43
  "spec/app_root/config/routes.rb",
43
44
  "spec/app_root/db/migrate/001_create_movies.rb",
44
45
  "spec/app_root/db/migrate/002_create_users.rb",
46
+ "spec/app_root/db/migrate/003_create_payments.rb",
45
47
  "spec/app_root/lib/console_with_fixtures.rb",
46
48
  "spec/app_root/log/.gitignore",
47
49
  "spec/app_root/script/console",
@@ -56,9 +58,10 @@ Gem::Specification.new do |s|
56
58
  s.rubygems_version = %q{1.3.5}
57
59
  s.summary = %q{Create records from Cucumber features without writing step definitions.}
58
60
  s.test_files = [
59
- "spec/app_root/app/models/benutzer.rb",
61
+ "spec/app_root/app/models/opera.rb",
60
62
  "spec/app_root/app/models/movie.rb",
61
63
  "spec/app_root/app/models/job_offer.rb",
64
+ "spec/app_root/app/models/payment.rb",
62
65
  "spec/app_root/app/models/machinist_model.rb",
63
66
  "spec/app_root/app/models/plain_ruby_class.rb",
64
67
  "spec/app_root/app/models/user.rb",
@@ -73,6 +76,7 @@ Gem::Specification.new do |s|
73
76
  "spec/app_root/config/routes.rb",
74
77
  "spec/app_root/db/migrate/002_create_users.rb",
75
78
  "spec/app_root/db/migrate/001_create_movies.rb",
79
+ "spec/app_root/db/migrate/003_create_payments.rb",
76
80
  "spec/app_root/lib/console_with_fixtures.rb",
77
81
  "spec/factory_spec.rb",
78
82
  "spec/spec_helper.rb"
@@ -12,11 +12,11 @@ module Cucumber
12
12
  def self.steps
13
13
  [
14
14
  [
15
- /^"([^\"]*)" is a (.+?)( with the .+?)?$/,
15
+ /^"([^\"]*)" is an? (.+?)( with the .+?)?$/,
16
16
  lambda { |name, raw_model, raw_attributes| Cucumber::Factory.parse_named_creation(self, name, raw_model, raw_attributes) }
17
17
  ],
18
18
  [
19
- /^there is a (.+?)( with the .+?)?$/,
19
+ /^there is an? (.+?)( with the .+?)?$/,
20
20
  lambda { |raw_model, raw_attributes| Cucumber::Factory.parse_creation(self, raw_model, raw_attributes) }
21
21
  ]
22
22
  ]
@@ -86,11 +86,15 @@ module Cucumber
86
86
  factory_name = factory_girl_factory_name(model_class)
87
87
  if defined?(::Factory) && factory = ::Factory.factories[factory_name]
88
88
  ::Factory.create(factory_name, attributes)
89
+ elsif model_class.respond_to?(:make) # Machinist blueprint
90
+ model_class.make(attributes)
91
+ elsif model_class.respond_to?(:create!) # Plain ActiveRecord
92
+ model = model_class.new
93
+ model.send(:attributes=, attributes, false) # ignore attr_accessible
94
+ model.save!
95
+ model
89
96
  else
90
- create_method = [:make, :create!, :new].detect do |method_name|
91
- model_class.respond_to? method_name
92
- end
93
- model_class.send(create_method, attributes)
97
+ model_class.new(attributes)
94
98
  end
95
99
  end
96
100
 
@@ -0,0 +1,4 @@
1
+ class Opera
2
+ def initialize(options)
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ class Payment < ActiveRecord::Base
2
+
3
+ # Only the comment is accessible, amount isn't
4
+ attr_accessible :comment
5
+
6
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ class CreatePayments < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :payments do |t|
5
+ t.text :comment
6
+ t.integer :amount
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :payments
12
+ end
13
+
14
+ end
data/spec/factory_spec.rb CHANGED
@@ -47,8 +47,10 @@ describe Cucumber::Factory do
47
47
  @world = Object.new
48
48
  end
49
49
 
50
- it "should create ActiveRecord models by calling #create!" do
51
- Movie.should_receive(:create!).with({})
50
+ it "should create ActiveRecord models by calling #new and #save!" do
51
+ movie = Movie.new
52
+ Movie.should_receive(:new).with().and_return(movie)
53
+ movie.should_receive(:save!)
52
54
  Cucumber::Factory.parse(@world, "Given there is a movie")
53
55
  end
54
56
 
@@ -74,25 +76,44 @@ describe Cucumber::Factory do
74
76
  end
75
77
 
76
78
  it "should instantiate classes with uppercase characters in their name" do
77
- Benutzer.should_receive(:new).with({})
78
- Cucumber::Factory.parse(@world, "Given there is a Benutzer")
79
+ user = User.new
80
+ User.should_receive(:new).and_return(user)
81
+ Cucumber::Factory.parse(@world, "Given there is a User")
82
+ end
83
+
84
+ it "should allow either 'a' or 'an' for the article" do
85
+ Opera.should_receive(:new).with({})
86
+ Cucumber::Factory.parse(@world, "Given there is an opera")
79
87
  end
80
88
 
81
89
  it "should create records with attributes" do
82
- Movie.should_receive(:create!).with({ :title => "Sunshine", :year => "2007" })
90
+ movie = Movie.new
91
+ Movie.stub(:new => movie)
92
+ movie.should_receive(:"attributes=").with({ :title => "Sunshine", :year => "2007" }, false)
83
93
  Cucumber::Factory.parse(@world, 'Given there is a movie with the title "Sunshine" and the year "2007"')
84
94
  end
85
95
 
86
96
  it "should create records with attributes containing spaces" do
87
- Movie.should_receive(:create!).with({ :box_office_result => "99999999" })
97
+ movie = Movie.new
98
+ Movie.stub(:new => movie)
99
+ movie.should_receive(:"attributes=").with({ :box_office_result => "99999999" }, false)
88
100
  Cucumber::Factory.parse(@world, 'Given there is a movie with the box office result "99999999"')
89
101
  end
90
102
 
91
103
  it "should create records with attributes containing uppercase characters" do
92
- Benutzer.should_receive(:create!).with({ :name => "Susanne" })
93
- Cucumber::Factory.parse(@world, 'Given there is a Benutzer with the Name "Susanne"')
104
+ user = User.new
105
+ User.stub(:new => user)
106
+ user.should_receive(:"attributes=").with({ :name => "Susanne" }, false)
107
+ Cucumber::Factory.parse(@world, 'Given there is a User with the Name "Susanne"')
94
108
  end
95
109
 
110
+ it "should override attr_accessible protection" do
111
+ Cucumber::Factory.parse(@world, 'Given there is a payment with the amount "120" and the comment "Thanks for lending"')
112
+ payment = Payment.last
113
+ payment.amount.should == 120
114
+ payment.comment.should == 'Thanks for lending'
115
+ end
116
+
96
117
  it "should set instance variables in the world" do
97
118
  Cucumber::Factory.parse(@world, 'Given "Sunshine" is a movie with the title "Sunshine" and the year "2007"')
98
119
  @world.instance_variable_get(:'@sunshine').title.should == "Sunshine"
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.2.1
4
+ version: 1.3.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: 2009-11-16 00:00:00 +01:00
12
+ date: 2009-12-10 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,10 +31,11 @@ files:
31
31
  - lib/cucumber_factory.rb
32
32
  - lib/cucumber_factory/factory.rb
33
33
  - spec/app_root/app/controllers/application_controller.rb
34
- - spec/app_root/app/models/benutzer.rb
35
34
  - spec/app_root/app/models/job_offer.rb
36
35
  - spec/app_root/app/models/machinist_model.rb
37
36
  - spec/app_root/app/models/movie.rb
37
+ - spec/app_root/app/models/opera.rb
38
+ - spec/app_root/app/models/payment.rb
38
39
  - spec/app_root/app/models/plain_ruby_class.rb
39
40
  - spec/app_root/app/models/user.rb
40
41
  - spec/app_root/config/boot.rb
@@ -48,6 +49,7 @@ files:
48
49
  - spec/app_root/config/routes.rb
49
50
  - spec/app_root/db/migrate/001_create_movies.rb
50
51
  - spec/app_root/db/migrate/002_create_users.rb
52
+ - spec/app_root/db/migrate/003_create_payments.rb
51
53
  - spec/app_root/lib/console_with_fixtures.rb
52
54
  - spec/app_root/log/.gitignore
53
55
  - spec/app_root/script/console
@@ -84,9 +86,10 @@ signing_key:
84
86
  specification_version: 3
85
87
  summary: Create records from Cucumber features without writing step definitions.
86
88
  test_files:
87
- - spec/app_root/app/models/benutzer.rb
89
+ - spec/app_root/app/models/opera.rb
88
90
  - spec/app_root/app/models/movie.rb
89
91
  - spec/app_root/app/models/job_offer.rb
92
+ - spec/app_root/app/models/payment.rb
90
93
  - spec/app_root/app/models/machinist_model.rb
91
94
  - spec/app_root/app/models/plain_ruby_class.rb
92
95
  - spec/app_root/app/models/user.rb
@@ -101,6 +104,7 @@ test_files:
101
104
  - spec/app_root/config/routes.rb
102
105
  - spec/app_root/db/migrate/002_create_users.rb
103
106
  - spec/app_root/db/migrate/001_create_movies.rb
107
+ - spec/app_root/db/migrate/003_create_payments.rb
104
108
  - spec/app_root/lib/console_with_fixtures.rb
105
109
  - spec/factory_spec.rb
106
110
  - spec/spec_helper.rb
@@ -1,2 +0,0 @@
1
- class Benutzer
2
- end