Commit 34aa640c01a58dc941e2637081997aa3aad09959

Authored by Stephen Crosby
1 parent 2932cb6f
Exists in master and in 1 other branch production

upgrade to rspec 3

Showing 80 changed files with 377 additions and 549 deletions   Show diff stats
.rspec 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +--color
  2 +--require spec_helper
... ...
.travis.yml
... ... @@ -7,7 +7,7 @@ rvm:
7 7 - ruby-head
8 8  
9 9 env:
10   - - COVERAGE=true
  10 + - RAILS_ENV=test COVERAGE=true
11 11  
12 12 sudo: false
13 13  
... ... @@ -15,7 +15,8 @@ cache: bundler
15 15  
16 16 services: mongodb
17 17  
18   -script: bundle exec rake errbit:bootstrap spec
  18 +before_script: bundle exec rake errbit:bootstrap
  19 +script: bundle exec rspec
19 20  
20 21 matrix:
21 22 allow_failures:
... ...
Gemfile
... ... @@ -56,8 +56,7 @@ gem 'yajl-ruby', :require => "yajl"
56 56 group :development, :test do
57 57 gem 'airbrake', :require => false
58 58 gem 'pry-rails'
59   -# gem 'rpm_contrib'
60   -# gem 'newrelic_rpm'
  59 + gem 'pry-byebug', platforms: [:mri]
61 60 gem 'quiet_assets'
62 61 end
63 62  
... ... @@ -75,7 +74,10 @@ group :development do
75 74 end
76 75  
77 76 group :test do
78   - gem 'rspec-rails', require: false
  77 + gem 'rspec'
  78 + gem 'rspec-rails', '~> 3.0', require: false
  79 + gem 'rspec-activemodel-mocks'
  80 + gem 'rspec-its'
79 81 gem 'mongoid-rspec', require: false
80 82 gem 'fabrication'
81 83 gem 'capybara'
... ...
Gemfile.lock
... ... @@ -45,7 +45,7 @@ GEM
45 45 minitest (~> 5.1)
46 46 thread_safe (~> 0.1)
47 47 tzinfo (~> 1.1)
48   - addressable (2.3.5)
  48 + addressable (2.3.6)
49 49 airbrake (3.1.14)
50 50 builder
51 51 json
... ... @@ -58,6 +58,9 @@ GEM
58 58 debug_inspector (>= 0.0.1)
59 59 bson (2.3.0)
60 60 builder (3.2.2)
  61 + byebug (2.7.0)
  62 + columnize (~> 0.3)
  63 + debugger-linecache (~> 1.2)
61 64 callsite (0.0.11)
62 65 campy (1.0.0)
63 66 capistrano (3.3.5)
... ... @@ -75,7 +78,7 @@ GEM
75 78 capistrano (~> 3.1)
76 79 sshkit (~> 1.3)
77 80 capistrano-stats (1.1.1)
78   - capybara (2.1.0)
  81 + capybara (2.4.4)
79 82 mime-types (>= 1.16)
80 83 nokogiri (>= 1.3.3)
81 84 rack (>= 1.0.0)
... ... @@ -91,6 +94,7 @@ GEM
91 94 execjs
92 95 coffee-script-source (1.8.0)
93 96 colorize (0.7.5)
  97 + columnize (0.9.0)
94 98 connection_pool (2.1.0)
95 99 coveralls (0.7.0)
96 100 multi_json (~> 1.3)
... ... @@ -102,6 +106,7 @@ GEM
102 106 addressable
103 107 database_cleaner (1.2.0)
104 108 debug_inspector (0.0.2)
  109 + debugger-linecache (1.2.0)
105 110 decent_exposure (2.3.2)
106 111 devise (3.4.1)
107 112 bcrypt (~> 3.0)
... ... @@ -110,14 +115,14 @@ GEM
110 115 responders
111 116 thread_safe (~> 0.1)
112 117 warden (~> 1.2.3)
113   - diff-lcs (1.2.4)
  118 + diff-lcs (1.2.5)
114 119 dotenv (0.9.0)
115   - draper (1.3.0)
  120 + draper (1.4.0)
116 121 actionpack (>= 3.0)
117 122 activemodel (>= 3.0)
118 123 activesupport (>= 3.0)
119   - request_store (~> 1.0.3)
120   - email_spec (1.5.0)
  124 + request_store (~> 1.0)
  125 + email_spec (1.6.0)
121 126 launchy (~> 2.1)
122 127 mail (~> 2.2)
123 128 erubis (2.7.0)
... ... @@ -152,14 +157,14 @@ GEM
152 157 jquery-rails (2.1.4)
153 158 railties (>= 3.0, < 5.0)
154 159 thor (>= 0.14, < 2.0)
155   - json (1.8.1)
  160 + json (1.8.2)
156 161 jwt (0.1.8)
157 162 multi_json (>= 1.5)
158 163 kaminari (0.14.1)
159 164 actionpack (>= 3.0.0)
160 165 activesupport (>= 3.0.0)
161 166 kgio (2.9.2)
162   - launchy (2.3.0)
  167 + launchy (2.4.3)
163 168 addressable (~> 2.3)
164 169 mail (2.6.3)
165 170 mime-types (>= 1.16, < 3)
... ... @@ -169,23 +174,23 @@ GEM
169 174 railties
170 175 method_source (0.8.2)
171 176 mime-types (1.25.1)
172   - mini_portile (0.6.1)
173   - minitest (5.5.0)
  177 + mini_portile (0.6.2)
  178 + minitest (5.5.1)
174 179 mongoid (4.0.0)
175 180 activemodel (~> 4.0)
176 181 moped (~> 2.0.0)
177 182 origin (~> 2.1)
178 183 tzinfo (>= 0.3.37)
179   - mongoid-rspec (1.9.0)
180   - mongoid (>= 3.0.1)
  184 + mongoid-rspec (2.0.0)
  185 + mongoid (~> 4.0.0)
181 186 rake
182   - rspec (>= 2.14)
  187 + rspec (~> 3.1)
183 188 mongoid_rails_migrations (1.0.1)
184 189 activesupport (>= 3.2.0)
185 190 bundler (>= 1.0.0)
186 191 rails (>= 3.2.0)
187 192 railties (>= 3.2.0)
188   - moped (2.0.2)
  193 + moped (2.0.3)
189 194 bson (~> 2.2)
190 195 connection_pool (~> 2.0)
191 196 optionable (~> 0.2.0)
... ... @@ -195,7 +200,7 @@ GEM
195 200 net-scp (1.2.1)
196 201 net-ssh (>= 2.6.5)
197 202 net-ssh (2.9.1)
198   - nokogiri (1.6.4.1)
  203 + nokogiri (1.6.5)
199 204 mini_portile (~> 0.6.0)
200 205 oauth2 (0.8.1)
201 206 faraday (~> 0.8)
... ... @@ -232,6 +237,9 @@ GEM
232 237 coderay (~> 1.0.5)
233 238 method_source (~> 0.8)
234 239 slop (~> 3.4)
  240 + pry-byebug (1.3.2)
  241 + byebug (~> 2.7)
  242 + pry (~> 0.9.12)
235 243 pry-rails (0.3.2)
236 244 pry (>= 0.9.10)
237 245 quiet_assets (1.0.2)
... ... @@ -242,7 +250,7 @@ GEM
242 250 rack-ssl (1.4.0)
243 251 rack
244 252 rack-ssl-enforcer (0.2.6)
245   - rack-test (0.6.2)
  253 + rack-test (0.6.3)
246 254 rack (>= 1.0)
247 255 rails (4.1.8)
248 256 actionmailer (= 4.1.8)
... ... @@ -265,28 +273,40 @@ GEM
265 273 rake (10.4.2)
266 274 rdoc (4.1.2)
267 275 json (~> 1.4)
268   - request_store (1.0.6)
  276 + request_store (1.1.0)
269 277 responders (1.1.2)
270 278 railties (>= 3.2, < 4.2)
271 279 rest-client (1.6.8)
272 280 mime-types (~> 1.16)
273 281 rdoc (>= 2.4.2)
274 282 ri_cal (0.8.8)
275   - rspec (2.14.1)
276   - rspec-core (~> 2.14.0)
277   - rspec-expectations (~> 2.14.0)
278   - rspec-mocks (~> 2.14.0)
279   - rspec-core (2.14.6)
280   - rspec-expectations (2.14.3)
281   - diff-lcs (>= 1.1.3, < 2.0)
282   - rspec-mocks (2.14.4)
283   - rspec-rails (2.14.0)
  283 + rspec (3.1.0)
  284 + rspec-core (~> 3.1.0)
  285 + rspec-expectations (~> 3.1.0)
  286 + rspec-mocks (~> 3.1.0)
  287 + rspec-activemodel-mocks (1.0.1)
  288 + activemodel (>= 3.0)
  289 + activesupport (>= 3.0)
  290 + rspec-mocks (>= 2.99, < 4.0)
  291 + rspec-core (3.1.7)
  292 + rspec-support (~> 3.1.0)
  293 + rspec-expectations (3.1.2)
  294 + diff-lcs (>= 1.2.0, < 2.0)
  295 + rspec-support (~> 3.1.0)
  296 + rspec-its (1.1.0)
  297 + rspec-core (>= 3.0.0)
  298 + rspec-expectations (>= 3.0.0)
  299 + rspec-mocks (3.1.3)
  300 + rspec-support (~> 3.1.0)
  301 + rspec-rails (3.1.0)
284 302 actionpack (>= 3.0)
285 303 activesupport (>= 3.0)
286 304 railties (>= 3.0)
287   - rspec-core (~> 2.14.0)
288   - rspec-expectations (~> 2.14.0)
289   - rspec-mocks (~> 2.14.0)
  305 + rspec-core (~> 3.1.0)
  306 + rspec-expectations (~> 3.1.0)
  307 + rspec-mocks (~> 3.1.0)
  308 + rspec-support (~> 3.1.0)
  309 + rspec-support (3.1.2)
290 310 rushover (0.3.0)
291 311 json
292 312 rest-client
... ... @@ -340,7 +360,9 @@ GEM
340 360 useragent (0.9.0)
341 361 warden (1.2.3)
342 362 rack (>= 1.0)
343   - websocket-driver (0.3.3)
  363 + websocket-driver (0.5.1)
  364 + websocket-extensions (>= 0.1.0)
  365 + websocket-extensions (0.1.1)
344 366 xmpp4r (0.5.5)
345 367 xpath (2.0.0)
346 368 nokogiri (~> 1.3)
... ... @@ -391,6 +413,7 @@ DEPENDENCIES
391 413 omniauth-github
392 414 pjax_rails
393 415 poltergeist
  416 + pry-byebug
