Commit f89b60669f4b999083b597393d9e76ce5ca7d473

Authored by Laust Rud Jacobsen
1 parent 909cbf7d
Exists in master and in 1 other branch production

Rubocop: fix block delimiters

Based on https://github.com/bbatsov/ruby-style-guide#single-line-blocks
.rubocop_todo.yml
... ... @@ -41,12 +41,6 @@ Rails/Output:
41 41 - 'app/interactors/problem_recacher.rb'
42 42 - 'db/seeds.rb'
43 43  
44   -# Offense count: 105
45   -# Cop supports --auto-correct.
46   -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
47   -Style/BlockDelimiters:
48   - Enabled: false
49   -
50 44 # Offense count: 15
51 45 # Configuration parameters: EnforcedStyle, SupportedStyles.
52 46 Style/ClassAndModuleChildren:
... ...
app/controllers/apps_controller.rb
... ... @@ -8,9 +8,9 @@ class AppsController < ApplicationController
8 8  
9 9 expose(:app_scope) { App }
10 10  
11   - expose(:apps) {
  11 + expose(:apps) do
12 12 app_scope.all.sort.map { |app| AppDecorator.new(app) }
13   - }
  13 + end
14 14  
15 15 expose(:app, ancestor: :app_scope, attributes: :app_params)
16 16  
... ... @@ -18,11 +18,11 @@ class AppsController < ApplicationController
18 18 AppDecorator.new(app)
19 19 end
20 20  
21   - expose(:all_errs) {
  21 + expose(:all_errs) do
22 22 params[:all_errs].present?
23   - }
  23 + end
24 24  
25   - expose(:problems) {
  25 + expose(:problems) do
26 26 if request.format == :atom
27 27 app.problems.unresolved.ordered
28 28 else
... ... @@ -32,15 +32,15 @@ class AppsController < ApplicationController
32 32 params[:environment]
33 33 ).ordered_by(params_sort, params_order).page(params[:page]).per(current_user.per_page)
34 34 end
35   - }
  35 + end
36 36  
37   - expose(:deploys) {
  37 + expose(:deploys) do
38 38 app.deploys.order_by(:created_at.desc).limit(5)
39   - }
  39 + end
40 40  
41   - expose(:users) {
  41 + expose(:users) do
42 42 User.all.sort_by { |u| u.name.downcase }
43   - }
  43 + end
44 44  
45 45 def index; end
46 46  
... ...
app/controllers/problems_controller.rb
... ... @@ -11,27 +11,27 @@ class ProblemsController < ApplicationController
11 11 :resolve_several, :unresolve_several, :unmerge_several
12 12 ]
13 13  
14   - expose(:app_scope) {
  14 + expose(:app_scope) do
15 15 params[:app_id] ? App.where(_id: params[:app_id]) : App.all
16   - }
  16 + end
17 17  
18   - expose(:app) {
  18 + expose(:app) do
19 19 AppDecorator.new app_scope.find(params[:app_id])
20   - }
  20 + end
21 21  
22   - expose(:problem) {
  22 + expose(:problem) do
23 23 ProblemDecorator.new app.problems.find(params[:id])
24   - }
  24 + end
25 25  
26   - expose(:all_errs) {
  26 + expose(:all_errs) do
27 27 params[:all_errs]
28   - }
  28 + end
29 29  
30   - expose(:params_environement) {
  30 + expose(:params_environement) do
31 31 params[:environment]
32   - }
  32 + end
33 33  
34   - expose(:problems) {
  34 + expose(:problems) do
35 35 pro = Problem.
36 36 for_apps(app_scope).
37 37 in_env(params_environement).
... ... @@ -43,7 +43,7 @@ class ProblemsController < ApplicationController
43 43 else
44 44 pro
45 45 end
46   - }
  46 + end
47 47  
48 48 def index; end
49 49  
... ...
app/controllers/problems_searcher.rb
... ... @@ -5,28 +5,28 @@ module ProblemsSearcher
5 5 extend ActiveSupport::Concern
6 6  
7 7 included do
8   - expose(:params_sort) {
  8 + expose(:params_sort) do
9 9 if %w(app message last_notice_at last_deploy_at count).member?(params[:sort])
10 10 params[:sort]
11 11 else
12 12 "last_notice_at"
13 13 end
14   - }
  14 + end
15 15  
16   - expose(:params_order) {
  16 + expose(:params_order) do
17 17 if %w(asc desc).member?(params[:order])
18 18 params[:order]
19 19 else
20 20 'desc'
21 21 end
22   - }
  22 + end
23 23  
24   - expose(:selected_problems) {
  24 + expose(:selected_problems) do
25 25 Array(Problem.find(err_ids))
26   - }
  26 + end
27 27  
28   - expose(:err_ids) {
  28 + expose(:err_ids) do
29 29 (params[:problems] || []).compact
30   - }
  30 + end
31 31 end
32 32 end
... ...
app/controllers/users_controller.rb
... ... @@ -5,9 +5,9 @@ class UsersController < ApplicationController
5 5 before_action :require_user_edit_priviledges, only: [:edit, :update]
6 6  
7 7 expose(:user, attributes: :user_params)
8   - expose(:users) {
  8 + expose(:users) do
9 9 User.all.page(params[:page]).per(current_user.per_page)
10   - }
  10 + end
11 11  
12 12 def index; end
13 13 def new; end
... ...
app/helpers/application_helper.rb
... ... @@ -20,7 +20,7 @@ module ApplicationHelper
20 20 end
21 21  
22 22 def generate_ical(deploys)
23   - RiCal.Calendar { |cal|
  23 + RiCal.Calendar do |cal|
24 24 deploys.each_with_index do |deploy, idx|
25 25 cal.event do |event|
26 26 event.summary = "#{idx + 1} #{deploy.repository}"
... ... @@ -31,7 +31,7 @@ module ApplicationHelper
31 31 event.organizer = deploy.username.to_s
32 32 end
33 33 end
34   - }.to_s
  34 + end.to_s
