Commit 9698c084b0ec733e11b7e763051179257e05669f
1 parent
e5875d94
Exists in
master
and in
1 other branch
move from Factory_girl gem to Fabrication and fix spec about spec/model/app_spec
Showing
18 changed files
with
145 additions
and
152 deletions
Show diff stats
Gemfile
... | ... | @@ -31,8 +31,7 @@ gem 'ri_cal' |
31 | 31 | group :development, :test do |
32 | 32 | gem 'rspec-rails', '~> 2.6' |
33 | 33 | gem 'webmock', :require => false |
34 | - gem 'factory_girl', '~> 1.3.3' | |
35 | - gem 'factory_girl_rails', '~> 1.0.1' | |
34 | + gem 'fabrication' | |
36 | 35 | unless ENV['TRAVIS'] |
37 | 36 | gem 'ruby-debug', :platform => :mri_18 |
38 | 37 | gem 'ruby-debug19', :platform => :mri_19, :require => 'ruby-debug' | ... | ... |
Gemfile.lock
... | ... | @@ -55,10 +55,7 @@ GEM |
55 | 55 | rspec (~> 2.0) |
56 | 56 | erubis (2.6.6) |
57 | 57 | abstract (>= 1.0.0) |
58 | - factory_girl (1.3.3) | |
59 | - factory_girl_rails (1.0.1) | |
60 | - factory_girl (~> 1.3) | |
61 | - railties (>= 3.0.0) | |
58 | + fabrication (1.2.0) | |
62 | 59 | faraday (0.7.4) |
63 | 60 | addressable (~> 2.2.6) |
64 | 61 | multipart-post (~> 1.1.0) |
... | ... | @@ -219,8 +216,7 @@ DEPENDENCIES |
219 | 216 | database_cleaner (~> 0.6.0) |
220 | 217 | devise (~> 1.4.0) |
221 | 218 | email_spec |
222 | - factory_girl (~> 1.3.3) | |
223 | - factory_girl_rails (~> 1.0.1) | |
219 | + fabrication | |
224 | 220 | haml |
225 | 221 | hoptoad_notifier (~> 2.4) |
226 | 222 | htmlentities (~> 4.3.0) | ... | ... |
config/application.rb
... | ... | @@ -45,6 +45,7 @@ module Errbit |
45 | 45 | g.orm :mongoid |
46 | 46 | g.template_engine :haml |
47 | 47 | g.test_framework :rspec, :fixture => false |
48 | + g.fixture_replacement :fabrication | |
48 | 49 | end |
49 | 50 | |
50 | 51 | # IssueTracker subclasses use inheritance, so preloading models provides querying consistency in dev mode. | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +Fabricator(:app) do | |
2 | + name { sequence(:app_name) } | |
3 | +end | |
4 | + | |
5 | +Fabricator(:app_with_watcher, :from => :app) do | |
6 | + watchers(:count => 1) { |parent, i| Fabricate.build(:watcher, :app => parent) } | |
7 | +end | |
8 | + | |
9 | +Fabricator(:watcher) do | |
10 | + app! | |
11 | + watcher_type 'email' | |
12 | + email { sequence(:email) } | |
13 | +end | |
14 | + | |
15 | +Fabricator(:user_watcher, :from => :watcher) do | |
16 | + user! | |
17 | + watcher_type 'user' | |
18 | +end | |
19 | + | |
20 | +Fabricator(:deploy) do | |
21 | + app! | |
22 | + username 'clyde.frog' | |
23 | + repository 'git@github.com/errbit/errbit.git' | |
24 | + environment 'production' | |
25 | + revision { ActiveSupport::SecureRandom.hex(10) } | |
26 | +end | |
27 | + | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +Fabricator :err do | |
2 | + problem! | |
3 | + klass! { 'FooError' } | |
4 | + component 'foo' | |
5 | + action 'bar' | |
6 | + environment 'production' | |
7 | +end | |
8 | + | |
9 | +Fabricator :notice do | |
10 | + err! | |
11 | + message 'FooError: Too Much Bar' | |
12 | + backtrace { random_backtrace } | |
13 | + server_environment 'environment-name' => 'production' | |
14 | + request {{ 'component' => 'foo', 'action' => 'bar' }} | |
15 | + notifier 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' | |
16 | +end | |
17 | + | |
18 | +def random_backtrace | |
19 | + backtrace = [] | |
20 | + 99.times {|t| backtrace << { | |
21 | + 'number' => rand(999), | |
22 | + 'file' => "/path/to/file/#{ActiveSupport::SecureRandom.hex(4)}.rb", | |
23 | + 'method' => ActiveSupport.methods.shuffle.first | |
24 | + }} | |
25 | + backtrace | |
26 | +end | |
27 | + | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +Fabricator :issue_tracker do | |
2 | + app! | |
3 | + api_token { sequence :word } | |
4 | + project_id { sequence :word } | |
5 | + account { sequence :word } | |
6 | + username { sequence :word } | |
7 | + password { sequence :word } | |
8 | +end | |
9 | + | |
10 | +%w(lighthouse pivotal_labs fogbugz).each do |t| | |
11 | + Fabricator "#{t}_tracker".to_sym, :from => :issue_tracker, :class_name => "#{t}_tracker".to_sym | |
12 | +end | |
13 | + | |
14 | +Fabricator :redmine_tracker, :from => :issue_tracker, :class_name => :redmine_tracker do | |
15 | + account 'http://redmine.example.com' | |
16 | +end | |
17 | + | |
18 | +Fabricator :mingle_tracker, :from => :issue_tracker, :class_name => :mingle_tracker do | |
19 | + account 'https://mingle.example.com' | |
20 | + ticket_properties 'card_type = Defect, defect_status = open, priority = essential' | |
21 | +end | |
22 | + | |
23 | +Fabricator :github_issues_tracker, :from => :issue_tracker, :class_name => :github_issues_tracker do | |
24 | + project_id 'test_account/test_project' | |
25 | + username 'test_username' | |
26 | +end | |
27 | + | ... | ... |
... | ... | @@ -0,0 +1,6 @@ |
1 | +Fabricate.sequence(:name) {|n| "John #{n} Doe"} | |
2 | +Fabricate.sequence(:word) {|n| "word#{n}"} | |
3 | +Fabricate.sequence(:app_name) {|n| "App ##{n}"} | |
4 | +Fabricate.sequence(:email) {|n| "email#{n}@example.com"} | |
5 | +Fabricate.sequence(:user_email) {|n| "user.#{n}@example.com"} | |
6 | + | ... | ... |
spec/factories.rb
spec/factories/app_factories.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -Factory.define(:app) do |p| | |
2 | - p.name { Factory.next :app_name } | |
3 | -end | |
4 | - | |
5 | -Factory.define(:app_with_watcher, :parent => :app) do |p| | |
6 | - p.after_create {|app| | |
7 | - Factory(:watcher, :app => app) | |
8 | - } | |
9 | -end | |
10 | - | |
11 | -Factory.define(:watcher) do |w| | |
12 | - w.association :app | |
13 | - w.watcher_type 'email' | |
14 | - w.email { Factory.next :email } | |
15 | -end | |
16 | - | |
17 | -Factory.define(:user_watcher, :parent => :watcher) do |w| | |
18 | - w.watcher_type 'user' | |
19 | - w.association :user | |
20 | -end | |
21 | - | |
22 | -Factory.define(:deploy) do |d| | |
23 | - d.app {|p| p.association :app} | |
24 | - d.username 'clyde.frog' | |
25 | - d.repository 'git@github.com/errbit/errbit.git' | |
26 | - d.environment 'production' | |
27 | - d.revision ActiveSupport::SecureRandom.hex(10) | |
28 | -end | |
29 | - |
spec/factories/comment_factories.rb
spec/factories/err_factories.rb
... | ... | @@ -1,40 +0,0 @@ |
1 | -Factory.define :problem do |p| | |
2 | - p.app {|a| a.association :app} | |
3 | - p.comments [] | |
4 | -end | |
5 | - | |
6 | -Factory.define(:problem_with_comments, :parent => :problem) do |ec| | |
7 | - ec.comments { (1..3).map { Factory(:comment) } } | |
8 | -end | |
9 | - | |
10 | - | |
11 | - | |
12 | -Factory.define :err do |e| | |
13 | - e.problem {|p| p.association :problem} | |
14 | - e.klass 'FooError' | |
15 | - e.component 'foo' | |
16 | - e.action 'bar' | |
17 | - e.environment 'production' | |
18 | -end | |
19 | - | |
20 | - | |
21 | - | |
22 | -Factory.define :notice do |n| | |
23 | - n.err {|e| e.association :err} | |
24 | - n.message 'FooError: Too Much Bar' | |
25 | - n.backtrace { random_backtrace } | |
26 | - n.server_environment 'environment-name' => 'production' | |
27 | - n.request {{ 'component' => 'foo', 'action' => 'bar' }} | |
28 | - n.notifier 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' | |
29 | -end | |
30 | - | |
31 | -def random_backtrace | |
32 | - backtrace = [] | |
33 | - 99.times {|t| backtrace << { | |
34 | - 'number' => rand(999), | |
35 | - 'file' => "/path/to/file/#{ActiveSupport::SecureRandom.hex(4)}.rb", | |
36 | - 'method' => ActiveSupport.methods.shuffle.first | |
37 | - }} | |
38 | - backtrace | |
39 | -end | |
40 | - |
spec/factories/issue_tracker_factories.rb
... | ... | @@ -1,27 +0,0 @@ |
1 | -Factory.define :issue_tracker do |e| | |
2 | - e.api_token { Factory.next :word } | |
3 | - e.project_id { Factory.next :word } | |
4 | - e.association :app, :factory => :app | |
5 | - e.account { Factory.next :word } | |
6 | - e.username { Factory.next :word } | |
7 | - e.password { Factory.next :word } | |
8 | -end | |
9 | - | |
10 | -%w(lighthouse pivotal_labs fogbugz).each do |t| | |
11 | - Factory.define "#{t}_tracker".to_sym, :parent => :issue_tracker, :class => "#{t}_tracker".to_sym do |e|; end | |
12 | -end | |
13 | - | |
14 | -Factory.define :redmine_tracker, :parent => :issue_tracker, :class => :redmine_tracker do |e| | |
15 | - e.account 'http://redmine.example.com' | |
16 | -end | |
17 | - | |
18 | -Factory.define :mingle_tracker, :parent => :issue_tracker, :class => :mingle_tracker do |e| | |
19 | - e.account 'https://mingle.example.com' | |
20 | - e.ticket_properties 'card_type = Defect, defect_status = open, priority = essential' | |
21 | -end | |
22 | - | |
23 | -Factory.define :github_issues_tracker, :parent => :issue_tracker, :class => :github_issues_tracker do |e| | |
24 | - e.project_id 'test_account/test_project' | |
25 | - e.username 'test_username' | |
26 | -end | |
27 | - |
spec/factories/user_factories.rb
spec/models/app_spec.rb
... | ... | @@ -3,21 +3,21 @@ require 'spec_helper' |
3 | 3 | describe App do |
4 | 4 | context 'validations' do |
5 | 5 | it 'requires a name' do |
6 | - app = Factory.build(:app, :name => nil) | |
6 | + app = Fabricate.build(:app, :name => nil) | |
7 | 7 | app.should_not be_valid |
8 | 8 | app.errors[:name].should include("can't be blank") |
9 | 9 | end |
10 | 10 | |
11 | 11 | it 'requires unique names' do |
12 | - Factory(:app, :name => 'Errbit') | |
13 | - app = Factory.build(:app, :name => 'Errbit') | |
12 | + Fabricate(:app, :name => 'Errbit') | |
13 | + app = Fabricate.build(:app, :name => 'Errbit') | |
14 | 14 | app.should_not be_valid |
15 | 15 | app.errors[:name].should include('is already taken') |
16 | 16 | end |
17 | 17 | |
18 | 18 | it 'requires unique api_keys' do |
19 | - Factory(:app, :api_key => 'APIKEY') | |
20 | - app = Factory.build(:app, :api_key => 'APIKEY') | |
19 | + Fabricate(:app, :api_key => 'APIKEY') | |
20 | + app = Fabricate.build(:app, :api_key => 'APIKEY') | |
21 | 21 | app.should_not be_valid |
22 | 22 | app.errors[:api_key].should include('is already taken') |
23 | 23 | end |
... | ... | @@ -26,43 +26,43 @@ describe App do |
26 | 26 | |
27 | 27 | context 'being created' do |
28 | 28 | it 'generates a new api-key' do |
29 | - app = Factory.build(:app) | |
29 | + app = Fabricate.build(:app) | |
30 | 30 | app.api_key.should be_nil |
31 | 31 | app.save |
32 | 32 | app.api_key.should_not be_nil |
33 | 33 | end |
34 | 34 | |
35 | 35 | it 'generates a correct api-key' do |
36 | - app = Factory(:app) | |
36 | + app = Fabricate(:app) | |
37 | 37 | app.api_key.should match(/^[a-f0-9]{32}$/) |
38 | 38 | end |
39 | 39 | |
40 | 40 | it 'is fine with blank github urls' do |
41 | - app = Factory.build(:app, :github_url => "") | |
41 | + app = Fabricate.build(:app, :github_url => "") | |
42 | 42 | app.save |
43 | 43 | app.github_url.should == "" |
44 | 44 | end |
45 | 45 | |
46 | 46 | it 'does not touch https github urls' do |
47 | - app = Factory.build(:app, :github_url => "https://github.com/errbit/errbit") | |
47 | + app = Fabricate.build(:app, :github_url => "https://github.com/errbit/errbit") | |
48 | 48 | app.save |
49 | 49 | app.github_url.should == "https://github.com/errbit/errbit" |
50 | 50 | end |
51 | 51 | |
52 | 52 | it 'normalizes http github urls' do |
53 | - app = Factory.build(:app, :github_url => "http://github.com/errbit/errbit") | |
53 | + app = Fabricate.build(:app, :github_url => "http://github.com/errbit/errbit") | |
54 | 54 | app.save |
55 | 55 | app.github_url.should == "https://github.com/errbit/errbit" |
56 | 56 | end |
57 | 57 | |
58 | 58 | it 'normalizes public git repo as a github url' do |
59 | - app = Factory.build(:app, :github_url => "https://github.com/errbit/errbit.git") | |
59 | + app = Fabricate.build(:app, :github_url => "https://github.com/errbit/errbit.git") | |
60 | 60 | app.save |
61 | 61 | app.github_url.should == "https://github.com/errbit/errbit" |
62 | 62 | end |
63 | 63 | |
64 | 64 | it 'normalizes private git repo as a github url' do |
65 | - app = Factory.build(:app, :github_url => "git@github.com:errbit/errbit.git") | |
65 | + app = Fabricate.build(:app, :github_url => "git@github.com:errbit/errbit.git") | |
66 | 66 | app.save |
67 | 67 | app.github_url.should == "https://github.com/errbit/errbit" |
68 | 68 | end |
... | ... | @@ -70,28 +70,28 @@ describe App do |
70 | 70 | |
71 | 71 | context '#github_url_to_file' do |
72 | 72 | it 'resolves to full path to file' do |
73 | - app = Factory(:app, :github_url => "https://github.com/errbit/errbit") | |
73 | + app = Fabricate(:app, :github_url => "https://github.com/errbit/errbit") | |
74 | 74 | app.github_url_to_file('/path/to/file').should == "https://github.com/errbit/errbit/blob/master/path/to/file" |
75 | 75 | end |
76 | 76 | end |
77 | 77 | |
78 | 78 | context '#github_url?' do |
79 | 79 | it 'is true when there is a github_url' do |
80 | - app = Factory(:app, :github_url => "https://github.com/errbit/errbit") | |
80 | + app = Fabricate(:app, :github_url => "https://github.com/errbit/errbit") | |
81 | 81 | app.github_url?.should be_true |
82 | 82 | end |
83 | 83 | |
84 | 84 | it 'is false when no github_url' do |
85 | - app = Factory(:app) | |
85 | + app = Fabricate(:app) | |
86 | 86 | app.github_url?.should be_false |
87 | 87 | end |
88 | 88 | end |
89 | 89 | |
90 | 90 | context "notification recipients" do |
91 | 91 | it "should send notices to either all users, or the configured watchers" do |
92 | - @app = Factory(:app) | |
93 | - 3.times { Factory(:user) } | |
94 | - 5.times { Factory(:watcher, :app => @app) } | |
92 | + @app = Fabricate(:app) | |
93 | + 3.times { Fabricate(:user) } | |
94 | + 5.times { Fabricate(:watcher, :app => @app) } | |
95 | 95 | @app.notify_all_users = true |
96 | 96 | @app.notification_recipients.size.should == 3 |
97 | 97 | @app.notify_all_users = false |
... | ... | @@ -102,9 +102,9 @@ describe App do |
102 | 102 | |
103 | 103 | context "copying attributes from existing app" do |
104 | 104 | it "should only copy the necessary fields" do |
105 | - @app, @copy_app = Factory(:app, :name => "app", :github_url => "url"), | |
106 | - Factory(:app, :name => "copy_app", :github_url => "copy url") | |
107 | - @copy_watcher = Factory(:watcher, :email => "copywatcher@example.com", :app => @copy_app) | |
105 | + @app, @copy_app = Fabricate(:app, :name => "app", :github_url => "url"), | |
106 | + Fabricate(:app, :name => "copy_app", :github_url => "copy url") | |
107 | + @copy_watcher = Fabricate(:watcher, :email => "copywatcher@example.com", :app => @copy_app) | |
108 | 108 | @app.copy_attributes_from(@copy_app.id) |
109 | 109 | @app.name.should == "app" |
110 | 110 | @app.github_url.should == "copy url" |
... | ... | @@ -115,7 +115,7 @@ describe App do |
115 | 115 | |
116 | 116 | context '#find_or_create_err!' do |
117 | 117 | before do |
118 | - @app = Factory(:app) | |
118 | + @app = Fabricate(:app) | |
119 | 119 | @conditions = { |
120 | 120 | :klass => 'Whoops', |
121 | 121 | :component => 'Foo', |
... | ... | @@ -125,7 +125,7 @@ describe App do |
125 | 125 | end |
126 | 126 | |
127 | 127 | it 'returns the correct err if one already exists' do |
128 | - existing = Factory(:err, @conditions.merge(:problem => Factory(:problem, :app => @app))) | |
128 | + existing = Fabricate(:err, @conditions.merge(:problem => Fabricate(:problem, :app => @app))) | |
129 | 129 | Err.where(@conditions).first.should == existing |
130 | 130 | @app.find_or_create_err!(@conditions).should == existing |
131 | 131 | end |
... | ... | @@ -146,7 +146,7 @@ describe App do |
146 | 146 | context '#report_error!' do |
147 | 147 | before do |
148 | 148 | @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read |
149 | - @app = Factory(:app, :api_key => 'APIKEY') | |
149 | + @app = Fabricate(:app, :api_key => 'APIKEY') | |
150 | 150 | ErrorReport.any_instance.stub(:fingerprint).and_return('fingerprintdigest') |
151 | 151 | end |
152 | 152 | |
... | ... | @@ -163,7 +163,7 @@ describe App do |
163 | 163 | :action => 'verify', |
164 | 164 | :environment => 'development', |
165 | 165 | :fingerprint => 'fingerprintdigest' |
166 | - }).and_return(err = Factory(:err)) | |
166 | + }).and_return(err = Fabricate(:err)) | |
167 | 167 | err.notices.stub(:create!) |
168 | 168 | @notice = App.report_error!(@xml) |
169 | 169 | end |
... | ... | @@ -176,7 +176,7 @@ describe App do |
176 | 176 | :action => 'verify', |
177 | 177 | :environment => 'development', |
178 | 178 | :fingerprint => 'fingerprintdigest' |
179 | - }).and_return(err = Factory(:err, :problem => Factory(:problem, :resolved => true))) | |
179 | + }).and_return(err = Fabricate(:err, :problem => Fabricate(:problem, :resolved => true))) | |
180 | 180 | err.should be_resolved |
181 | 181 | @notice = App.report_error!(@xml) |
182 | 182 | @notice.err.should == err | ... | ... |
spec/spec_helper.rb
... | ... | @@ -10,6 +10,10 @@ require 'webmock/rspec' |
10 | 10 | # in ./support/ and its subdirectories. |
11 | 11 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} |
12 | 12 | |
13 | +Fabrication.configure do |config| | |
14 | + fabricator_dir = "spec/fabricators" | |
15 | +end | |
16 | + | |
13 | 17 | RSpec.configure do |config| |
14 | 18 | config.mock_with :rspec |
15 | 19 | config.include Devise::TestHelpers, :type => :controller | ... | ... |