394 417 pry-rails
395 418 quiet_assets
396 419 rack-ssl
... ... @@ -398,7 +421,10 @@ DEPENDENCIES
398 421 rails_autolink
399 422 railties (~> 4.1.8)
400 423 ri_cal
401   - rspec-rails
  424 + rspec
  425 + rspec-activemodel-mocks
  426 + rspec-its
  427 + rspec-rails (~> 3.0)
402 428 rushover
403 429 sass-rails
404 430 test-unit
... ...
spec/acceptance/acceptance_helper.rb
1   -require 'spec_helper'
2 1 require 'capybara/rspec'
3 2 require 'capybara/poltergeist'
4 3  
... ...
spec/acceptance/sign_in_with_github_spec.rb
... ... @@ -3,7 +3,7 @@ require &#39;acceptance/acceptance_helper&#39;
3 3 feature 'Sign in with GitHub' do
4 4  
5 5 background do
6   - Errbit::Config.stub(:github_authentication) { true }
  6 + allow(Errbit::Config).to receive(:github_authentication).and_return(true)
7 7 Fabricate(:user, :github_login => 'nashby')
8 8 end
9 9  
... ...
spec/controllers/api/v1/notices_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Api::V1::NoticesController do
4   -
  1 +describe Api::V1::NoticesController, type: 'controller' do
5 2 context "when logged in" do
6 3 before do
7 4 @user = Fabricate(:user)
... ... @@ -50,5 +47,4 @@ describe Api::V1::NoticesController do
50 47  
51 48 end
52 49 end
53   -
54 50 end
... ...
spec/controllers/api/v1/problems_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Api::V1::ProblemsController do
4   -
  1 +describe Api::V1::ProblemsController, type: 'controller' do
5 2 context "when logged in" do
6 3 before do
7 4 @user = Fabricate(:user)
... ... @@ -69,8 +66,6 @@ describe Api::V1::ProblemsController do
69 66 Fabricate(:problem, :first_notice_at => Date.new(2012, 8, 30))
70 67 end
71 68  
72   -
73   -
74 69 it "should return JSON if JSON is requested" do
75 70 get :index, :auth_token => @user.authentication_token, :format => "json"
76 71 expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError)
... ... @@ -86,17 +81,13 @@ describe Api::V1::ProblemsController do
86 81 expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError)
87 82 end
88 83  
89   -
90   -
91 84 describe "given a date range" do
92   -
93 85 it "should return only the problems open during the date range" do
94 86 get :index, {:auth_token => @user.authentication_token, :start_date => "2012-08-20", :end_date => "2012-08-27"}
95 87 expect(response).to be_success
96 88 problems = JSON.load response.body
97 89 expect(problems.length).to eq 2
98 90 end
99   -
100 91 end
101 92  
102 93 it "should return all problems" do
... ... @@ -105,8 +96,6 @@ describe Api::V1::ProblemsController do
105 96 problems = JSON.load response.body
106 97 expect(problems.length).to eq 4
107 98 end
108   -
109 99 end
110 100 end
111   -
112 101 end
... ...
spec/controllers/apps_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe AppsController do
4   -
  1 +describe AppsController, type: 'controller' do
5 2 it_requires_authentication
6 3 it_requires_admin_privileges :for => {:new => :get, :edit => :get, :create => :post, :update => :put, :destroy => :delete}
7 4  
... ... @@ -218,7 +215,7 @@ describe AppsController do
218 215 describe "POST /apps" do
219 216 before do
220 217 @app = Fabricate(:app)
221   - App.stub(:new).and_return(@app)
  218 + allow(App).to receive(:new).and_return(@app)
222 219 end
223 220  
224 221 context "when the create is successful" do
... ...
spec/controllers/comments_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe CommentsController do
  1 +describe CommentsController, type: 'controller' do
4 2 let(:app) { Fabricate(:app) }
5 3 let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :app => app, :environment => "production")) }
6 4  
... ...
spec/controllers/deploys_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe DeploysController do
  1 +describe DeploysController, type: 'controller' do
4 2 render_views
5 3  
6 4 context 'POST #create' do
... ... @@ -21,7 +19,7 @@ describe DeploysController do
21 19 end
22 20  
23 21 it 'creates a deploy' do
24   - App.stub(:find_by_api_key!).and_return(@app)
  22 + expect(App).to receive(:find_by_api_key!).and_return(@app)
25 23 expect(@app.deploys).to receive(:create!).
26 24 with({
27 25 :username => 'john.doe',
... ... @@ -40,7 +38,6 @@ describe DeploysController do
40 38 expect(email.to).to include(@app.watchers.first.email)
41 39 expect(email.subject).to eq "[#{@app.name}] Deployed to production by john.doe"
42 40 end
43   -
44 41 end
45 42  
46 43 context "GET #index" do
... ... @@ -59,6 +56,4 @@ describe DeploysController do
59 56 expect(response.body).to match(@deploy.app.name)
60 57 end
61 58 end
62   -
63 59 end
64   -
... ...
spec/controllers/devise_sessions_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Devise::SessionsController do
  1 +describe Devise::SessionsController, type: 'controller' do
4 2 render_views
5 3  
6 4 describe "POST /users/sign_in" do
... ... @@ -23,4 +21,3 @@ describe Devise::SessionsController do
23 21 end
24 22 end
25 23 end
26   -
... ...
spec/controllers/notices_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NoticesController do
  1 +describe NoticesController, type: 'controller' do
4 2 it_requires_authentication :for => { :locate => :get }
5 3  
6 4 let(:notice) { Fabricate(:notice) }
... ... @@ -78,6 +76,4 @@ describe NoticesController do
78 76 end
79 77 end
80 78 end
81   -
82 79 end
83   -
... ...
spec/controllers/problems_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe ProblemsController do
4   -
  1 +describe ProblemsController, type: 'controller' do
5 2 it_requires_authentication :for => {
6 3 :index => :get, :show => :get, :resolve => :put, :search => :get
7 4 },
... ... @@ -218,38 +215,35 @@ describe ProblemsController do
218 215 before do
219 216 sign_in admin
220 217  
221   - @problem = Fabricate(:err)
222   - App.stub(:find).with(@problem.app.id.to_s).and_return(@problem.app)
223   - @problem.app.problems.stub(:find).and_return(@problem.problem)
224   - @problem.problem.stub(:resolve!)
  218 + @err = Fabricate(:err)
225 219 end
226 220  
227   - it 'finds the app and the problem' do
228   - expect(App).to receive(:find).with(@problem.app.id.to_s).and_return(@problem.app)
229   - expect(@problem.app.problems).to receive(:find).and_return(@problem.problem)
230   - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id
231   - expect(controller.app).to eq @problem.app
232   - expect(controller.problem).to eq @problem.problem
  221 + it 'finds the app and the err' do
  222 + expect(App).to receive(:find).with(@err.app.id.to_s).and_return(@err.app)
  223 + expect(@err.app.problems).to receive(:find).and_return(@err.problem)
  224 + put :resolve, :app_id => @err.app.id, :id => @err.problem.id
  225 + expect(controller.app).to eq @err.app
  226 + expect(controller.problem).to eq @err.problem
233 227 end
234 228  
235 229 it "should resolve the issue" do
236   - expect(@problem.problem).to receive(:resolve!).and_return(true)
237   - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id
  230 + put :resolve, :app_id => @err.app.id, :id => @err.problem.id
  231 + expect(@err.problem.reload.resolved).to be(true)
238 232 end
239 233  
240 234 it "should display a message" do
241   - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id
  235 + put :resolve, :app_id => @err.app.id, :id => @err.problem.id
242 236 expect(request.flash[:success]).to match(/Great news/)
243 237 end
244 238  
245 239 it "should redirect to the app page" do
246   - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id
247   - expect(response).to redirect_to(app_path(@problem.app))
  240 + put :resolve, :app_id => @err.app.id, :id => @err.problem.id
  241 + expect(response).to redirect_to(app_path(@err.app))
248 242 end
249 243  
250 244 it "should redirect back to problems page" do
251 245 request.env["HTTP_REFERER"] = problems_path
252   - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id
  246 + put :resolve, :app_id => @err.app.id, :id => @err.problem.id
253 247 expect(response).to redirect_to(problems_path)
254 248 end
255 249 end
... ... @@ -268,8 +262,8 @@ describe ProblemsController do
268 262  
269 263 before do
270 264 problem.app.issue_tracker = issue_tracker
271   - controller.stub(:problem).and_return(problem)
272   - controller.stub(:current_user).and_return(admin)
  265 + allow(controller).to receive(:problem).and_return(problem)
  266 + allow(controller).to receive(:current_user).and_return(admin)
273 267 end
274 268  
275 269 it "should redirect to problem page" do
... ... @@ -461,7 +455,5 @@ describe ProblemsController do
461 455 expect(response).to redirect_to(edit_app_path(@app))
462 456 end
463 457 end
464   -
465 458 end
466   -
467 459 end
... ...
spec/controllers/users/omniauth_callbacks_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Users::OmniauthCallbacksController do
4   -
  1 +describe Users::OmniauthCallbacksController, type: 'controller' do
5 2 def stub_env_for_github_omniauth(login, token = nil)
6 3 # This a Devise specific thing for functional tests. See https://github.com/plataformatec/devise/issues/closed#issue/608
7 4 request.env["devise.mapping"] = Devise.mappings[:user]
... ... @@ -12,7 +9,7 @@ describe Users::OmniauthCallbacksController do
12 9 :credentials => { :token => token }
13 10 )
14 11 }
15   - @controller.stub(:env).and_return(env)
  12 + allow(@controller).to receive(:env).and_return(env)
16 13 end
17 14  
18 15 context 'Linking a GitHub account to a signed in user' do
... ...
spec/controllers/users_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe UsersController do
4   -
  1 +describe UsersController, type: 'controller' do