35 35 end
36 36  
37 37 def user_agent_graph(problem)
... ...
app/interactors/problem_destroy.rb
... ... @@ -20,9 +20,9 @@ class ProblemDestroy
20 20 # the number of problem destroy
21 21 #
22 22 def self.execute(problems)
23   - Array(problems).each { |problem|
  23 + Array(problems).each do |problem|
24 24 ProblemDestroy.new(problem).execute
25   - }.count
  25 + end.count
26 26 end
27 27  
28 28 private
... ...
app/interactors/resolved_problem_clearer.rb
... ... @@ -5,14 +5,14 @@ class ResolvedProblemClearer
5 5 # Clear all problem already resolved
6 6 #
7 7 def execute
8   - nb_problem_resolved.tap { |nb|
  8 + nb_problem_resolved.tap do |nb|
9 9 if nb > 0
10 10 criteria.each do |problem|
11 11 ProblemDestroy.new(problem).execute
12 12 end
13 13 repair_database
14 14 end
15   - }
  15 + end
16 16 end
17 17  
18 18 private
... ...
config/load.rb
... ... @@ -29,9 +29,9 @@ Errbit::Config = Configurator.run(
29 29 mongo_url: %w(MONGOLAB_URI MONGOHQ_URL MONGODB_URL MONGO_URL),
30 30  
31 31 # github
32   - github_url: ['GITHUB_URL', lambda { |values|
  32 + github_url: ['GITHUB_URL', lambda do |values|
33 33 values[:github_url].gsub(%r{/*\z}, '')
34   - }],
  34 + end],
35 35 github_authentication: ['GITHUB_AUTHENTICATION'],
36 36 github_client_id: ['GITHUB_CLIENT_ID'],
37 37 github_secret: ['GITHUB_SECRET'],
... ... @@ -40,9 +40,9 @@ Errbit::Config = Configurator.run(
40 40 github_api_url: ['GITHUB_API_URL'],
41 41 github_site_title: ['GITHUB_SITE_TITLE'],
42 42  
43   - email_delivery_method: ['EMAIL_DELIVERY_METHOD', lambda { |values|
  43 + email_delivery_method: ['EMAIL_DELIVERY_METHOD', lambda do |values|
44 44 values[:email_delivery_method] && values[:email_delivery_method].to_sym
45   - }],
  45 + end],
46 46  
47 47 # smtp settings
48 48 smtp_address: ['SMTP_SERVER'],
... ... @@ -50,10 +50,10 @@ Errbit::Config = Configurator.run(
50 50 smtp_authentication: ['SMTP_AUTHENTICATION'],
51 51 smtp_user_name: %w(SMTP_USERNAME SENDGRID_USERNAME),
52 52 smtp_password: %w(SMTP_PASSWORD SENDGRID_PASSWORD),
53   - smtp_domain: ['SMTP_DOMAIN', 'SENDGRID_DOMAIN', lambda { |values|
  53 + smtp_domain: ['SMTP_DOMAIN', 'SENDGRID_DOMAIN', lambda do |values|
54 54 values[:smtp_domain] ||
55 55 (values[:email_from] && values[:email_from].split('@').last) || nil
56   - }],
  56 + end],
57 57  
58 58 # sendmail settings
59 59 sendmail_location: ['SENDMAIL_LOCATION'],
... ...
lib/tasks/errbit/demo.rake
... ... @@ -32,12 +32,13 @@ namespace :errbit do
32 32  
33 33 def random_backtrace
34 34 backtrace = []
35   - 99.times {|t|
  35 + 99.times do |t|
36 36 backtrace << {
37 37 'number' => t.hash % 1000,
38 38 'file' => "/path/to/file.rb",
39 39 'method' => RANDOM_METHODS.sample.to_s
40   - }}
  40 + }
  41 + end
41 42 backtrace
42 43 end
43 44  
... ...
spec/acceptance/app_regenerate_api_key_spec.rb
... ... @@ -3,9 +3,9 @@ require &#39;acceptance/acceptance_helper&#39;
3 3 feature "Regeneration api_Key" do
4 4 let(:app) { Fabricate(:app) }
5 5 let(:admin) { Fabricate(:admin) }
6   - let(:user) {
  6 + let(:user) do
7 7 Fabricate(:user_watcher, app: app).user
8   - }
  8 + end
9 9  
10 10 before do
11 11 app && admin
... ... @@ -16,9 +16,9 @@ feature &quot;Regeneration api_Key&quot; do
16 16 log_in admin
17 17 click_link app.name
18 18 click_link I18n.t('apps.show.edit')
19   - expect {
  19 + expect do
20 20 click_link I18n.t('apps.fields.regenerate_api_key')
21   - }.to change {
  21 + end.to change {
22 22 app.reload.api_key
23 23 }
24 24 click_link I18n.t('shared.navigation.apps')
... ... @@ -36,9 +36,9 @@ end
36 36  
37 37 feature "Create an application" do
38 38 let(:admin) { Fabricate(:admin) }
39   - let(:user) {
  39 + let(:user) do
40 40 Fabricate(:user_watcher, app: app).user
41   - }
  41 + end
42 42  
43 43 before do
44 44 admin
... ...
spec/controllers/apps_controller_spec.rb
... ... @@ -312,9 +312,9 @@ describe AppsController, type: &#39;controller&#39; do
312 312  
313 313 it "should destroy the app" do
314 314 delete :destroy, id: @app.id
315   - expect {
  315 + expect do
316 316 @app.reload
317   - }.to raise_error(Mongoid::Errors::DocumentNotFound)
  317 + end.to raise_error(Mongoid::Errors::DocumentNotFound)
318 318 end
319 319  
320 320 it "should display a message" do
... ...
spec/controllers/problems_controller_spec.rb
... ... @@ -326,10 +326,10 @@ describe ProblemsController, type: &#39;controller&#39; do
326 326 it "should unmerge a merged problem" do
327 327 merged_problem = Problem.merge!(@problem1, @problem2)
328 328 expect(merged_problem.errs.length).to eq 2
329   - expect {
  329 + expect do
330 330 post :unmerge_several, problems: [merged_problem.id.to_s]
331 331 expect(merged_problem.reload.errs.length).to eq 1
332   - }.to change(Problem, :count).by(1)
  332 + end.to change(Problem, :count).by(1)
333 333 end
334 334 end
335 335  
... ... @@ -370,9 +370,9 @@ describe ProblemsController, type: &#39;controller&#39; do
370 370  
371 371 context "POST /problems/destroy_several" do
372 372 it "should delete the problems" do
373   - expect {
  373 + expect do
374 374 post :destroy_several, problems: [@problem1.id.to_s]
375   - }.to change(Problem, :count).by(-1)
  375 + end.to change(Problem, :count).by(-1)
376 376 end
377 377 end
378 378  
... ... @@ -385,9 +385,9 @@ describe ProblemsController, type: &#39;controller&#39; do
385 385 end
386 386  
387 387 it "destroys all problems" do
388   - expect {
  388 + expect do
389 389 post :destroy_all, app_id: @app.id
390   - }.to change(Problem, :count).by(-2)
  390 + end.to change(Problem, :count).by(-2)
391 391 expect(controller.app).to eq @app
392 392 end
393 393  
... ...
spec/controllers/users_controller_spec.rb
... ... @@ -56,9 +56,9 @@ describe UsersController, type: &#39;controller&#39; do
56 56 end
57 57  
58 58 it "should not be able to become an admin" do
59   - expect {
  59 + expect do
60 60 put :update, id: user.to_param, user: { admin: true }
61   - }.to_not change {
  61 + end.to_not change {
62 62 user.reload.admin
63 63 }.from(false)
64 64 end
... ... @@ -157,9 +157,9 @@ describe UsersController, type: &#39;controller&#39; do
157 157 end
158 158  
159 159 context "when the create is unsuccessful" do
160   - let(:user) {
  160 + let(:user) do
161 161 Struct.new(:admin, :attributes).new(true, {})
162   - }
  162 + end
163 163 before do
164 164 expect(User).to receive(:new).and_return(user)
165 165 expect(user).to receive(:save).and_return(false)
... ... @@ -174,9 +174,9 @@ describe UsersController, type: &#39;controller&#39; do
174 174  
175 175 context "PUT /users/:id" do
176 176 context "when the update is successful" do
177   - before {
  177 + before do
178 178 put :update, id: user.to_param, user: user_params
179   - }
  179 + end
180 180  
181 181 context "with normal params" do
182 182 let(:user_params) { { name: 'Kermit' } }
... ... @@ -198,10 +198,10 @@ describe UsersController, type: &#39;controller&#39; do
198 198 context "with a destroy success" do
199 199 let(:user_destroy) { double(destroy: true) }
200 200  
201   - before {
  201 + before do
202 202 expect(UserDestroy).to receive(:new).with(user).and_return(user_destroy)
203 203 delete :destroy, id: user.id
204   - }
  204 + end
205 205  
206 206 it 'should destroy user' do
207 207 expect(request.flash[:success]).to eq I18n.t('controllers.users.flash.destroy.success', name: user.name)
... ... @@ -210,10 +210,10 @@ describe UsersController, type: &#39;controller&#39; do
210 210 end
211 211  
212 212 context "with trying destroy himself" do
213   - before {
  213 + before do
214 214 expect(UserDestroy).to_not receive(:new)
215 215 delete :destroy, id: admin.id
216   - }
  216 + end
217 217  
218 218 it 'should not destroy user' do
219 219 expect(response).to redirect_to(users_path)
... ... @@ -224,12 +224,12 @@ describe UsersController, type: &#39;controller&#39; do
224 224  
225 225 describe "#user_params" do
226 226 context "with current user not admin" do
227   - before {
  227 + before do
228 228 allow(controller).to receive(:current_user).and_return(user)
229 229 allow(controller).to receive(:params).and_return(
230 230 ActionController::Parameters.new(user_param)
231 231 )
232   - }
  232 + end
233 233 let(:user_param) { { 'user' => { name: 'foo', admin: true } } }
234 234 it 'not have admin field' do
235 235 expect(controller.send(:user_params)).to eq('name' => 'foo')
... ...
spec/decorators/issue_tracker_decorator_spec.rb
1 1 describe IssueTrackerDecorator do
2 2 let(:fake_tracker) do
3   - klass = Class.new(ErrbitPlugin::IssueTracker) {
  3 + klass = Class.new(ErrbitPlugin::IssueTracker) do
4 4 def self.label
5 5 'fake'
6 6 end
... ... @@ -19,7 +19,7 @@ describe IssueTrackerDecorator do
19 19 def configured?
20 20 true
21 21 end
22   - }
  22 + end
23 23 klass.new 'nothing special'
24 24 end
25 25  
... ...
spec/fabricators/app_fabricator.rb
... ... @@ -4,9 +4,9 @@ Fabricator(:app) do
4 4 end
5 5  
6 6 Fabricator(:app_with_watcher, from: :app) do
7   - watchers(count: 1) { |parent, _i|
  7 + watchers(count: 1) do |parent, _i|
8 8 Fabricate.build(:watcher, app: parent)
9   - }
  9 + end
10 10 end
11 11  
12 12 Fabricator(:watcher) do
... ...
spec/fabricators/issue_tracker_fabricator.rb
1 1 Fabricator :issue_tracker do
2 2 type_tracker 'mock'
3   - options {
  3 + options do
4 4 {
5 5 foo: 'one',
6 6 bar: 'two'
7   - }}
  7 + }
  8 + end
8 9 app
9 10 end
... ...
spec/fabricators/problem_fabricator.rb
... ... @@ -6,19 +6,19 @@ Fabricator(:problem) do
6 6 end
7 7  
8 8 Fabricator(:problem_with_comments, from: :problem) do
9   - after_create { |parent|
  9 + after_create do |parent|
10 10 3.times do
11 11 Fabricate(:comment, err: parent)
12 12 end
13   - }
  13 + end
14 14 end
15 15  
16 16 Fabricator(:problem_with_errs, from: :problem) do
17   - after_create { |parent|
  17 + after_create do |parent|
18 18 3.times do
19 19 Fabricate(:err, problem: parent)
20 20 end
21   - }
  21 + end
22 22 end
23 23  
24 24 Fabricator(:problem_resolved, from: :problem) do
... ...
spec/interactors/problem_destroy_spec.rb
1 1 describe ProblemDestroy do
2   - let(:problem_destroy) {
  2 + let(:problem_destroy) do
3 3 ProblemDestroy.new(problem)
4   - }
  4 + end
5 5  
6 6 context "in unit way" do
7   - let(:problem) {
  7 + let(:problem) do
8 8 problem = Problem.new
9 9 allow(problem).to receive(:errs).and_return(double(:criteria, only: [err_1, err_2]))
10 10 allow(problem).to receive(:comments).and_return(double(:criteria, only: [comment_1, comment_2]))
11 11 allow(problem).to receive(:delete)
12 12 problem
13   - }
  13 + end
14 14 let(:err_1) { Err.new }
15 15 let(:err_2) { Err.new }
16 16  
... ...
spec/interactors/problem_merge_spec.rb
... ... @@ -4,9 +4,9 @@ describe ProblemMerge do
4 4  
5 5 describe "#initialize" do
6 6 it 'failed if less than 2 uniq problem pass in args' do
7   - expect {
  7 + expect do
8 8 ProblemMerge.new(problem)
9   - }.to raise_error(ArgumentError)
  9 + end.to raise_error(ArgumentError)
10 10 end
11 11  
12 12 it 'extract first problem like merged_problem' do
... ... @@ -20,18 +20,18 @@ describe ProblemMerge do
20 20 end
21 21  
22 22 describe "#merge" do
23   - let!(:problem_merge) {
  23 + let!(:problem_merge) do
24 24 ProblemMerge.new(problem, problem_1)
25   - }
  25 + end
26 26 let(:first_errs) { problem.errs }
27 27 let(:merged_errs) { problem_1.errs }
28 28 let!(:notice) { Fabricate(:notice, err: first_errs.first) }
29 29 let!(:notice_1) { Fabricate(:notice, err: merged_errs.first) }
30 30  
31 31 it 'delete one of problem' do
32   - expect {
  32 + expect do
33 33 problem_merge.merge
34   - }.to change(Problem, :count).by(-1)
  34 + end.to change(Problem, :count).by(-1)
35 35 end
36 36  
37 37 it 'move all err in one problem' do
... ... @@ -55,9 +55,9 @@ describe ProblemMerge do
55 55 let!(:comment) { Fabricate(:comment, err: problem) }
56 56 let!(:comment_2) { Fabricate(:comment, err: problem_1, user: comment.user) }
57 57 it 'merge comment' do
58   - expect {
  58 + expect do
59 59 problem_merge.merge
60   - }.to change {
  60 + end.to change {
61 61 problem.comments.size
62 62 }.from(1).to(2)
63 63 expect(comment_2.reload.err).to eq problem
... ...
spec/interactors/resolved_problem_clearer_spec.rb
1 1 describe ResolvedProblemClearer do
2   - let(:resolved_problem_clearer) {
  2 + let(:resolved_problem_clearer) do
3 3 ResolvedProblemClearer.new
4   - }
  4 + end
5 5 describe "#execute" do
6   - let!(:problems) {
  6 + let!(:problems) do
7 7 [
8 8 Fabricate(:problem),
9 9 Fabricate(:problem),
10 10 Fabricate(:problem)
11 11 ]
12   - }
  12 + end
13 13 context 'without problem resolved' do
14 14 it 'do nothing' do
15   - expect {
  15 + expect do
16 16 expect(resolved_problem_clearer.execute).to eq 0
17   - }.to_not change {
  17 + end.to_not change {
18 18 Problem.count
19 19 }
20 20 end
... ... @@ -34,9 +34,9 @@ describe ResolvedProblemClearer do
34 34 end
35 35  
36 36 it 'delete problem resolve' do
37   - expect {
  37 + expect do
38 38 expect(resolved_problem_clearer.execute).to eq 2
39   - }.to change {
  39 + end.to change {
40 40 Problem.count
41 41 }.by(-2)
42 42 expect(Problem.where(_id: problems.first.id).first).to be_nil
... ...
spec/interactors/user_destroy_spec.rb
1 1 describe UserDestroy do
2   - let(:app) {
  2 + let(:app) do
3 3 Fabricate(
4 4 :app,
5 5 watchers: [
6 6 Fabricate.build(:user_watcher, user: user)
7 7 ])
8   - }
  8 + end
9 9  
10 10 describe "#destroy" do
11 11 let!(:user) { Fabricate(:user) }
12 12 it 'should delete user' do
13   - expect {
  13 + expect do
14 14 UserDestroy.new(user).destroy
15   - }.to change(User, :count)
  15 + end.to change(User, :count)
16 16 end
17 17  
18 18 it 'should delete watcher' do
19   - expect {
  19 + expect do
20 20 UserDestroy.new(user).destroy
21   - }.to change {
  21 + end.to change {
22 22 app.reload.watchers.where(user_id: user.id).count
23 23 }.from(1).to(0)
24 24 end
... ...
spec/lib/airbrake_api/v3/notice_parser_spec.rb
... ... @@ -2,13 +2,13 @@ describe AirbrakeApi::V3::NoticeParser do
2 2 let(:app) { Fabricate(:app) }
3 3  
4 4 it 'raises error when errors attribute is missing' do
5   - expect {
  5 + expect do
6 6 AirbrakeApi::V3::NoticeParser.new({}).report
7   - }.to raise_error(AirbrakeApi::ParamsError)
  7 + end.to raise_error(AirbrakeApi::ParamsError)
8 8  
9   - expect {
  9 + expect do
10 10 AirbrakeApi::V3::NoticeParser.new('errors' => []).report
11   - }.to raise_error(AirbrakeApi::ParamsError)
  11 + end.to raise_error(AirbrakeApi::ParamsError)
12 12 end
13 13  
14 14 it 'parses JSON payload and returns ErrorReport' do
... ...
spec/models/app_spec.rb
... ... @@ -164,13 +164,13 @@ describe App, type: &#39;model&#39; do
164 164  
165 165 context '#find_or_create_err!' do
166 166 let(:app) { Fabricate(:app) }
167   - let(:conditions) {
  167 + let(:conditions) do
168 168 {
169 169 error_class: 'Whoops',
170 170 environment: 'production',
171 171 fingerprint: 'some-finger-print'
172 172 }
173   - }
  173 + end
174 174  
175 175 it 'returns the correct err if one already exists' do
176 176 existing = Fabricate(
... ... @@ -188,23 +188,23 @@ describe App, type: &#39;model&#39; do
188 188  
189 189 it 'creates a new problem if a matching one does not already exist' do
190 190 expect(Err.where(conditions).first).to be_nil
191   - expect {
  191 + expect do
192 192 app.find_or_create_err!(conditions)
193   - }.to change(Problem, :count).by(1)
  193 + end.to change(Problem, :count).by(1)
194 194 end
195 195  
196 196 context "without error_class" do
197   - let(:conditions) {
  197 + let(:conditions) do
198 198 {
199 199 environment: 'production',
200 200 fingerprint: 'some-finger-print'
201 201 }
202   - }
  202 + end
203 203 it 'save the err' do
204 204 expect(Err.where(conditions).first).to be_nil
205   - expect {
  205 + expect do
206 206 app.find_or_create_err!(conditions)
207   - }.to change(Problem, :count).by(1)
  207 + end.to change(Problem, :count).by(1)
208 208 end
209 209 end
210 210 end
... ... @@ -215,9 +215,9 @@ describe App, type: &#39;model&#39; do
215 215 expect(App.find_by_api_key!(app.api_key)).to eq app
216 216 end
217 217 it 'raise Mongoid::Errors::DocumentNotFound if not found' do
218   - expect {
  218 + expect do
219 219 App.find_by_api_key!('foo')
220   - }.to raise_error(Mongoid::Errors::DocumentNotFound)
  220 + end.to raise_error(Mongoid::Errors::DocumentNotFound)
221 221 end
222 222 end
223 223 end
... ...
spec/models/error_report_spec.rb
... ... @@ -17,18 +17,18 @@ module Airbrake
17 17 end
18 18  
19 19 describe ErrorReport do
20   - let(:xml) {
  20 + let(:xml) do
21 21 Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice.xml').read
22   - }
  22 + end
23 23  
24 24 let(:error_report) { ErrorReport.new(xml) }
25 25  
26   - let!(:app) {
  26 + let!(:app) do
27 27 Fabricate(
28 28 :app,
29 29 api_key: 'APIKEY'
30 30 )
31   - }
  31 + end
32 32  
33 33 describe "#app" do
34 34 it 'find the good app' do
... ... @@ -44,39 +44,39 @@ describe ErrorReport do
44 44  
45 45 describe "#generate_notice!" do
46 46 it "save a notice" do
47   - expect {
  47 + expect do
48 48 error_report.generate_notice!
49   - }.to change {
  49 + end.to change {
50 50 app.reload.problems.count
51 51 }.by(1)
52 52 end
53 53  
54 54 context "with a minimal notice" do
55   - let(:xml) {
  55 + let(:xml) do
56 56 Rails.root.join('spec', 'fixtures', 'minimal_test_notice.xml').read
57   - }
  57 + end
58 58  
59 59 it 'save a notice' do
60   - expect {
  60 + expect do
61 61 error_report.generate_notice!
62   - }.to change {
  62 + end.to change {
63 63 app.reload.problems.count
64 64 }.by(1)
65 65 end
66 66 end
67 67  
68 68 context "with notice generate by Airbrake gem" do
69   - let(:xml) {
  69 + let(:xml) do
70 70 Airbrake::Notice.new(
71 71 exception: Exception.new,
72 72 api_key: 'APIKEY',
73 73 project_root: Rails.root
74 74 ).to_xml
75   - }
  75 + end
76 76 it 'save a notice' do
77   - expect {
  77 + expect do
78 78 error_report.generate_notice!
79   - }.to change {
  79 + end.to change {
80 80 app.reload.problems.count
81 81 }.by(1)
82 82 end
... ... @@ -201,10 +201,10 @@ describe ErrorReport do
201 201 end
202 202  
203 203 it 'memoize the notice' do
204   - expect {
  204 + expect do
205 205 error_report.generate_notice!
206 206 error_report.generate_notice!
207   - }.to change {
  207 + end.to change {
208 208 Notice.count
209 209 }.by(1)
210 210 end
... ... @@ -213,9 +213,9 @@ describe ErrorReport do
213 213 error_report.generate_notice!
214 214 error_report.problem.resolve!
215 215  
216   - expect {
  216 + expect do
217 217 ErrorReport.new(xml).generate_notice!
218   - }.to change {
  218 + end.to change {
219 219 error_report.problem.reload.resolved?
220 220 }.from(true).to(false)
221 221 end
... ... @@ -237,26 +237,26 @@ describe ErrorReport do
237 237 end
238 238  
239 239 context "with xml without request section" do
240   - let(:xml) {
  240 + let(:xml) do
241 241 Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice_without_request_section.xml').read
242   - }
  242 + end
243 243 it "save a notice" do
244   - expect {
  244 + expect do
245 245 error_report.generate_notice!
246   - }.to change {
  246 + end.to change {
247 247 app.reload.problems.count
248 248 }.by(1)
249 249 end
250 250 end
251 251  
252 252 context "with xml with only a single line of backtrace" do
253   - let(:xml) {
  253 + let(:xml) do
254 254 Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice_with_one_line_of_backtrace.xml').read
255   - }
  255 + end
256 256 it "save a notice" do
257   - expect {
  257 + expect do
258 258 error_report.generate_notice!
259   - }.to change {
  259 + end.to change {
260 260 app.reload.problems.count
261 261 }.by(1)
262 262 end
... ...
spec/models/problem_spec.rb
... ... @@ -10,25 +10,25 @@ describe Problem, type: &#39;model&#39; do
10 10 describe "Fabrication" do
11 11 context "Fabricate(:problem)" do
12 12 it 'should have no comment' do
13   - expect {
  13 + expect do
14 14 Fabricate(:problem)
15   - }.to_not change(Comment, :count)
  15 + end.to_not change(Comment, :count)
16 16 end
17 17 end
18 18  
19 19 context "Fabricate(:problem_with_comments)" do
20 20 it 'should have 3 comments' do
21   - expect {
  21 + expect do
22 22 Fabricate(:problem_with_comments)
23   - }.to change(Comment, :count).by(3)
  23 + end.to change(Comment, :count).by(3)
24 24 end
25 25 end
26 26  
27 27 context "Fabricate(:problem_with_errs)" do
28 28 it 'should have 3 errs' do
29   - expect {
  29 + expect do
30 30 Fabricate(:problem_with_errs)
31   - }.to change(Err, :count).by(3)
  31 + end.to change(Err, :count).by(3)
32 32 end
33 33 end
34 34 end
... ... @@ -65,9 +65,9 @@ describe Problem, type: &#39;model&#39; do
65 65 it "adding a notice caches its message" do
66 66 err = Fabricate(:err)
67 67 problem = err.problem
68   - expect {
  68 + expect do
69 69 Fabricate(:notice, err: err, message: 'ERR 1')
70   - }.to change(problem, :message).from(nil).to('ERR 1')
  70 + end.to change(problem, :message).from(nil).to('ERR 1')
71 71 end
72 72 end
73 73  
... ... @@ -132,9 +132,9 @@ describe Problem, type: &#39;model&#39; do
132 132 er.add_on_blank(:resolved)
133 133 allow(problem).to receive(:errors).and_return(er)
134 134 expect(problem).to_not be_valid
135   - expect {
  135 + expect do
136 136 problem.resolve!
137   - }.to raise_error(Mongoid::Errors::Validations)
  137 + end.to raise_error(Mongoid::Errors::Validations)
138 138 end
139 139 end
140 140  
... ... @@ -201,17 +201,17 @@ describe Problem, type: &#39;model&#39; do
201 201 end
202 202  
203 203 it "adding a notice increases #notices_count by 1" do
204   - expect {
  204 + expect do
205 205 Fabricate(:notice, err: @err, message: 'ERR 1')
206   - }.to change(@problem.reload, :notices_count).from(0).to(1)
  206 + end.to change(@problem.reload, :notices_count).from(0).to(1)
207 207 end
208 208  
209 209 it "removing a notice decreases #notices_count by 1" do
210 210 Fabricate(:notice, err: @err, message: 'ERR 1')
211   - expect {
  211 + expect do
212 212 @err.notices.first.destroy
213 213 @problem.reload
214   - }.to change(@problem, :notices_count).from(1).to(0)
  214 + end.to change(@problem, :notices_count).from(1).to(0)
215 215 end
216 216 end
217 217  
... ... @@ -226,10 +226,10 @@ describe Problem, type: &#39;model&#39; do
226 226 end
227 227  
228 228 it "is updated when an app is updated" do
229   - expect {
  229 + expect do
230 230 app.update_attributes!(name: "Bar App")
231 231 problem.reload
232   - }.to change(problem, :app_name).to("Bar App")
  232 + end.to change(problem, :app_name).to("Bar App")
233 233 end
234 234 end
235 235  
... ... @@ -248,10 +248,10 @@ describe Problem, type: &#39;model&#39; do
248 248 it "is updated when a deploy is created" do
249 249 problem = Fabricate(:problem, app: @app, environment: "production")
250 250 next_deploy = 5.minutes.ago
251   - expect {
  251 + expect do
252 252 @deploy = Fabricate(:deploy, app: @app, created_at: next_deploy)
253 253 problem.reload
254   - }.to change { problem.last_deploy_at.iso8601 }.
  254 + end.to change { problem.last_deploy_at.iso8601 }.
255 255 from(@last_deploy.iso8601).
256 256 to(next_deploy.iso8601)
257 257 end
... ... @@ -270,10 +270,10 @@ describe Problem, type: &#39;model&#39; do
270 270  
271 271 it "removing a notice removes string from #messages" do
272 272 Fabricate(:notice, err: @err, message: 'ERR 1')
273   - expect {
  273 + expect do
274 274 @err.notices.first.destroy
275 275 @problem.reload
276   - }.to change(@problem, :messages).from(Digest::MD5.hexdigest('ERR 1') => { 'value' => 'ERR 1', 'count' => 1 }).to({})
  276 + end.to change(@problem, :messages).from(Digest::MD5.hexdigest('ERR 1') => { 'value' => 'ERR 1', 'count' => 1 }).to({})
277 277 end
278 278  
279 279 it "removing a notice from the problem with broken counter should not raise an error" do
... ... @@ -297,10 +297,10 @@ describe Problem, type: &#39;model&#39; do
297 297  
298 298 it "removing a notice removes string from #hosts" do
299 299 Fabricate(:notice, err: @err, request: { 'url' => "http://example.com/resource/12" })
300   - expect {
  300 + expect do
301 301 @err.notices.first.destroy
302 302 @problem.reload
303   - }.to change(@problem, :hosts).from(Digest::MD5.hexdigest('example.com') => { 'value' => 'example.com', 'count' => 1 }).to({})
  303 + end.to change(@problem, :hosts).from(Digest::MD5.hexdigest('example.com') => { 'value' => 'example.com', 'count' => 1 }).to({})
304 304 end
305 305 end
306 306  
... ... @@ -325,10 +325,10 @@ describe Problem, type: &#39;model&#39; do
325 325 }
326 326 }
327 327 )
328   - expect {
  328 + expect do
329 329 @err.notices.first.destroy
330 330 @problem.reload
331   - }.to change(@problem, :user_agents).
  331 + end.to change(@problem, :user_agents).
332 332 from(
333 333 Digest::MD5.hexdigest('Chrome 10.0.648.204 (OS X 10.6.7)') => {
334 334 'value' => 'Chrome 10.0.648.204 (OS X 10.6.7)', 'count' => 1 }
... ... @@ -347,17 +347,17 @@ describe Problem, type: &#39;model&#39; do
347 347 end
348 348  
349 349 it "adding a comment increases #comments_count by 1" do
350   - expect {
  350 + expect do
351 351 Fabricate(:comment, err: @problem)
352   - }.to change(@problem, :comments_count).from(0).to(1)
  352 + end.to change(@problem, :comments_count).from(0).to(1)
353 353 end
354 354  
355 355 it "removing a comment decreases #comments_count by 1" do
356 356 Fabricate(:comment, err: @problem)
357   - expect {
  357 + expect do
358 358 @problem.reload.comments.first.destroy
359 359 @problem.reload
360   - }.to change(@problem, :comments_count).from(1).to(0)
  360 + end.to change(@problem, :comments_count).from(1).to(0)
361 361 end
362 362 end
363 363  
... ... @@ -420,9 +420,9 @@ describe Problem, type: &#39;model&#39; do
420 420 end
421 421  
422 422 it 'update the notice_count' do
423   - expect {
  423 + expect do
424 424 problem.recache
425   - }.to change {
  425 + end.to change {
426 426 problem.notices_count
427 427 }.from(0).to(1)
428 428 end
... ...
spec/models/user_spec.rb
... ... @@ -39,10 +39,10 @@ describe User do
39 39  
40 40 context "First user" do
41 41 it "should be created this admin access via db:seed" do
42   - expect {
  42 + expect do
43 43 allow($stdout).to receive(:puts).and_return(true)
44 44 require Rails.root.join('db/seeds.rb')
45   - }.to change {
  45 + end.to change {
46 46 User.where(admin: true).count
47 47 }.from(0).to(1)
48 48 end
... ...
spec/requests/notices_controller_spec.rb
... ... @@ -5,10 +5,10 @@ describe &quot;Notices management&quot;, type: &#39;request&#39; do
5 5 context "with valide notice" do
6 6 let(:xml) { Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice.xml').read }
7 7 it 'save a new notice' do
8   - expect {
  8 + expect do
9 9 post '/notifier_api/v2/notices', data: xml
10 10 expect(response).to be_success
11   - }.to change {
  11 + end.to change {
12 12 errbit_app.problems.count
13 13 }.by(1)
14 14 end
... ... @@ -17,10 +17,10 @@ describe &quot;Notices management&quot;, type: &#39;request&#39; do
17 17 context "with notice with empty backtrace" do
18 18 let(:xml) { Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice_without_line_of_backtrace.xml').read }
19 19 it 'save a new notice' do
20   - expect {
  20 + expect do
21 21 post '/notifier_api/v2/notices', data: xml
22 22 expect(response).to be_success
23   - }.to change {
  23 + end.to change {
24 24 errbit_app.problems.count
25 25 }.by(1)
26 26 end
... ... @@ -30,21 +30,21 @@ describe &quot;Notices management&quot;, type: &#39;request&#39; do
30 30 let(:errbit_app) { Fabricate(:app) }
31 31 let(:xml) { Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice.xml').read }
32 32 it 'not save a new notice and return 422' do
33   - expect {
  33 + expect do
34 34 post '/notifier_api/v2/notices', data: xml
35 35 expect(response.status).to eq 422
36 36 expect(response.body).to eq "Your API key is unknown"
37   - }.to_not change(errbit_app.problems, :count)
  37 + end.to_not change(errbit_app.problems, :count)
38 38 end
39 39 end
40 40  
41 41 context "with GET request" do
42 42 let(:xml) { Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice.xml').read }
43 43 it 'save a new notice' do
44   - expect {
  44 + expect do
45 45 get '/notifier_api/v2/notices', data: xml
46 46 expect(response).to be_success
47   - }.to change {
  47 + end.to change {
48 48 errbit_app.problems.count
49 49 }.by(1)
50 50 end
... ...
spec/views/apps/edit.html.haml_spec.rb
... ... @@ -35,11 +35,11 @@ describe &quot;apps/edit.html.haml&quot;, type: &#39;view&#39; do
35 35 end
36 36  
37 37 context "with unvalid app" do
38   - let(:app) {
  38 + let(:app) do
39 39 app = stub_model(App)
40 40 app.errors.add(:base, 'You must specify your')
41 41 app
42   - }
  42 + end
43 43  
44 44 it 'see the error' do
45 45 render
... ...
spec/views/apps/new.html.haml_spec.rb
... ... @@ -21,11 +21,11 @@ describe &quot;apps/new.html.haml&quot;, type: &#39;view&#39; do
21 21 end
22 22  
23 23 context "with unvalid app" do
24   - let(:app) {
  24 + let(:app) do
25 25 app = stub_model(App)
26 26 app.errors.add(:base, 'You must specify your')
27 27 app
28   - }
  28 + end
29 29  
30 30 it 'see the error' do
31 31 render
... ...
spec/views/issue_trackers/issue.md.erb_spec.rb
1 1 describe "issue_trackers/issue.md.erb", type: 'view' do
2   - let(:problem) {
  2 + let(:problem) do
3 3 problem = Fabricate(:problem)
4 4 Fabricate(:notice, err: Fabricate(:err, problem: problem))
5 5 problem
6   - }
  6 + end
7 7  
8 8 before do
9 9 allow(view).to receive(:problem).and_return(ProblemDecorator.new(problem))
... ...
spec/views/issue_trackers/issue.txt.erb_spec.rb
1 1 describe "issue_trackers/issue.txt.erb", type: 'view' do
2   - let(:problem) {
  2 + let(:problem) do
3 3 problem = Fabricate(:problem)
4 4 Fabricate(:notice, err: Fabricate(:err, problem: problem))
5 5 problem
6   - }
  6 + end
7 7  
8 8 before do
9 9 allow(view).to receive(:problem).and_return(
... ...
spec/views/problems/show.html.haml_spec.rb
1 1 describe "problems/show.html.haml", type: 'view' do
2 2 let(:problem) { Fabricate(:problem) }
3 3 let(:comment) { Fabricate(:comment) }
4   - let(:pivotal_tracker) {
  4 + let(:pivotal_tracker) do
5 5 Class.new(ErrbitPlugin::MockIssueTracker) do
6 6 def self.label
7 7 'pivotal'
... ... @@ -15,8 +15,8 @@ describe &quot;problems/show.html.haml&quot;, type: &#39;view&#39; do
15 15 true
16 16 end
17 17 end
18   - }
19   - let(:github_tracker) {
  18 + end
  19 + let(:github_tracker) do
20 20 Class.new(ErrbitPlugin::MockIssueTracker) do
21 21 def self.label
22 22 'github'
... ... @@ -30,13 +30,13 @@ describe &quot;problems/show.html.haml&quot;, type: &#39;view&#39; do
30 30 true
31 31 end
32 32 end
33   - }
34   - let(:trackers) {
  33 + end
  34 + let(:trackers) do
35 35 {
36 36 'github' => github_tracker,
37 37 'pivotal' => pivotal_tracker
38 38 }
39   - }
  39 + end
40 40 let(:app) { AppDecorator.new(problem.app) }
41 41  
42 42 before do
... ...
spec/views/users/edit.html.haml_spec.rb
1 1 describe 'users/edit.html.haml', type: 'view' do
2 2 let(:user) { stub_model(User, name: 'shingara') }
3   - before {
  3 + before do
4 4 allow(view).to receive(:current_user).and_return(user)
5 5 allow(view).to receive(:user).and_return(user)
6   - }
  6 + end
7 7 it 'should have per_page option' do
8 8 render
9 9 expect(rendered).to match(/id="user_per_page"/)
... ...
spec/views/users/index.html.haml_spec.rb
1 1 describe 'users/index.html.haml', type: 'view' do
2 2 let(:user) { stub_model(User) }
3   - before {
  3 + before do
4 4 allow(view).to receive(:current_user).and_return(user)
5 5 allow(view).to receive(:users).and_return(
6 6 Kaminari.paginate_array([user], total_count: 1).page(1)
7 7 )
8   - }
  8 + end
9 9 it 'should see users option' do
10 10 render
11 11 expect(rendered).to match(/class='user_list'/)
... ...
spec/views/users/new.html.haml_spec.rb
1 1 describe 'users/new.html.haml', type: 'view' do
2 2 let(:user) { stub_model(User) }
3   - before {
  3 + before do
4 4 allow(view).to receive(:current_user).and_return(user)
5 5 allow(view).to receive(:user).and_return(user)
6   - }
  6 + end
7 7 it 'should have per_page option' do
8 8 render
9 9 expect(rendered).to match(/id="user_per_page"/)
... ...