5 2 it_requires_authentication
6 3 it_requires_admin_privileges :for => {
7 4 :index => :get,
... ... @@ -16,7 +13,6 @@ describe UsersController do
16 13 let(:other_user) { Fabricate(:user) }
17 14  
18 15 context 'Signed in as a regular user' do
19   -
20 16 before do
21 17 sign_in user
22 18 end
... ... @@ -104,16 +100,12 @@ describe UsersController do
104 100 end
105 101  
106 102 context "GET /users" do
107   -
108 103 it 'paginates all users' do
109 104 admin.update_attribute :per_page, 2
110   - users = 3.times {
111   - Fabricate(:user)
112   - }
  105 + 3.times { Fabricate(:user) }
113 106 get :index
114 107 expect(controller.users.to_a.size).to eq 2
115 108 end
116   -
117 109 end
118 110  
119 111 context "GET /users/:id" do
... ... @@ -140,7 +132,7 @@ describe UsersController do
140 132  
141 133 context "POST /users" do
142 134 context "when the create is successful" do
143   - let(:attrs) { {:user => Fabricate.attributes_for(:user)} }
  135 + let(:attrs) { {:user => Fabricate.to_params(:user)} }
144 136  
145 137 it "sets a message to display" do
146 138 post :create, attrs
... ... @@ -156,7 +148,7 @@ describe UsersController do
156 148 attrs[:user][:admin] = true
157 149 post :create, attrs
158 150 expect(response).to be_redirect
159   - expect(User.find(controller.user.to_param).admin).to be_true
  151 + expect(User.find(controller.user.to_param).admin).to be(true)
160 152 end
161 153  
162 154 it "should has auth token" do
... ... @@ -205,7 +197,6 @@ describe UsersController do
205 197 end
206 198  
207 199 context "DELETE /users/:id" do
208   -
209 200 context "with a destroy success" do
210 201 let(:user_destroy) { double(:destroy => true) }
211 202  
... ... @@ -236,8 +227,10 @@ describe UsersController do
236 227 describe "#user_params" do
237 228 context "with current user not admin" do
238 229 before {
239   - controller.stub(:current_user).and_return(user)
240   - controller.stub(:params).and_return(ActionController::Parameters.new(user_param))
  230 + allow(controller).to receive(:current_user).and_return(user)
  231 + allow(controller).to receive(:params).and_return(
  232 + ActionController::Parameters.new(user_param)
  233 + )
241 234 }
242 235 let(:user_param) { {'user' => { :name => 'foo', :admin => true }} }
243 236 it 'not have admin field' do
... ... @@ -261,7 +254,5 @@ describe UsersController do
261 254 end
262 255 end
263 256 end
264   -
265 257 end
266   -
267 258 end
... ...
spec/controllers/watchers_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe WatchersController do
  1 +describe WatchersController, type: 'controller' do
4 2 let(:app) do
5 3 a = Fabricate(:app)
6 4 Fabricate(:user_watcher, :app => a)
... ... @@ -8,7 +6,6 @@ describe WatchersController do
8 6 end
9 7  
10 8 describe "DELETE /apps/:app_id/watchers/:id/destroy" do
11   -
12 9 context "with admin user" do
13 10 before(:each) do
14 11 sign_in Fabricate(:admin)
... ...
spec/decorators/app_decorator_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe AppDecorator do
4   -
5 2 describe "#email_at_notices" do
6   -
7 3 it 'return the list separate by comma' do
8 4 expect(AppDecorator.new(double(:email_at_notices => [2,3])).email_at_notices).to eql '2, 3'
9 5 end
10   -
11 6 end
12 7  
13 8 describe "#notify_user_display" do
14   -
15 9 it 'return display:none if notify' do
16 10 expect(AppDecorator.new(double(:notify_all_users => true)).notify_user_display).to eql 'display: none;'
17 11 end
... ... @@ -19,11 +13,9 @@ describe AppDecorator do
19 13 it 'return blank if no notify' do
20 14 expect(AppDecorator.new(double(:notify_all_users => false)).notify_user_display).to eql ''
21 15 end
22   -
23 16 end
24 17  
25 18 describe "#notify_err_display" do
26   -
27 19 it 'return display:none if no notify' do
28 20 expect(AppDecorator.new(double(:notify_on_errs => false)).notify_err_display).to eql 'display: none;'
29 21 end
... ... @@ -31,7 +23,5 @@ describe AppDecorator do
31 23 it 'return blank if no notify' do
32 24 expect(AppDecorator.new(double(:notify_on_errs => true)).notify_err_display).to eql ''
33 25 end
34   -
35 26 end
36   -
37 27 end
... ...
spec/decorators/issue_tracker_decorator_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe IssueTrackerDecorator do
4 2 let(:fake_tracker) do
5 3 Class.new(ErrbitPlugin::IssueTracker) do
... ...
spec/decorators/issue_tracker_field_decorator.rb
1   -require 'spec_helper'
2   -
3 1 describe IssueTrackerFieldDecorator do
4   -
5 2 describe "#label" do
6 3 it 'return the label of field_info by default' do
7 4 expect(IssueTrackerFieldDecorator.new(:foo, {:label => 'hello'}).label).to eq 'hello'
8 5 end
  6 +
9 7 it 'return the key of field if no label define' do
10 8 expect(IssueTrackerFieldDecorator.new(:foo, {}).label).to eq 'foo'
11 9 end
12 10 end
13   -
14 11 end
... ...
spec/decorators/watcher_decorator_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe WatcherDecorator do
4 2 describe "#email_choosen" do
5 3 context "with email define" do
... ...
spec/helpers/application_helper_spec.rb
1   -require 'spec_helper'
  1 +require 'rails_helper'
2 2  
3 3 # Specs in this file have access to a helper object that includes
4 4 # the AbcHelper. For example:
... ...
spec/helpers/backtrace_line_helper.rb
1   -require 'spec_helper'
2   -
3 1 describe BacktraceLineHelper do
4 2 describe "in app lines" do
5 3 let(:notice) do
... ...
spec/helpers/navigation_helper_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe NavigationHelper do
4 2 describe '#page_count_from_end' do
5 3 it 'returns the page number when counting from the last occurrence of a notice' do
... ...
spec/helpers/problems_helper_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe ProblemsHelper do
4 2 describe '#truncated_problem_message' do
5 3 it 'is html safe' do
... ... @@ -24,8 +22,8 @@ describe ProblemsHelper do
24 22  
25 23 context "default config" do
26 24 before do
27   - Errbit::Config.stub(:use_gravatar).and_return(true)
28   - Errbit::Config.stub(:gravatar_default).and_return('identicon')
  25 + allow(Errbit::Config).to receive(:use_gravatar).and_return(true)
  26 + allow(Errbit::Config).to receive(:gravatar_default).and_return('identicon')
29 27 end
30 28  
31 29 it "should render image_tag with correct alt and src" do
... ... @@ -69,7 +67,7 @@ describe ProblemsHelper do
69 67 let(:email_hash) { Digest::MD5.hexdigest email }
70 68  
71 69 it "should return the http url" do
72   - ActionController::TestRequest.any_instance.stub :ssl? => true
  70 + allow(controller.request).to receive(:ssl?).and_return(true)
73 71 expect(helper.gravatar_url(email)).to eq("https://secure.gravatar.com/avatar/#{email_hash}?d=identicon")
74 72 end
75 73 end
... ...
spec/interactors/problem_destroy_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe ProblemDestroy do
4 2 let(:problem_destroy) {
5 3 ProblemDestroy.new(problem)
... ... @@ -8,9 +6,9 @@ describe ProblemDestroy do
8 6 context "in unit way" do
9 7 let(:problem) {
10 8 problem = Problem.new
11   - problem.stub(:errs).and_return(double(:criteria, :only => [err_1, err_2]))
12   - problem.stub(:comments).and_return(double(:criteria, :only => [comment_1, comment_2]))
13   - problem.stub(:delete)
  9 + allow(problem).to receive(:errs).and_return(double(:criteria, :only => [err_1, err_2]))
  10 + allow(problem).to receive(:comments).and_return(double(:criteria, :only => [comment_1, comment_2]))
  11 + allow(problem).to receive(:delete)
14 12 problem
15 13 }
16 14 let(:err_1) { Err.new }
... ... @@ -73,5 +71,4 @@ describe ProblemDestroy do
73 71 expect(Notice.where(:_id => notice_2_2.id).entries).to be_empty
74 72 end
75 73 end
76   -
77 74 end
... ...
spec/interactors/problem_merge_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe ProblemMerge do
4 2 let(:problem) { Fabricate(:problem_with_errs) }
5 3 let(:problem_1) { Fabricate(:problem_with_errs) }
... ...
spec/interactors/problem_updater_cache_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe ProblemUpdaterCache do
4 2 let(:problem) { Fabricate(:problem_with_errs) }
5 3 let(:first_errs) { problem.errs }
... ...
spec/interactors/resolved_problem_clearer_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe ResolvedProblemClearer do
4 2 let(:resolved_problem_clearer) {
5 3 ResolvedProblemClearer.new
... ... @@ -21,7 +19,7 @@ describe ResolvedProblemClearer do
21 19 }
22 20 end
23 21 it 'not repair database' do
24   - Mongoid.default_session.stub(:command).and_call_original
  22 + allow(Mongoid.default_session).to receive(:command).and_call_original
25 23 expect(Mongoid.default_session).to_not receive(:command).with({:repairDatabase => 1})
26 24 resolved_problem_clearer.execute
27 25 end
... ... @@ -29,8 +27,8 @@ describe ResolvedProblemClearer do
29 27  
30 28 context "with problem resolve" do
31 29 before do
32   - Mongoid.default_session.stub(:command).and_call_original
33   - Mongoid.default_session.stub(:command).with({:repairDatabase => 1})
  30 + allow(Mongoid.default_session).to receive(:command).and_call_original
  31 + allow(Mongoid.default_session).to receive(:command).with({:repairDatabase => 1})
34 32 problems.first.resolve!
35 33 problems.second.resolve!
36 34 end
... ... @@ -46,7 +44,6 @@ describe ResolvedProblemClearer do
46 44 end
47 45  
48 46 it 'repair database' do
49   - Mongoid.default_session.stub(:command).and_call_original
50 47 expect(Mongoid.default_session).to receive(:command).with({:repairDatabase => 1})
51 48 resolved_problem_clearer.execute
52 49 end
... ...
spec/interactors/user_destroy_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe UserDestroy do
4 2 let(:app) { Fabricate(
5 3 :app,
... ...
spec/mailers/mailer_spec.rb
1   -require 'spec_helper'
2   -
3 1 shared_examples "a notification email" do
4 2 it "should have X-Mailer header" do
5 3 expect(@email).to have_header('X-Mailer', 'Errbit')
... ... @@ -36,6 +34,7 @@ describe Mailer do
36 34 let!(:user) { Fabricate(:admin) }
37 35  
38 36 before do
  37 + ActionMailer::Base.deliveries = []
39 38 notice.backtrace.lines.last.update_attributes(:file => "[PROJECT_ROOT]/path/to/file.js")
40 39 notice.app.update_attributes(
41 40 :asset_host => "http://example.com",
... ... @@ -78,12 +77,12 @@ describe Mailer do
78 77 include EmailSpec::Matchers
79 78  
80 79 let!(:notice) { Fabricate(:notice) }
81   - let!(:comment) { Fabricate.build(:comment, :err => notice.problem) }
  80 + let!(:comment) { Fabricate(:comment, :err => notice.problem) }
82 81 let!(:watcher) { Fabricate(:watcher, :app => comment.app) }
83 82 let(:recipients) { ['recipient@example.com', 'another@example.com']}
84 83  
85 84 before do
86   - comment.stub(:notification_recipients).and_return(recipients)
  85 + expect(comment).to receive(:notification_recipients).and_return(recipients)
87 86 Fabricate(:notice, :err => notice.err)
88 87 @email = Mailer.comment_notification(comment).deliver
89 88 end
... ...
spec/models/app_spec.rb
1   -require 'spec_helper'
2   -
3   -describe App do
4   -
  1 +describe App, type: 'model' do
5 2 context "Attributes" do
6 3 it { should have_field(:_id).of_type(String) }
7 4 it { should have_field(:name).of_type(String) }
... ... @@ -112,12 +109,12 @@ describe App do
112 109 context '#github_repo?' do
113 110 it 'is true when there is a github_repo' do
114 111 app = Fabricate(:app, :github_repo => "errbit/errbit")
115   - expect(app.github_repo?).to be_true
  112 + expect(app.github_repo?).to be(true)
116 113 end
117 114  
118 115 it 'is false when no github_repo' do
119 116 app = Fabricate(:app)
120   - expect(app.github_repo?).to be_false
  117 + expect(app.github_repo?).to be(false)
121 118 end
122 119 end
123 120  
... ... @@ -137,19 +134,19 @@ describe App do
137 134 it "should be true if notify on errs and there are notification recipients" do
138 135 app = Fabricate(:app, :notify_on_errs => true, :notify_all_users => false)
139 136 2.times { Fabricate(:watcher, :app => app) }
140   - expect(app.emailable?).to be_true
  137 + expect(app.emailable?).to be(true)
141 138 end
142 139  
143 140 it "should be false if notify on errs is disabled" do
144 141 app = Fabricate(:app, :notify_on_errs => false, :notify_all_users => false)
145 142 2.times { Fabricate(:watcher, :app => app) }
146   - expect(app.emailable?).to be_false
  143 + expect(app.emailable?).to be(false)
147 144 end
148 145  
149 146 it "should be false if there are no notification recipients" do
150 147 app = Fabricate(:app, :notify_on_errs => true, :notify_all_users => false)
151 148 expect(app.watchers).to be_empty
152   - expect(app.emailable?).to be_false
  149 + expect(app.emailable?).to be(false)
153 150 end
154 151 end
155 152  
... ...
spec/models/backtrace_line_normalizer_spec.rb
1   -require 'spec_helper'
2   -
3   -describe BacktraceLineNormalizer do
  1 +describe BacktraceLineNormalizer, type: 'model' do
4 2 subject { described_class.new(raw_line).call }
5 3  
6 4 describe "sanitize" do
... ...
spec/models/backtrace_line_spec.rb
1   -require 'spec_helper'
2   -
3   -describe BacktraceLine do
  1 +describe BacktraceLine, type: 'model' do
4 2 subject { described_class.new(raw_line) }
5 3  
6 4 describe "root at the start of decorated filename" do
... ...
spec/models/backtrace_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Backtrace do
  1 +describe Backtrace, type: 'model' do
4 2 subject { described_class.new }
5 3  
6 4 its(:fingerprint) { should be_present }
... ... @@ -19,7 +17,7 @@ describe Backtrace do
19 17 }
20 18 let(:fingerprint) { "fingerprint" }
21 19  
22   - before { subject.stub(:fingerprint => fingerprint) }
  20 + before { allow(subject).to receive(:fingerprint).and_return(fingerprint) }
23 21  
24 22 its(:similar) { should == similar_backtrace }
25 23 end
... ... @@ -30,10 +28,10 @@ describe Backtrace do
30 28 let(:attributes) { double :attributes }
31 29 let(:backtrace) { double :backtrace }
32 30  
33   - before { described_class.stub(:new => backtrace) }
  31 + before { allow(described_class).to receive(:new).and_return(backtrace) }
34 32  
35 33 context "no similar backtrace" do
36   - before { backtrace.stub(:similar => nil) }
  34 + before { allow(backtrace).to receive(:similar).and_return(nil) }
37 35 it "create new backtrace" do
38 36 expect(described_class).to receive(:create).with(attributes)
39 37  
... ... @@ -43,7 +41,7 @@ describe Backtrace do
43 41  
44 42 context "similar backtrace exist" do
45 43 let(:similar_backtrace) { double :similar_backtrace }
46   - before { backtrace.stub(:similar => similar_backtrace) }
  44 + before { allow(backtrace).to receive(:similar).and_return(similar_backtrace) }
47 45  
48 46 it { should == similar_backtrace }
49 47 end
... ...
spec/models/comment_observer_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "Callback on Comment" do
  1 +describe "Callback on Comment", type: 'model' do
4 2 context 'when a Comment is saved' do
5 3 let(:comment) { Fabricate.build(:comment) }
6 4  
7 5 context 'and it is emailable?' do
8   - before { comment.stub(:emailable?).and_return(true) }
  6 + before { allow(comment).to receive(:emailable?).and_return(true) }
9 7  
10 8 it 'should send an email notification' do
11 9 expect(Mailer).to receive(:comment_notification).
... ... @@ -16,7 +14,7 @@ describe &quot;Callback on Comment&quot; do
16 14 end
17 15  
18 16 context 'and it is not emailable?' do
19   - before { comment.stub(:emailable?).and_return(false) }
  17 + before { allow(comment).to receive(:emailable?).and_return(false) }
20 18  
21 19 it 'should not send an email notification' do
22 20 expect(Mailer).to_not receive(:comment_notification)
... ...
spec/models/comment_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Comment do
  1 +describe Comment, type: 'model' do
4 2 context 'validations' do
5 3 it 'should require a body' do
6 4 comment = Fabricate.build(:comment, :body => nil)
... ... @@ -37,19 +35,19 @@ describe Comment do
37 35 end
38 36  
39 37 it 'should be true if app is emailable? and there are notification recipients' do
40   - expect(comment.emailable?).to be_true
  38 + expect(comment.emailable?).to be(true)
41 39 end
42 40  
43 41 it 'should be false if app is not emailable?' do
44 42 app.update_attribute(:notify_on_errs, false)
45 43 expect(comment.notification_recipients).to be_any
46   - expect(comment.emailable?).to be_false
  44 + expect(comment.emailable?).to be(false)
47 45 end
48 46  
49 47 it 'should be false if there are no notification recipients' do
50 48 watcher.destroy
51   - expect(app.emailable?).to be_true
52   - expect(comment.emailable?).to be_false
  49 + expect(app.emailable?).to be(true)
  50 + expect(comment.emailable?).to be(false)
53 51 end
54 52 end
55 53 end
... ...
spec/models/deploy_observer_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "Callback on Deploy" do
  1 +describe "Callback on Deploy", type: 'model' do
4 2 context 'when a Deploy is saved' do
5 3 context 'and the app should notify on deploys' do
6 4 it 'should send an email notification' do
... ...
spec/models/deploy_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Deploy do
4   -
  1 +describe Deploy, type: 'model' do
5 2 context 'validations' do
6 3 it 'requires a username' do
7 4 deploy = Fabricate.build(:deploy, :username => nil)
... ... @@ -36,7 +33,6 @@ describe Deploy do
36 33 expect(@staging_errs.all?{|problem| problem.reload.resolved?}).to eq false
37 34 end
38 35 end
39   -
40 36 end
41 37  
42 38 it "should produce a shortened revision with 7 characters" do
... ...
spec/models/err_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Err do
4   -
  1 +describe Err, type: 'model' do
5 2 context 'validations' do
6 3 it 'requires a fingerprint' do
7 4 err = Fabricate.build(:err, :fingerprint => nil)
... ... @@ -15,5 +12,4 @@ describe Err do
15 12 expect(err.errors[:problem_id]).to include("can't be blank")
16 13 end
17 14 end
18   -
19 15 end
... ...
spec/models/error_report_spec.rb
1   -require 'spec_helper'
2 1 require 'airbrake/version'
3 2 require 'airbrake/backtrace'
4 3 require 'airbrake/notice'
... ... @@ -41,22 +40,22 @@ describe ErrorReport do
41 40 end
42 41  
43 42 describe "#backtrace" do
44   -
45 43 it 'should have valid backtrace' do
46 44 expect(error_report.backtrace).to be_valid
47 45 end
48 46 end
49 47  
50 48 describe "#fingerprint_strategy" do
51   - after(:all) {
52   - error_report.fingerprint_strategy = Fingerprint::Sha1
53   - }
54   -
55 49 it "should be possible to change how fingerprints are generated" do
56   - strategy = double()
57   - strategy.should_receive(:generate){ 'fingerprints' }
58   - error_report.fingerprint_strategy = strategy
59   - error_report.generate_notice!
  50 + def error_report.fingerprint_strategy
  51 + Class.new do
  52 + def self.generate(*args)
  53 + 'fingerprintzzz'
  54 + end
  55 + end
  56 + end
  57 +
  58 + expect(error_report.error.fingerprint).to eq('fingerprintzzz')
60 59 end
61 60 end
62 61  
... ... @@ -68,6 +67,7 @@ describe ErrorReport do
68 67 app.reload.problems.count
69 68 }.by(1)
70 69 end
  70 +
71 71 context "with notice generate by Airbrake gem" do
72 72 let(:xml) { Airbrake::Notice.new(
73 73 :exception => Exception.new,
... ... @@ -112,73 +112,74 @@ describe ErrorReport do
112 112 expect(subject.user_attributes['email']).to eq 'mr.bean@example.com'
113 113 expect(subject.user_attributes['username']).to eq 'mrbean'
114 114 end
  115 +
115 116 it 'valid env_vars' do
116   - # XML: <var key="SCRIPT_NAME"/>
117   - expect(subject.env_vars).to have_key('SCRIPT_NAME')
118   - expect(subject.env_vars['SCRIPT_NAME']).to be_nil # blank ends up nil
119   -
120   - # XML representation:
121   - # <var key="rack.session.options">
122   - # <var key="secure">false</var>
123   - # <var key="httponly">true</var>
124   - # <var key="path">/</var>
125   - # <var key="expire_after"/>
126   - # <var key="domain"/>
127   - # <var key="id"/>
128   - # </var>
129   - expected = {
130   - 'secure' => 'false',
131   - 'httponly' => 'true',
132   - 'path' => '/',
133   - 'expire_after' => nil,
134   - 'domain' => nil,
135   - 'id' => nil
136   - }
137   - expect(subject.env_vars).to have_key('rack_session_options')
138   - expect(subject.env_vars['rack_session_options']).to eql(expected)
139   - end
  117 + # XML: <var key="SCRIPT_NAME"/>
  118 + expect(subject.env_vars).to have_key('SCRIPT_NAME')
  119 + expect(subject.env_vars['SCRIPT_NAME']).to be_nil # blank ends up nil
  120 +
  121 + # XML representation:
  122 + # <var key="rack.session.options">
  123 + # <var key="secure">false</var>
  124 + # <var key="httponly">true</var>
  125 + # <var key="path">/</var>
  126 + # <var key="expire_after"/>
  127 + # <var key="domain"/>
  128 + # <var key="id"/>
  129 + # </var>
  130 + expected = {
  131 + 'secure' => 'false',
  132 + 'httponly' => 'true',
  133 + 'path' => '/',
  134 + 'expire_after' => nil,
  135 + 'domain' => nil,
  136 + 'id' => nil
  137 + }
  138 + expect(subject.env_vars).to have_key('rack_session_options')
  139 + expect(subject.env_vars['rack_session_options']).to eql(expected)
  140 + end
140 141 end
  142 + end
  143 +
  144 + it 'save a notice assignes to err' do
  145 + error_report.generate_notice!
  146 + expect(error_report.notice.err).to be_a(Err)
  147 + end
141 148  
142   - it 'save a notice assignes to err' do
  149 + it 'memoize the notice' do
  150 + expect {
143 151 error_report.generate_notice!
144   - expect(error_report.notice.err).to be_a(Err)
145   - end
  152 + error_report.generate_notice!
  153 + }.to change {
  154 + Notice.count
  155 + }.by(1)
  156 + end
146 157  
147   - it 'memoize the notice' do
148   - expect {
149   - error_report.generate_notice!
150   - error_report.generate_notice!
151   - }.to change {
152   - Notice.count
153   - }.by(1)
154   - end
  158 + it 'find the correct err for the notice' do
  159 + err = Fabricate(:err, :problem => Fabricate(:problem, :resolved => true))
155 160  
156   - it 'find the correct err for the notice' do
157   - err = Fabricate(:err, :problem => Fabricate(:problem, :resolved => true))
  161 + allow(error_report).to receive(:fingerprint).and_return(err.fingerprint)
158 162  
159   - ErrorReport.any_instance.stub(:fingerprint).and_return(err.fingerprint)
  163 + expect {
  164 + error_report.generate_notice!
  165 + }.to change {
  166 + error_report.error.resolved?
  167 + }.from(true).to(false)
  168 + end
160 169  
161   - expect {
162   - error_report.generate_notice!
163   - }.to change {
164   - error_report.error.resolved?
165   - }.from(true).to(false)
  170 + context "with notification service configured" do
  171 + before do
  172 + app.notify_on_errs = true
  173 + app.watchers.build(:email => 'foo@example.com')
  174 + app.save
166 175 end
167   -
168   - context "with notification service configured" do
169   - before do
170   - app.notify_on_errs = true
171   - app.watchers.build(:email => 'foo@example.com')
172   - app.save
173   - end
174   - it 'send email' do
175   - notice = error_report.generate_notice!
176   - email = ActionMailer::Base.deliveries.last
177   - expect(email.to).to include(app.watchers.first.email)
178   - expect(email.subject).to include(notice.message.truncate(50))
179   - expect(email.subject).to include("[#{app.name}]")
180   - expect(email.subject).to include("[#{notice.environment_name}]")
181   - end
  176 + it 'send email' do
  177 + notice = error_report.generate_notice!
  178 + email = ActionMailer::Base.deliveries.last
  179 + expect(email.to).to include(app.watchers.first.email)
  180 + expect(email.subject).to include(notice.message.truncate(50))
  181 + expect(email.subject).to include("[#{app.name}]")
  182 + expect(email.subject).to include("[#{notice.environment_name}]")
182 183 end
183 184  
184 185 context "with xml without request section" do
... ... @@ -270,8 +271,6 @@ describe ErrorReport do
270 271 expect(error_report.should_keep?).to be false
271 272 end
272 273 end
273   -
274 274 end
275   -
276 275 end
277 276 end
... ...
spec/models/fabricators_spec.rb
1   -require 'spec_helper'
2   -
3 1 Fabrication::Config.fabricator_path.each do |folder|
4 2 Dir.glob(File.join(Rails.root, folder, '**', '*.rb')).each do |file|
5 3 require file
... ...
spec/models/fingerprint/md5_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Fingerprint::MD5 do
  1 +describe Fingerprint::MD5, type: 'model' do
4 2 context 'being created' do
5 3 let(:backtrace) do
6 4 Backtrace.create(:raw => [
... ...
spec/models/fingerprint/sha1_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Fingerprint::Sha1 do
4   -
  1 +describe Fingerprint::Sha1, type: 'model' do
5 2 context '#generate' do
6 3 let(:backtrace) {
7 4 Backtrace.create(:raw => [
... ... @@ -80,8 +77,5 @@ describe Fingerprint::Sha1 do
80 77 should eq "#<ActiveSupport::HashWithIndifferentAccess> #<Object>"
81 78 end
82 79 end
83   -
84 80 end
85   -
86 81 end
87   -
... ...
spec/models/issue_spec.rb
1   -require "spec_helper"
2   -
3   -describe Issue do
4   -
  1 +describe Issue, type: 'model' do
5 2 subject(:issue) { Issue.new(problem: problem, user: user, title: title, body: body) }
6 3  
7 4 let(:problem) { notice.problem }
... ... @@ -33,15 +30,13 @@ describe Issue do
33 30 context "when has no title" do
34 31 let(:body) { "barrr" }
35 32  
36   - pending "returns an error" do
37   - end
  33 + pending "returns an error"
38 34 end
39 35  
40 36 context "when has no body" do
41 37 let(:title) { "Foo" }
42 38  
43   - pending "returns an error" do
44   - end
  39 + pending "returns an error"
45 40 end
46 41  
47 42 context "when app has a issue tracker" do
... ...
spec/models/issue_tracker_spec.rb
1   -require 'spec_helper'
2   -
3   -describe IssueTracker do
  1 +describe IssueTracker, type: 'model' do
4 2 describe "Association" do
5 3 it { should be_embedded_in(:app) }
6 4 end
... ...
spec/models/notice_observer_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "Callback on Notice" do
  1 +describe "Callback on Notice", type: 'model' do
4 2 describe "email notifications (configured individually for each app)" do
5 3 custom_thresholds = [2, 4, 8, 16, 32, 64]
6 4  
... ... @@ -24,7 +22,6 @@ describe &quot;Callback on Notice&quot; do
24 22 end
25 23 end
26 24  
27   -
28 25 describe "email notifications for a resolved issue" do
29 26 before do
30 27 Errbit::Config.per_app_email_at_notices = true
... ...
spec/models/notice_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Notice do
  1 +describe Notice, type: 'model' do
4 2 context 'validations' do
5 3 it 'requires a backtrace' do
6 4 notice = Fabricate.build(:notice, :backtrace => nil)
... ...
spec/models/notification_service/campfire_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationService::CampfireService do
  1 +describe NotificationService::CampfireService, type: 'model' do
4 2 it "it should send a notification to campfire" do
5 3 # setup
6 4 notice = Fabricate :notice
... ... @@ -9,8 +7,8 @@ describe NotificationService::CampfireService do
9 7  
10 8 #campy stubbing
11 9 campy = double('CampfireService')
12   - Campy::Room.stub(:new).and_return(campy)
13   - campy.stub(:speak) { true }
  10 + allow(Campy::Room).to receive(:new).and_return(campy)
  11 + allow(campy).to receive(:speak).and_return(true)
14 12  
15 13 #assert
16 14 expect(campy).to receive(:speak)
... ... @@ -18,4 +16,3 @@ describe NotificationService::CampfireService do
18 16 notification_service.create_notification(problem)
19 17 end
20 18 end
21   -
... ...
spec/models/notification_service/flowdock_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationServices::FlowdockService do
  1 +describe NotificationServices::FlowdockService, type: 'model' do
4 2 let(:service) { Fabricate.build(:flowdock_notification_service) }
5 3 let(:app) { Fabricate(:app, :name => 'App #3') }
6 4 let(:problem) { Fabricate(:problem, :app => app, :message => '<3') }
7 5  
8 6 it 'sends message in appropriate format' do
9   - Flowdock::Flow.any_instance.should_receive(:push_to_team_inbox) do |*args|
10   - expect(args.first[:content]).to_not include('<3')
11   - expect(args.first[:content]).to include('&lt;3')
12   -
13   - expect(args.first[:project]).to eq('App3')
  7 + allow_any_instance_of(Flowdock::Flow).to receive(:push_to_team_inbox) do |*args|
  8 + expect(args[1][:content]).to_not include('<3')
  9 + expect(args[1][:content]).to include('&lt;3')
  10 + expect(args[1][:project]).to eq('App3')
14 11 end
  12 +
15 13 service.create_notification(problem)
16 14 end
17 15 end
... ...
spec/models/notification_service/gtalk_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationService::GtalkService do
  1 +describe NotificationService::GtalkService, type: 'model' do
4 2 it "it should send a notification to gtalk" do
5 3 # setup
6 4 notice = Fabricate :notice
... ... @@ -47,8 +45,8 @@ describe NotificationService::GtalkService do
47 45 expect(@gtalk).to receive(:connect)
48 46 expect(@gtalk).to receive(:auth)
49 47 jid = double("jid")
50   - Jabber::JID.stub(:new).with(@notification_service.subdomain).and_return(jid)
51   - Jabber::Client.stub(:new).with(jid).and_return(@gtalk)
  48 + allow(Jabber::JID).to receive(:new).with(@notification_service.subdomain).and_return(jid)
  49 + allow(Jabber::Client).to receive(:new).with(jid).and_return(@gtalk)
52 50 end
53 51 it "should send a notification to all ',' separated users" do
54 52 expect(Jabber::Message).to receive(:new).with("first@domain.org", @error_msg)
... ... @@ -120,6 +118,4 @@ describe NotificationService::GtalkService do
120 118  
121 119 notification_service.create_notification(problem)
122 120 end
123   -
124 121 end
125   -
... ...
spec/models/notification_service/hipchat_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationServices::HipchatService do
  1 +describe NotificationServices::HipchatService, type: 'model' do
4 2 let(:service) { Fabricate.build(:hipchat_notification_service) }
5 3 let(:problem) { Fabricate(:problem) }
6 4 let(:room) { double }
7 5  
8 6 before do
9   - HipChat::Client.any_instance.stub(:[] => room)
  7 + allow_any_instance_of(HipChat::Client).to receive(:[]).and_return(room)
10 8 end
11 9  
12 10 it 'sends message' do
... ... @@ -15,7 +13,7 @@ describe NotificationServices::HipchatService do
15 13 end
16 14  
17 15 it 'escapes html in message' do
18   - problem.stub(:message => '<3')
  16 + allow(problem).to receive(:message).and_return('<3')
19 17 expect(room).to receive(:send) do |_, message|
20 18 expect(message).to_not include('<3')
21 19 expect(message).to include('&lt;3')
... ...
spec/models/notification_service/hoiio_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationService::HoiioService do
  1 +describe NotificationService::HoiioService, type: 'model' do
4 2 it "it should send a notification to hoiio" do
5 3 # setup
6 4 notice = Fabricate :notice
... ... @@ -9,8 +7,8 @@ describe NotificationService::HoiioService do
9 7  
10 8 # hoi stubbing
11 9 sms = double('HoiioService')
12   - Hoi::SMS.stub(:new).and_return(sms)
13   - sms.stub(:send) { true }
  10 + allow(Hoi::SMS).to receive(:new).and_return(sms)
  11 + allow(sms).to receive(:send).and_return(true)
14 12  
15 13 #assert
16 14 expect(sms).to receive(:send)
... ... @@ -18,4 +16,3 @@ describe NotificationService::HoiioService do
18 16 notification_service.create_notification(problem)
19 17 end
20 18 end
21   -
... ...
spec/models/notification_service/hubot_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationService::HubotService do
  1 +describe NotificationService::HubotService, type: 'model' do
4 2 it "it should send a notification to Hubot" do
5 3 # setup
6 4 notice = Fabricate :notice
... ...
spec/models/notification_service/notification_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationService do
  1 +describe NotificationService, type: 'model' do
4 2  
5 3 let(:notice) { Fabricate :notice }
6 4 let(:notification_service) { Fabricate :notification_service, :app => notice.app }
7 5 let(:problem) { notice.problem }
8 6  
9 7 it "it should use http by default in #problem_url" do
10   - notification_service.problem_url(problem).should start_with 'http://'
  8 + expect(notification_service.problem_url(problem)).to start_with 'http://'
11 9 end
12 10  
13 11 it "it should use the protocol value specified in the config in #problem_url" do
14 12 Errbit::Config.protocol = 'https'
15   - notification_service.problem_url(problem).should start_with 'https://'
  13 + expect(notification_service.problem_url(problem)).to start_with 'https://'
16 14 end
17   -
18 15 end
... ...
spec/models/notification_service/pushover_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationService::PushoverService do
  1 +describe NotificationService::PushoverService, type: 'model' do
4 2 it "it should send a notification to Pushover" do
5 3 # setup
6 4 notice = Fabricate :notice
... ... @@ -9,8 +7,8 @@ describe NotificationService::PushoverService do
9 7  
10 8 # hoi stubbing
11 9 notification = double('PushoverService')
12   - Rushover::Client.stub(:new).and_return(notification)
13   - notification.stub(:notify) { true }
  10 + allow(Rushover::Client).to receive(:new).and_return(notification)
  11 + allow(notification).to receive(:notify).and_return(true)
14 12  
15 13 #assert
16 14 expect(notification).to receive(:notify)
... ...
spec/models/notification_service/slack_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationService::SlackService do
  1 +describe NotificationService::SlackService, type: 'model' do
4 2 it "it should send a notification to Slack with channel" do
5 3 # setup
6 4 notice = Fabricate :notice
... ...
spec/models/notification_service/webhook_service_spec.rb
1   -require 'spec_helper'
2   -
3   -describe NotificationService::WebhookService do
  1 +describe NotificationService::WebhookService, type: 'model' do
4 2 it "it should send a notification to a user-specified URL" do
5 3 notice = Fabricate :notice
6 4 notification_service = Fabricate :webhook_notification_service, :app => notice.app
7 5 problem = notice.problem
8   -
  6 +
9 7 expect(HTTParty).to receive(:post).with(notification_service.api_token, :body => {:problem => problem.to_json}).and_return(true)
10 8  
11 9 notification_service.create_notification(problem)
... ...
spec/models/problem_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Problem do
4   -
  1 +describe Problem, type: 'model' do
5 2 context 'validations' do
6 3 it 'requires an environment' do
7 4 err = Fabricate.build(:problem, :environment => nil)
... ... @@ -59,7 +56,7 @@ describe Problem do
59 56 notice1 = Fabricate(:notice, :err => err)
60 57 expect(problem.first_notice_at.to_i).to be_within(1).of(notice1.created_at.to_i)
61 58  
62   - notice2 = Fabricate(:notice, :err => err)
  59 + Fabricate(:notice, :err => err)
63 60 expect(problem.first_notice_at.to_i).to be_within(1).of(notice1.created_at.to_i)
64 61 end
65 62 end
... ... @@ -128,12 +125,12 @@ describe Problem do
128 125 it "should throw an err if it's not successful" do
129 126 problem = Fabricate(:problem)
130 127 expect(problem).to_not be_resolved
131   - problem.stub(:valid?).and_return(false)
  128 + allow(problem).to receive(:valid?).and_return(false)
132 129 ## update_attributes not test #valid? but #errors.any?
133 130 # https://github.com/mongoid/mongoid/blob/master/lib/mongoid/persistence.rb#L137
134 131 er = ActiveModel::Errors.new(problem)
135 132 er.add_on_blank(:resolved)
136   - problem.stub(:errors).and_return(er)
  133 + allow(problem).to receive(:errors).and_return(er)
137 134 expect(problem).to_not be_valid
138 135 expect {
139 136 problem.resolve!
... ... @@ -210,7 +207,7 @@ describe Problem do
210 207 end
211 208  
212 209 it "removing a notice decreases #notices_count by 1" do
213   - notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1')
  210 + Fabricate(:notice, :err => @err, :message => 'ERR 1')
214 211 expect {
215 212 @err.notices.first.destroy
216 213 @problem.reload
... ... @@ -240,7 +237,7 @@ describe Problem do
240 237 before do
241 238 @app = Fabricate(:app)
242 239 @last_deploy = Time.at(10.days.ago.localtime.to_i)
243   - deploy = Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production")
  240 + Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production")
244 241 end
245 242  
246 243 it "is set when a problem is created" do
... ... @@ -276,7 +273,7 @@ describe Problem do
276 273 end
277 274  
278 275 it "removing a notice removes string from #messages" do
279   - notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1')
  276 + Fabricate(:notice, :err => @err, :message => 'ERR 1')
280 277 expect {
281 278 @err.notices.first.destroy
282 279 @problem.reload
... ... @@ -284,7 +281,7 @@ describe Problem do
284 281 end
285 282  
286 283 it "removing a notice from the problem with broken counter should not raise an error" do
287   - notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1')
  284 + Fabricate(:notice, :err => @err, :message => 'ERR 1')
288 285 @problem.messages = {}
289 286 @problem.save!
290 287 expect {@err.notices.first.destroy}.not_to raise_error
... ... @@ -309,7 +306,7 @@ describe Problem do
309 306 end
310 307  
311 308 it "removing a notice removes string from #hosts" do
312   - notice1 = Fabricate(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"})
  309 + Fabricate(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"})
313 310 expect {
314 311 @err.notices.first.destroy
315 312 @problem.reload
... ... @@ -335,7 +332,7 @@ describe Problem do
335 332 end
336 333  
337 334 it "removing a notice removes string from #user_agents" do
338   - notice1 = Fabricate(:notice, :err => @err, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}})
  335 + Fabricate(:notice, :err => @err, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}})
339 336 expect {
340 337 @err.notices.first.destroy
341 338 @problem.reload
... ... @@ -362,7 +359,7 @@ describe Problem do
362 359 end
363 360  
364 361 it "removing a comment decreases #comments_count by 1" do
365   - comment1 = Fabricate(:comment, :err => @problem)
  362 + Fabricate(:comment, :err => @problem)
366 363 expect {
367 364 @problem.reload.comments.first.destroy
368 365 @problem.reload
... ... @@ -418,7 +415,4 @@ describe Problem do
418 415 end
419 416 end
420 417 end
421   -
422   -
423 418 end
424   -
... ...
spec/models/user_spec.rb
1   -require 'spec_helper'
2   -
3 1 describe User do
4   -
5 2 context 'validations' do
6 3 it 'require that a name is present' do
7 4 user = Fabricate.build(:user, :name => nil)
... ... @@ -41,7 +38,6 @@ describe User do
41 38 end
42 39  
43 40 context 'Watchers' do
44   -
45 41 it 'has many watchers' do
46 42 user = Fabricate(:user)
47 43 watcher = Fabricate(:user_watcher, :user => user)
... ... @@ -53,23 +49,20 @@ describe User do
53 49 user = Fabricate(:user)
54 50 watched_app = Fabricate(:app)
55 51 unwatched_app = Fabricate(:app)
56   - watcher = Fabricate(:user_watcher, :app => watched_app, :user => user)
  52 + Fabricate(:user_watcher, :app => watched_app, :user => user)
57 53 expect(user.apps.all).to include(watched_app)
58 54 expect(user.apps.all).to_not include(unwatched_app)
59 55 end
60   -
61 56 end
62 57  
63 58 context "First user" do
64 59 it "should be created this admin access via db:seed" do
65 60 expect {
66   - $stdout.stub(:puts => true)
  61 + allow($stdout).to receive(:puts).and_return(true)
67 62 require Rails.root.join('db/seeds.rb')
68 63 }.to change {
69 64 User.where(:admin => true).count
70 65 }.from(0).to(1)
71 66 end
72 67 end
73   -
74 68 end
75   -
... ...
spec/models/watcher_spec.rb
1   -require 'spec_helper'
2   -
3   -describe Watcher do
4   -
  1 +describe Watcher, type: 'model' do
5 2 context 'validations' do
6 3 it 'requires an email address or an associated user' do
7 4 watcher = Fabricate.build(:watcher, :email => nil, :user => nil)
... ... @@ -32,6 +29,4 @@ describe Watcher do
32 29 expect(watcher.address).to eq 'widgets@acme.com'
33 30 end
34 31 end
35   -
36 32 end
37   -
... ...
spec/rails_helper.rb 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +# This file is copied to spec/ when you run 'rails generate rspec:install'
  2 +ENV["RAILS_ENV"] ||= 'test'
  3 +require 'spec_helper'
  4 +require File.expand_path("../../config/environment", __FILE__)
  5 +require 'rspec/rails'
  6 +# Add additional requires below this line. Rails is not loaded until this point!
  7 +
  8 +# Requires supporting ruby files with custom matchers and macros, etc, in
  9 +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
  10 +# run as spec files by default. This means that files in spec/support that end
  11 +# in _spec.rb will both be required and run as specs, causing the specs to be
  12 +# run twice. It is recommended that you do not name files matching this glob to
  13 +# end with _spec.rb. You can configure this pattern with the --pattern
  14 +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
  15 +#
  16 +# The following line is provided for convenience purposes. It has the downside
  17 +# of increasing the boot-up time by auto-requiring all files in the support
  18 +# directory. Alternatively, in the individual `*_spec.rb` files, manually
  19 +# require only the support files necessary.
  20 +#
  21 +# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
  22 +
  23 +RSpec.configure do |config|
  24 + # RSpec Rails can automatically mix in different behaviours to your tests
  25 + # based on their file location, for example enabling you to call `get` and
  26 + # `post` in specs under `spec/controllers`.
  27 + #
  28 + # You can disable this behaviour by removing the line below, and instead
  29 + # explicitly tag your specs with their type, e.g.:
  30 + #
  31 + # RSpec.describe UsersController, :type => :controller do
  32 + # # ...
  33 + # end
  34 + #
  35 + # The different available types are documented in the features, such as in
  36 + # https://relishapp.com/rspec/rspec-rails/docs
  37 + config.infer_spec_type_from_file_location!
  38 +end
... ...
spec/requests/notices_controller_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "Notices management" do
4   -
5   - let(:errbit_app) { Fabricate(:app,
6   - :api_key => 'APIKEY') }
  1 +describe "Notices management", type: 'request' do
  2 + let(:errbit_app) { Fabricate(:app, :api_key => 'APIKEY') }
7 3  
8 4 describe "create a new notice" do
9 5 context "with valide notice" do
... ... @@ -38,11 +34,8 @@ describe &quot;Notices management&quot; do
38 34 post '/notifier_api/v2/notices', :data => xml
39 35 expect(response.status).to eq 422
40 36 expect(response.body).to eq "Your API key is unknown"
41   - }.to_not change {
42   - errbit_app.problems.count
43   - }.by(1)
  37 + }.to_not change(errbit_app.problems, :count)
44 38 end
45   -
46 39 end
47 40  
48 41 context "with GET request" do
... ...
spec/spec_helper.rb
... ... @@ -19,11 +19,13 @@ end
19 19  
20 20 require File.expand_path("../../config/environment", __FILE__)
21 21 require 'rspec/rails'
  22 +require 'rspec/its'
22 23 require 'email_spec'
23 24 require 'database_cleaner'
24 25 require 'xmpp4r'
25 26 require 'xmpp4r/muc'
26 27 require 'mongoid-rspec'
  28 +require 'fabrication'
27 29 require 'errbit_plugin/mock_issue_tracker'
28 30  
29 31 # Requires supporting files with custom matchers and macros, etc,
... ... @@ -31,11 +33,8 @@ require &#39;errbit_plugin/mock_issue_tracker&#39;
31 33 Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
32 34  
33 35 RSpec.configure do |config|
34   - config.mock_with :rspec
35 36 config.include Devise::TestHelpers, :type => :controller
36 37 config.include Mongoid::Matchers, :type => :model
37   - config.filter_run :focused => true
38   - config.run_all_when_everything_filtered = true
39 38 config.alias_example_to :fit, :focused => true
40 39  
41 40 config.before(:each) do
... ...
spec/support/macros.rb
... ... @@ -21,13 +21,13 @@ def it_requires_authentication(options = {})
21 21 options[:for].each do |action, method|
22 22 it "#{method.to_s.upcase} #{action} redirects to the sign in page" do
23 23 send(method, action, options[:params])
24   - response.should redirect_to(new_user_session_path)
  24 + expect(response).to redirect_to(new_user_session_path)
25 25 end
26 26 end
27 27 end
28 28 end
29 29  
30   -def it_requires_admin_privileges(options = {})
  30 +def it_requires_admin_privileges(options = {})
31 31 default_options = {
32 32 :for => {
33 33 :index => :get,
... ... @@ -51,7 +51,7 @@ def it_requires_admin_privileges(options = {})
51 51 options[:for].each do |action, method|
52 52 it "#{method.to_s.upcase} #{action} redirects to the root path" do
53 53 send(method, action, options[:params])
54   - response.should redirect_to(root_path)
  54 + expect(response).to redirect_to(root_path)
55 55 end
56 56 end
57 57 end
... ...
spec/views/apps/edit.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "apps/edit.html.haml" do
  1 +describe "apps/edit.html.haml", type: 'view' do
4 2 let(:app) { stub_model(App) }
5 3 let(:app_decorate) { AppDecorator.new(app) }
  4 +
6 5 before do
7   - view.stub(:app).and_return(app)
8   - view.stub(:app_decorate).and_return(app_decorate)
9   - controller.stub(:current_user) { stub_model(User) }
  6 + allow(view).to receive(:app).and_return(app)
  7 + allow(view).to receive(:app_decorate).and_return(app_decorate)
  8 + allow(controller).to receive(:current_user).and_return(stub_model(User))
10 9 end
11 10  
12 11 describe "content_for :action_bar" do
... ... @@ -23,7 +22,6 @@ describe &quot;apps/edit.html.haml&quot; do
23 22 render
24 23 expect(action_bar).to have_selector('a.button[data-confirm="%s"]' % I18n.t('apps.confirm_delete'))
25 24 end
26   -
27 25 end
28 26  
29 27 context "with unvalid app" do
... ... @@ -38,6 +36,4 @@ describe &quot;apps/edit.html.haml&quot; do
38 36 expect(rendered).to match(/You must specify your/)
39 37 end
40 38 end
41   -
42 39 end
43   -
... ...
spec/views/apps/index.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "apps/index.html.haml" do
  1 +describe "apps/index.html.haml", type: 'view' do
4 2 before do
5 3 app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.now, :revision => "123456789abcdef")])
6   - view.stub(:apps).and_return([app])
7   - controller.stub(:current_user) { stub_model(User) }
  4 + allow(view).to receive(:apps).and_return([app])
  5 + allow(controller).to receive(:current_user).and_return(stub_model(User))
8 6 end
9 7  
10 8 describe "deploy column" do
... ... @@ -14,4 +12,3 @@ describe &quot;apps/index.html.haml&quot; do
14 12 end
15 13 end
16 14 end
17   -
... ...
spec/views/apps/new.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "apps/new.html.haml" do
  1 +describe "apps/new.html.haml", type: 'view' do
4 2 let(:app) { stub_model(App) }
5 3 let(:app_decorate) { AppDecorator.new(app) }
  4 +
6 5 before do
7   - view.stub(:app).and_return(app)
8   - view.stub(:app_decorate).and_return(app_decorate)
9   - controller.stub(:current_user) { stub_model(User) }
  6 + allow(view).to receive(:app).and_return(app)
  7 + allow(view).to receive(:app_decorate).and_return(app_decorate)
  8 + allow(controller).to receive(:current_user).and_return(stub_model(User))
10 9 end
11 10  
12 11 describe "content_for :action_bar" do
... ... @@ -34,6 +33,4 @@ describe &quot;apps/new.html.haml&quot; do
34 33 expect(rendered).to match(/You must specify your/)
35 34 end
36 35 end
37   -
38 36 end
39   -
... ...
spec/views/apps/show.atom.builder_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "apps/show.atom.builder" do
  1 +describe "apps/show.atom.builder", type: 'view' do
4 2 let(:app) { stub_model(App) }
5 3 let(:problems) { [
6 4 stub_model(Problem, :message => 'foo', :app => app)
7 5 ]}
8 6  
9 7 before do
10   - view.stub(:app).and_return(app)
11   - view.stub(:problems).and_return(problems)
  8 + allow(view).to receive(:app).and_return(app)
  9 + allow(view).to receive(:problems).and_return(problems)
12 10 end
13 11  
14 12 context "with errs" do
... ... @@ -17,5 +15,4 @@ describe &quot;apps/show.atom.builder&quot; do
17 15 expect(rendered).to match(problems.first.message)
18 16 end
19 17 end
20   -
21 18 end
... ...
spec/views/apps/show.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "apps/show.html.haml" do
  1 +describe "apps/show.html.haml", type: 'view' do
4 2 let(:app) { stub_model(App) }
5 3 let(:user) { stub_model(User) }
6 4  
... ... @@ -9,20 +7,18 @@ describe &quot;apps/show.html.haml&quot; do
9 7 end
10 8  
11 9 before do
12   - view.stub(:app).and_return(app)
13   - view.stub(:all_errs).and_return(false)
14   - view.stub(:deploys).and_return([])
15   - controller.stub(:current_user) { user }
  10 + allow(view).to receive(:app).and_return(app)
  11 + allow(view).to receive(:all_errs).and_return(false)
  12 + allow(view).to receive(:deploys).and_return([])
  13 + allow(controller).to receive(:current_user).and_return(user)
16 14 end
17 15  
18 16 describe "content_for :action_bar" do
19   -
20 17 it "should confirm the 'cancel' link" do
21 18 render
22 19  
23 20 expect(action_bar).to have_selector('a.button', :text => 'all errs')
24 21 end
25   -
26 22 end
27 23  
28 24 context "without errs" do
... ... @@ -34,7 +30,7 @@ describe &quot;apps/show.html.haml&quot; do
34 30  
35 31 context "with user watch application" do
36 32 before do
37   - user.stub(:watching?).with(app).and_return(true)
  33 + allow(user).to receive(:watching?).with(app).and_return(true)
38 34 end
39 35 it 'see the unwatch button' do
40 36 render
... ... @@ -44,13 +40,11 @@ describe &quot;apps/show.html.haml&quot; do
44 40  
45 41 context "with user not watch application" do
46 42 before do
47   - user.stub(:watching?).with(app).and_return(false)
  43 + allow(user).to receive(:watching?).with(app).and_return(false)
48 44 end
49 45 it 'not see the unwatch button' do
50 46 render
51 47 expect(action_bar).to_not include(I18n.t('apps.show.unwatch'))
52 48 end
53 49 end
54   -
55 50 end
56   -
... ...
spec/views/notices/_summary.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "notices/_summary.html.haml" do
  1 +describe "notices/_summary.html.haml", type: 'view' do
4 2 let(:notice) { Fabricate(:notice, :framework => 'Rails 3.2.11') }
5 3  
6 4 it "renders application framework" do
... ... @@ -9,4 +7,3 @@ describe &quot;notices/_summary.html.haml&quot; do
9 7 expect(rendered).to have_content('Rails 3.2.11')
10 8 end
11 9 end
12   -
... ...
spec/views/notices/_user_attributes.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "notices/_user_attributes.html.haml" do
  1 +describe "notices/_user_attributes.html.haml", type: 'view' do
4 2 describe 'autolink' do
5 3 let(:notice) do
6 4 user_attributes = { 'foo' => {'bar' => 'http://example.com'} }
... ... @@ -15,4 +13,3 @@ describe &quot;notices/_user_attributes.html.haml&quot; do
15 13 end
16 14 end
17 15 end
18   -
... ...
spec/views/problems/index.atom.builder_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "problems/index.atom.builder" do
4   -
  1 +describe "problems/index.atom.builder", type: 'view' do
5 2 it 'display problem message' do
6 3 app = App.new(:new_record => false)
7   - view.stub(:problems).and_return([Problem.new(
  4 + allow(view).to receive(:problems).and_return([Problem.new(
8 5 :message => 'foo',
9 6 :new_record => false, :app => app), Problem.new(:new_record => false, :app => app)])
10 7 render
11 8 expect(rendered).to match('foo')
12 9 end
13   -
14 10 end
... ...
spec/views/problems/index.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "problems/index.html.haml" do
  1 +describe "problems/index.html.haml", type: 'view' do
4 2 let(:problem_1) { Fabricate(:problem) }
5 3 let(:problem_2) { Fabricate(:problem, :app => problem_1.app) }
6 4  
7 5 before do
8   - # view.stub(:app).and_return(problem.app)
9   - view.stub(:selected_problems).and_return([])
10   - view.stub(:problems).and_return(Kaminari.paginate_array([problem_1, problem_2]).page(1).per(10))
11   - view.stub(:params_sort).and_return('asc')
12   - controller.stub(:current_user) { Fabricate(:user) }
  6 + allow(view).to receive(:selected_problems).and_return([])
  7 + allow(view).to receive(:problems).and_return(
  8 + Kaminari.paginate_array([problem_1, problem_2]).page(1).per(10)
  9 + )
  10 + allow(view).to receive(:params_sort).and_return('asc')
  11 + allow(controller).to receive(:current_user).and_return(Fabricate(:user))
13 12 end
14 13  
15 14 describe "with problem" do
... ... @@ -20,6 +19,4 @@ describe &quot;problems/index.html.haml&quot; do
20 19 expect(rendered).to have_selector('div#problem_table.problem_table')
21 20 end
22 21 end
23   -
24 22 end
25   -
... ...
spec/views/problems/show.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "problems/show.html.haml" do
  1 +describe "problems/show.html.haml", type: 'view' do
4 2 let(:problem) { Fabricate(:problem) }
5 3 let(:comment) { Fabricate(:comment) }
6 4 let(:pivotal_tracker) {
... ... @@ -23,22 +21,19 @@ describe &quot;problems/show.html.haml&quot; do
23 21 }
24 22  
25 23 before do
26   - view.stub(:app).and_return(problem.app)
27   - view.stub(:problem).and_return(problem)
  24 + allow(view).to receive(:app).and_return(problem.app)
  25 + allow(view).to receive(:problem).and_return(problem)
28 26  
29 27 assign :comment, comment
30 28 assign :notices, problem.notices.page(1).per(1)
31 29 assign :notice, problem.notices.first
32 30  
33   - controller.stub(:current_user) { Fabricate(:user) }
  31 + allow(controller).to receive(:current_user).and_return(Fabricate(:user))
34 32 end
35 33  
36 34 def with_issue_tracker(tracker, problem)
37   - ErrbitPlugin::Registry.stub(:issue_trackers).and_return(trackers)
  35 + allow(ErrbitPlugin::Registry).to receive(:issue_trackers).and_return(trackers)
38 36 problem.app.issue_tracker = IssueTracker.new :type_tracker => tracker, :options => {:api_token => "token token token", :project_id => "1234"}
39   -
40   - view.stub(:problem).and_return(problem)
41   - view.stub(:app).and_return(problem.app)
42 37 end
43 38  
44 39 describe "content_for :action_bar" do
... ... @@ -52,13 +47,13 @@ describe &quot;problems/show.html.haml&quot; do
52 47 end
53 48  
54 49 it "should confirm the 'resolve' link if configuration is unset" do
55   - Errbit::Config.stub(:confirm_err_actions).and_return(nil)
  50 + allow(Errbit::Config).to receive(:confirm_err_actions).and_return(nil)
56 51 render
57 52 expect(action_bar).to have_selector('a.resolve[data-confirm="%s"]' % I18n.t('problems.confirm.resolve_one'))
58 53 end
59 54  
60 55 it "should not confirm the 'resolve' link if configured not to" do
61   - Errbit::Config.stub(:confirm_err_actions).and_return(false)
  56 + allow(Errbit::Config).to receive(:confirm_err_actions).and_return(false)
62 57 render
63 58 expect(action_bar).to have_selector('a.resolve[data-confirm="null"]')
64 59 end
... ... @@ -73,8 +68,9 @@ describe &quot;problems/show.html.haml&quot; do
73 68 it "should link 'up' to app_problems_path if HTTP_REFERER isn't set'" do
74 69 controller.request.env['HTTP_REFERER'] = nil
75 70 problem = Fabricate(:problem_with_comments)
76   - view.stub(:problem).and_return(problem)
77   - view.stub(:app).and_return(problem.app)
  71 +
  72 + allow(view).to receive(:problem).and_return(problem)
  73 + allow(view).to receive(:app).and_return(problem.app)
78 74 render
79 75  
80 76 expect(action_bar).to have_selector("span a.up[href='#{app_problems_path(problem.app)}']", :text => 'up')
... ... @@ -86,8 +82,8 @@ describe &quot;problems/show.html.haml&quot; do
86 82 it 'should allow creating issue for github if application has a github tracker' do
87 83 problem = Fabricate(:problem_with_comments, app: app)
88 84 with_issue_tracker("github", problem)
89   - view.stub(:problem).and_return(problem)
90   - view.stub(:app).and_return(problem.app)
  85 + allow(view).to receive(:problem).and_return(problem)
  86 + allow(view).to receive(:app).and_return(problem.app)
91 87 render
92 88  
93 89 expect(action_bar).to have_selector("span a.github_create.create-issue", text: 'create issue')
... ... @@ -98,8 +94,6 @@ describe &quot;problems/show.html.haml&quot; do
98 94 let(:app) { App.new(:new_record => false) }
99 95  
100 96 it 'not see link to create issue' do
101   - view.stub(:problem).and_return(problem)
102   - view.stub(:app).and_return(problem.app)
103 97 render
104 98 expect(view.content_for(:action_bar)).to_not match(/create issue/)
105 99 end
... ... @@ -118,7 +112,8 @@ describe &quot;problems/show.html.haml&quot; do
118 112 before do
119 113 problem.issue_link = nil
120 114 user = Fabricate(:user, :github_login => 'test_user', :github_oauth_token => 'abcdef')
121   - controller.stub(:current_user) { user }
  115 +
  116 + allow(controller).to receive(:current_user).and_return(user)
122 117 end
123 118  
124 119 it 'links to the associated tracker' do
... ... @@ -161,13 +156,13 @@ describe &quot;problems/show.html.haml&quot; do
161 156  
162 157 describe "content_for :comments" do
163 158 before do
164   - Errbit::Config.stub(:use_gravatar).and_return(true)
  159 + problem = Fabricate(:problem_with_comments)
  160 + allow(view).to receive(:problem).and_return(problem)
  161 + allow(view).to receive(:app).and_return(problem.app)
  162 + allow(Errbit::Config).to receive(:use_gravatar).and_return(true)
165 163 end
166 164  
167 165 it 'should display comments and new comment form' do
168   - problem = Fabricate(:problem_with_comments)
169   - view.stub(:problem).and_return(problem)
170   - view.stub(:app).and_return(problem.app)
171 166 render
172 167  
173 168 expect(view.content_for(:comments)).to include('Test comment')
... ... @@ -175,9 +170,7 @@ describe &quot;problems/show.html.haml&quot; do
175 170 expect(view.content_for(:comments)).to include('Add a comment')
176 171 end
177 172  
178   - it 'should display existing comments' do
179   - problem = Fabricate(:problem_with_comments)
180   - problem.reload
  173 + it 'should display existing comments with configured tracker' do
181 174 with_issue_tracker("pivotal", problem)
182 175 render
183 176  
... ...
spec/views/problems/show.ics.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe "problems/show.html.ics" do
  1 +describe "problems/show.html.ics", type: 'view' do
4 2 let(:problem) { Fabricate(:problem) }
  3 +
5 4 before do
6   - view.stub(:problem).and_return(problem)
  5 + allow(view).to receive(:problem).and_return(problem)
7 6 end
8 7  
9 8 it 'should work' do
10 9 render :template => 'problems/show', :formats => [:ics], :handlers => [:haml]
11 10 end
12   -
13   -
14 11 end
... ...
spec/views/users/edit.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe 'users/edit.html.haml' do
  1 +describe 'users/edit.html.haml', type: 'view' do
4 2 let(:user) { stub_model(User, :name => 'shingara') }
5 3 before {
6   - view.stub(:current_user).and_return(user)
7   - view.stub(:user).and_return(user)
  4 + allow(view).to receive(:current_user).and_return(user)
  5 + allow(view).to receive(:user).and_return(user)
8 6 }
9 7 it 'should have per_page option' do
10 8 render
... ...
spec/views/users/index.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe 'users/index.html.haml' do
  1 +describe 'users/index.html.haml', type: 'view' do
4 2 let(:user) { stub_model(User) }
5 3 before {
6   - view.stub(:current_user).and_return(user)
7   - view.stub(:users).and_return(
  4 + allow(view).to receive(:current_user).and_return(user)
  5 + allow(view).to receive(:users).and_return(
8 6 Kaminari.paginate_array([user], :total_count => 1).page(1)
9 7 )
10 8 }
... ... @@ -12,5 +10,4 @@ describe &#39;users/index.html.haml&#39; do
12 10 render
13 11 expect(rendered).to match(/class='user_list'/)
14 12 end
15   -
16 13 end
... ...
spec/views/users/new.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe 'users/new.html.haml' do
  1 +describe 'users/new.html.haml', type: 'view' do
4 2 let(:user) { stub_model(User) }
5 3 before {
6   - view.stub(:current_user).and_return(user)
7   - view.stub(:user).and_return(user)
  4 + allow(view).to receive(:current_user).and_return(user)
  5 + allow(view).to receive(:user).and_return(user)
8 6 }
9 7 it 'should have per_page option' do
10 8 render
... ...
spec/views/users/show.html.haml_spec.rb
1   -require 'spec_helper'
2   -
3   -describe 'users/show.html.haml' do
4   -
  1 +describe 'users/show.html.haml', type: 'view' do
5 2 let(:user) do
6 3 stub_model(User, :created_at => Time.now, :email => "test@example.com")
7 4 end
8 5  
9 6 before do
10   - Errbit::Config.stub(:github_authentication) { true }
11   - controller.stub(:current_user) { stub_model(User) }
12   - view.stub(:user) { user }
  7 + allow(Errbit::Config).to receive(:github_authentication).and_return(true)
  8 + allow(controller).to receive(:current_user).and_return(stub_model(User))
  9 + allow(view).to receive(:user).and_return(user)
13 10 end
14 11  
15 12 context 'with GitHub authentication' do
... ... @@ -38,7 +35,7 @@ describe &#39;users/show.html.haml&#39; do
38 35  
39 36 context 'viewing own user page' do
40 37 before do
41   - controller.stub(:current_user) { user }
  38 + allow(controller).to receive(:current_user).and_return(user)
42 39 end
43 40  
44 41 it 'shows link github button when no login or token' do
... ...