diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/.travis.yml b/.travis.yml index c20722a..8bcfc97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ rvm: - ruby-head env: - - COVERAGE=true + - RAILS_ENV=test COVERAGE=true sudo: false @@ -15,7 +15,8 @@ cache: bundler services: mongodb -script: bundle exec rake errbit:bootstrap spec +before_script: bundle exec rake errbit:bootstrap +script: bundle exec rspec matrix: allow_failures: diff --git a/Gemfile b/Gemfile index 62f7696..4ea6a99 100644 --- a/Gemfile +++ b/Gemfile @@ -56,8 +56,7 @@ gem 'yajl-ruby', :require => "yajl" group :development, :test do gem 'airbrake', :require => false gem 'pry-rails' -# gem 'rpm_contrib' -# gem 'newrelic_rpm' + gem 'pry-byebug', platforms: [:mri] gem 'quiet_assets' end @@ -75,7 +74,10 @@ group :development do end group :test do - gem 'rspec-rails', require: false + gem 'rspec' + gem 'rspec-rails', '~> 3.0', require: false + gem 'rspec-activemodel-mocks' + gem 'rspec-its' gem 'mongoid-rspec', require: false gem 'fabrication' gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 8ea3100..44aeb2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) - addressable (2.3.5) + addressable (2.3.6) airbrake (3.1.14) builder json @@ -58,6 +58,9 @@ GEM debug_inspector (>= 0.0.1) bson (2.3.0) builder (3.2.2) + byebug (2.7.0) + columnize (~> 0.3) + debugger-linecache (~> 1.2) callsite (0.0.11) campy (1.0.0) capistrano (3.3.5) @@ -75,7 +78,7 @@ GEM capistrano (~> 3.1) sshkit (~> 1.3) capistrano-stats (1.1.1) - capybara (2.1.0) + capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) @@ -91,6 +94,7 @@ GEM execjs coffee-script-source (1.8.0) colorize (0.7.5) + columnize (0.9.0) connection_pool (2.1.0) coveralls (0.7.0) multi_json (~> 1.3) @@ -102,6 +106,7 @@ GEM addressable database_cleaner (1.2.0) debug_inspector (0.0.2) + debugger-linecache (1.2.0) decent_exposure (2.3.2) devise (3.4.1) bcrypt (~> 3.0) @@ -110,14 +115,14 @@ GEM responders thread_safe (~> 0.1) warden (~> 1.2.3) - diff-lcs (1.2.4) + diff-lcs (1.2.5) dotenv (0.9.0) - draper (1.3.0) + draper (1.4.0) actionpack (>= 3.0) activemodel (>= 3.0) activesupport (>= 3.0) - request_store (~> 1.0.3) - email_spec (1.5.0) + request_store (~> 1.0) + email_spec (1.6.0) launchy (~> 2.1) mail (~> 2.2) erubis (2.7.0) @@ -152,14 +157,14 @@ GEM jquery-rails (2.1.4) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - json (1.8.1) + json (1.8.2) jwt (0.1.8) multi_json (>= 1.5) kaminari (0.14.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) kgio (2.9.2) - launchy (2.3.0) + launchy (2.4.3) addressable (~> 2.3) mail (2.6.3) mime-types (>= 1.16, < 3) @@ -169,23 +174,23 @@ GEM railties method_source (0.8.2) mime-types (1.25.1) - mini_portile (0.6.1) - minitest (5.5.0) + mini_portile (0.6.2) + minitest (5.5.1) mongoid (4.0.0) activemodel (~> 4.0) moped (~> 2.0.0) origin (~> 2.1) tzinfo (>= 0.3.37) - mongoid-rspec (1.9.0) - mongoid (>= 3.0.1) + mongoid-rspec (2.0.0) + mongoid (~> 4.0.0) rake - rspec (>= 2.14) + rspec (~> 3.1) mongoid_rails_migrations (1.0.1) activesupport (>= 3.2.0) bundler (>= 1.0.0) rails (>= 3.2.0) railties (>= 3.2.0) - moped (2.0.2) + moped (2.0.3) bson (~> 2.2) connection_pool (~> 2.0) optionable (~> 0.2.0) @@ -195,7 +200,7 @@ GEM net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (2.9.1) - nokogiri (1.6.4.1) + nokogiri (1.6.5) mini_portile (~> 0.6.0) oauth2 (0.8.1) faraday (~> 0.8) @@ -232,6 +237,9 @@ GEM coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) + pry-byebug (1.3.2) + byebug (~> 2.7) + pry (~> 0.9.12) pry-rails (0.3.2) pry (>= 0.9.10) quiet_assets (1.0.2) @@ -242,7 +250,7 @@ GEM rack-ssl (1.4.0) rack rack-ssl-enforcer (0.2.6) - rack-test (0.6.2) + rack-test (0.6.3) rack (>= 1.0) rails (4.1.8) actionmailer (= 4.1.8) @@ -265,28 +273,40 @@ GEM rake (10.4.2) rdoc (4.1.2) json (~> 1.4) - request_store (1.0.6) + request_store (1.1.0) responders (1.1.2) railties (>= 3.2, < 4.2) rest-client (1.6.8) mime-types (~> 1.16) rdoc (>= 2.4.2) ri_cal (0.8.8) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.6) - rspec-expectations (2.14.3) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.4) - rspec-rails (2.14.0) + rspec (3.1.0) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-activemodel-mocks (1.0.1) + activemodel (>= 3.0) + activesupport (>= 3.0) + rspec-mocks (>= 2.99, < 4.0) + rspec-core (3.1.7) + rspec-support (~> 3.1.0) + rspec-expectations (3.1.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.1.0) + rspec-its (1.1.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.1.3) + rspec-support (~> 3.1.0) + rspec-rails (3.1.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-support (~> 3.1.0) + rspec-support (3.1.2) rushover (0.3.0) json rest-client @@ -340,7 +360,9 @@ GEM useragent (0.9.0) warden (1.2.3) rack (>= 1.0) - websocket-driver (0.3.3) + websocket-driver (0.5.1) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.1) xmpp4r (0.5.5) xpath (2.0.0) nokogiri (~> 1.3) @@ -391,6 +413,7 @@ DEPENDENCIES omniauth-github pjax_rails poltergeist + pry-byebug pry-rails quiet_assets rack-ssl @@ -398,7 +421,10 @@ DEPENDENCIES rails_autolink railties (~> 4.1.8) ri_cal - rspec-rails + rspec + rspec-activemodel-mocks + rspec-its + rspec-rails (~> 3.0) rushover sass-rails test-unit diff --git a/spec/acceptance/acceptance_helper.rb b/spec/acceptance/acceptance_helper.rb index 1d8c1c5..30321d2 100644 --- a/spec/acceptance/acceptance_helper.rb +++ b/spec/acceptance/acceptance_helper.rb @@ -1,4 +1,3 @@ -require 'spec_helper' require 'capybara/rspec' require 'capybara/poltergeist' diff --git a/spec/acceptance/sign_in_with_github_spec.rb b/spec/acceptance/sign_in_with_github_spec.rb index e4002f6..6e77700 100644 --- a/spec/acceptance/sign_in_with_github_spec.rb +++ b/spec/acceptance/sign_in_with_github_spec.rb @@ -3,7 +3,7 @@ require 'acceptance/acceptance_helper' feature 'Sign in with GitHub' do background do - Errbit::Config.stub(:github_authentication) { true } + allow(Errbit::Config).to receive(:github_authentication).and_return(true) Fabricate(:user, :github_login => 'nashby') end diff --git a/spec/controllers/api/v1/notices_controller_spec.rb b/spec/controllers/api/v1/notices_controller_spec.rb index 759bd92..9d0c3a4 100644 --- a/spec/controllers/api/v1/notices_controller_spec.rb +++ b/spec/controllers/api/v1/notices_controller_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe Api::V1::NoticesController do - +describe Api::V1::NoticesController, type: 'controller' do context "when logged in" do before do @user = Fabricate(:user) @@ -50,5 +47,4 @@ describe Api::V1::NoticesController do end end - end diff --git a/spec/controllers/api/v1/problems_controller_spec.rb b/spec/controllers/api/v1/problems_controller_spec.rb index 03a5b0e..2cb1ade 100644 --- a/spec/controllers/api/v1/problems_controller_spec.rb +++ b/spec/controllers/api/v1/problems_controller_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe Api::V1::ProblemsController do - +describe Api::V1::ProblemsController, type: 'controller' do context "when logged in" do before do @user = Fabricate(:user) @@ -69,8 +66,6 @@ describe Api::V1::ProblemsController do Fabricate(:problem, :first_notice_at => Date.new(2012, 8, 30)) end - - it "should return JSON if JSON is requested" do get :index, :auth_token => @user.authentication_token, :format => "json" expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError) @@ -86,17 +81,13 @@ describe Api::V1::ProblemsController do expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError) end - - describe "given a date range" do - it "should return only the problems open during the date range" do get :index, {:auth_token => @user.authentication_token, :start_date => "2012-08-20", :end_date => "2012-08-27"} expect(response).to be_success problems = JSON.load response.body expect(problems.length).to eq 2 end - end it "should return all problems" do @@ -105,8 +96,6 @@ describe Api::V1::ProblemsController do problems = JSON.load response.body expect(problems.length).to eq 4 end - end end - end diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index 77d53ba..f839181 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe AppsController do - +describe AppsController, type: 'controller' do it_requires_authentication it_requires_admin_privileges :for => {:new => :get, :edit => :get, :create => :post, :update => :put, :destroy => :delete} @@ -218,7 +215,7 @@ describe AppsController do describe "POST /apps" do before do @app = Fabricate(:app) - App.stub(:new).and_return(@app) + allow(App).to receive(:new).and_return(@app) end context "when the create is successful" do diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 02c7b92..3ee17e8 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe CommentsController do +describe CommentsController, type: 'controller' do let(:app) { Fabricate(:app) } let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :app => app, :environment => "production")) } diff --git a/spec/controllers/deploys_controller_spec.rb b/spec/controllers/deploys_controller_spec.rb index e56129c..7937fa6 100644 --- a/spec/controllers/deploys_controller_spec.rb +++ b/spec/controllers/deploys_controller_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe DeploysController do +describe DeploysController, type: 'controller' do render_views context 'POST #create' do @@ -21,7 +19,7 @@ describe DeploysController do end it 'creates a deploy' do - App.stub(:find_by_api_key!).and_return(@app) + expect(App).to receive(:find_by_api_key!).and_return(@app) expect(@app.deploys).to receive(:create!). with({ :username => 'john.doe', @@ -40,7 +38,6 @@ describe DeploysController do expect(email.to).to include(@app.watchers.first.email) expect(email.subject).to eq "[#{@app.name}] Deployed to production by john.doe" end - end context "GET #index" do @@ -59,6 +56,4 @@ describe DeploysController do expect(response.body).to match(@deploy.app.name) end end - end - diff --git a/spec/controllers/devise_sessions_controller_spec.rb b/spec/controllers/devise_sessions_controller_spec.rb index 64dc2fe..7ff91e7 100644 --- a/spec/controllers/devise_sessions_controller_spec.rb +++ b/spec/controllers/devise_sessions_controller_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Devise::SessionsController do +describe Devise::SessionsController, type: 'controller' do render_views describe "POST /users/sign_in" do @@ -23,4 +21,3 @@ describe Devise::SessionsController do end end end - diff --git a/spec/controllers/notices_controller_spec.rb b/spec/controllers/notices_controller_spec.rb index 8effa42..7646555 100644 --- a/spec/controllers/notices_controller_spec.rb +++ b/spec/controllers/notices_controller_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe NoticesController do +describe NoticesController, type: 'controller' do it_requires_authentication :for => { :locate => :get } let(:notice) { Fabricate(:notice) } @@ -78,6 +76,4 @@ describe NoticesController do end end end - end - diff --git a/spec/controllers/problems_controller_spec.rb b/spec/controllers/problems_controller_spec.rb index f125415..24f86d0 100644 --- a/spec/controllers/problems_controller_spec.rb +++ b/spec/controllers/problems_controller_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe ProblemsController do - +describe ProblemsController, type: 'controller' do it_requires_authentication :for => { :index => :get, :show => :get, :resolve => :put, :search => :get }, @@ -218,38 +215,35 @@ describe ProblemsController do before do sign_in admin - @problem = Fabricate(:err) - App.stub(:find).with(@problem.app.id.to_s).and_return(@problem.app) - @problem.app.problems.stub(:find).and_return(@problem.problem) - @problem.problem.stub(:resolve!) + @err = Fabricate(:err) end - it 'finds the app and the problem' do - expect(App).to receive(:find).with(@problem.app.id.to_s).and_return(@problem.app) - expect(@problem.app.problems).to receive(:find).and_return(@problem.problem) - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id - expect(controller.app).to eq @problem.app - expect(controller.problem).to eq @problem.problem + it 'finds the app and the err' do + expect(App).to receive(:find).with(@err.app.id.to_s).and_return(@err.app) + expect(@err.app.problems).to receive(:find).and_return(@err.problem) + put :resolve, :app_id => @err.app.id, :id => @err.problem.id + expect(controller.app).to eq @err.app + expect(controller.problem).to eq @err.problem end it "should resolve the issue" do - expect(@problem.problem).to receive(:resolve!).and_return(true) - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id + put :resolve, :app_id => @err.app.id, :id => @err.problem.id + expect(@err.problem.reload.resolved).to be(true) end it "should display a message" do - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id + put :resolve, :app_id => @err.app.id, :id => @err.problem.id expect(request.flash[:success]).to match(/Great news/) end it "should redirect to the app page" do - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id - expect(response).to redirect_to(app_path(@problem.app)) + put :resolve, :app_id => @err.app.id, :id => @err.problem.id + expect(response).to redirect_to(app_path(@err.app)) end it "should redirect back to problems page" do request.env["HTTP_REFERER"] = problems_path - put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id + put :resolve, :app_id => @err.app.id, :id => @err.problem.id expect(response).to redirect_to(problems_path) end end @@ -268,8 +262,8 @@ describe ProblemsController do before do problem.app.issue_tracker = issue_tracker - controller.stub(:problem).and_return(problem) - controller.stub(:current_user).and_return(admin) + allow(controller).to receive(:problem).and_return(problem) + allow(controller).to receive(:current_user).and_return(admin) end it "should redirect to problem page" do @@ -461,7 +455,5 @@ describe ProblemsController do expect(response).to redirect_to(edit_app_path(@app)) end end - end - end diff --git a/spec/controllers/users/omniauth_callbacks_controller_spec.rb b/spec/controllers/users/omniauth_callbacks_controller_spec.rb index 9337177..84ec87b 100644 --- a/spec/controllers/users/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/users/omniauth_callbacks_controller_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe Users::OmniauthCallbacksController do - +describe Users::OmniauthCallbacksController, type: 'controller' do def stub_env_for_github_omniauth(login, token = nil) # This a Devise specific thing for functional tests. See https://github.com/plataformatec/devise/issues/closed#issue/608 request.env["devise.mapping"] = Devise.mappings[:user] @@ -12,7 +9,7 @@ describe Users::OmniauthCallbacksController do :credentials => { :token => token } ) } - @controller.stub(:env).and_return(env) + allow(@controller).to receive(:env).and_return(env) end context 'Linking a GitHub account to a signed in user' do diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 1d91c4a..f9aa899 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe UsersController do - +describe UsersController, type: 'controller' do it_requires_authentication it_requires_admin_privileges :for => { :index => :get, @@ -16,7 +13,6 @@ describe UsersController do let(:other_user) { Fabricate(:user) } context 'Signed in as a regular user' do - before do sign_in user end @@ -104,16 +100,12 @@ describe UsersController do end context "GET /users" do - it 'paginates all users' do admin.update_attribute :per_page, 2 - users = 3.times { - Fabricate(:user) - } + 3.times { Fabricate(:user) } get :index expect(controller.users.to_a.size).to eq 2 end - end context "GET /users/:id" do @@ -140,7 +132,7 @@ describe UsersController do context "POST /users" do context "when the create is successful" do - let(:attrs) { {:user => Fabricate.attributes_for(:user)} } + let(:attrs) { {:user => Fabricate.to_params(:user)} } it "sets a message to display" do post :create, attrs @@ -156,7 +148,7 @@ describe UsersController do attrs[:user][:admin] = true post :create, attrs expect(response).to be_redirect - expect(User.find(controller.user.to_param).admin).to be_true + expect(User.find(controller.user.to_param).admin).to be(true) end it "should has auth token" do @@ -205,7 +197,6 @@ describe UsersController do end context "DELETE /users/:id" do - context "with a destroy success" do let(:user_destroy) { double(:destroy => true) } @@ -236,8 +227,10 @@ describe UsersController do describe "#user_params" do context "with current user not admin" do before { - controller.stub(:current_user).and_return(user) - controller.stub(:params).and_return(ActionController::Parameters.new(user_param)) + allow(controller).to receive(:current_user).and_return(user) + allow(controller).to receive(:params).and_return( + ActionController::Parameters.new(user_param) + ) } let(:user_param) { {'user' => { :name => 'foo', :admin => true }} } it 'not have admin field' do @@ -261,7 +254,5 @@ describe UsersController do end end end - end - end diff --git a/spec/controllers/watchers_controller_spec.rb b/spec/controllers/watchers_controller_spec.rb index b77b4ab..f0545fb 100644 --- a/spec/controllers/watchers_controller_spec.rb +++ b/spec/controllers/watchers_controller_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe WatchersController do +describe WatchersController, type: 'controller' do let(:app) do a = Fabricate(:app) Fabricate(:user_watcher, :app => a) @@ -8,7 +6,6 @@ describe WatchersController do end describe "DELETE /apps/:app_id/watchers/:id/destroy" do - context "with admin user" do before(:each) do sign_in Fabricate(:admin) diff --git a/spec/decorators/app_decorator_spec.rb b/spec/decorators/app_decorator_spec.rb index 6418f9f..f317983 100644 --- a/spec/decorators/app_decorator_spec.rb +++ b/spec/decorators/app_decorator_spec.rb @@ -1,17 +1,11 @@ -require 'spec_helper' - describe AppDecorator do - describe "#email_at_notices" do - it 'return the list separate by comma' do expect(AppDecorator.new(double(:email_at_notices => [2,3])).email_at_notices).to eql '2, 3' end - end describe "#notify_user_display" do - it 'return display:none if notify' do expect(AppDecorator.new(double(:notify_all_users => true)).notify_user_display).to eql 'display: none;' end @@ -19,11 +13,9 @@ describe AppDecorator do it 'return blank if no notify' do expect(AppDecorator.new(double(:notify_all_users => false)).notify_user_display).to eql '' end - end describe "#notify_err_display" do - it 'return display:none if no notify' do expect(AppDecorator.new(double(:notify_on_errs => false)).notify_err_display).to eql 'display: none;' end @@ -31,7 +23,5 @@ describe AppDecorator do it 'return blank if no notify' do expect(AppDecorator.new(double(:notify_on_errs => true)).notify_err_display).to eql '' end - end - end diff --git a/spec/decorators/issue_tracker_decorator_spec.rb b/spec/decorators/issue_tracker_decorator_spec.rb index 72a58b8..315c3bc 100644 --- a/spec/decorators/issue_tracker_decorator_spec.rb +++ b/spec/decorators/issue_tracker_decorator_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe IssueTrackerDecorator do let(:fake_tracker) do Class.new(ErrbitPlugin::IssueTracker) do diff --git a/spec/decorators/issue_tracker_field_decorator.rb b/spec/decorators/issue_tracker_field_decorator.rb index 8307fc2..e9476ad 100644 --- a/spec/decorators/issue_tracker_field_decorator.rb +++ b/spec/decorators/issue_tracker_field_decorator.rb @@ -1,14 +1,11 @@ -require 'spec_helper' - describe IssueTrackerFieldDecorator do - describe "#label" do it 'return the label of field_info by default' do expect(IssueTrackerFieldDecorator.new(:foo, {:label => 'hello'}).label).to eq 'hello' end + it 'return the key of field if no label define' do expect(IssueTrackerFieldDecorator.new(:foo, {}).label).to eq 'foo' end end - end diff --git a/spec/decorators/watcher_decorator_spec.rb b/spec/decorators/watcher_decorator_spec.rb index 6abaa6a..1983363 100644 --- a/spec/decorators/watcher_decorator_spec.rb +++ b/spec/decorators/watcher_decorator_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe WatcherDecorator do describe "#email_choosen" do context "with email define" do diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 25c1666..ca5d063 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' # Specs in this file have access to a helper object that includes # the AbcHelper. For example: diff --git a/spec/helpers/backtrace_line_helper.rb b/spec/helpers/backtrace_line_helper.rb index f09de7c..45ab917 100644 --- a/spec/helpers/backtrace_line_helper.rb +++ b/spec/helpers/backtrace_line_helper.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe BacktraceLineHelper do describe "in app lines" do let(:notice) do diff --git a/spec/helpers/navigation_helper_spec.rb b/spec/helpers/navigation_helper_spec.rb index ff35528..716ec16 100644 --- a/spec/helpers/navigation_helper_spec.rb +++ b/spec/helpers/navigation_helper_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe NavigationHelper do describe '#page_count_from_end' do it 'returns the page number when counting from the last occurrence of a notice' do diff --git a/spec/helpers/problems_helper_spec.rb b/spec/helpers/problems_helper_spec.rb index cb46e03..bbb86b6 100644 --- a/spec/helpers/problems_helper_spec.rb +++ b/spec/helpers/problems_helper_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe ProblemsHelper do describe '#truncated_problem_message' do it 'is html safe' do @@ -24,8 +22,8 @@ describe ProblemsHelper do context "default config" do before do - Errbit::Config.stub(:use_gravatar).and_return(true) - Errbit::Config.stub(:gravatar_default).and_return('identicon') + allow(Errbit::Config).to receive(:use_gravatar).and_return(true) + allow(Errbit::Config).to receive(:gravatar_default).and_return('identicon') end it "should render image_tag with correct alt and src" do @@ -69,7 +67,7 @@ describe ProblemsHelper do let(:email_hash) { Digest::MD5.hexdigest email } it "should return the http url" do - ActionController::TestRequest.any_instance.stub :ssl? => true + allow(controller.request).to receive(:ssl?).and_return(true) expect(helper.gravatar_url(email)).to eq("https://secure.gravatar.com/avatar/#{email_hash}?d=identicon") end end diff --git a/spec/interactors/problem_destroy_spec.rb b/spec/interactors/problem_destroy_spec.rb index 6d128af..2f7bfb3 100644 --- a/spec/interactors/problem_destroy_spec.rb +++ b/spec/interactors/problem_destroy_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe ProblemDestroy do let(:problem_destroy) { ProblemDestroy.new(problem) @@ -8,9 +6,9 @@ describe ProblemDestroy do context "in unit way" do let(:problem) { problem = Problem.new - problem.stub(:errs).and_return(double(:criteria, :only => [err_1, err_2])) - problem.stub(:comments).and_return(double(:criteria, :only => [comment_1, comment_2])) - problem.stub(:delete) + allow(problem).to receive(:errs).and_return(double(:criteria, :only => [err_1, err_2])) + allow(problem).to receive(:comments).and_return(double(:criteria, :only => [comment_1, comment_2])) + allow(problem).to receive(:delete) problem } let(:err_1) { Err.new } @@ -73,5 +71,4 @@ describe ProblemDestroy do expect(Notice.where(:_id => notice_2_2.id).entries).to be_empty end end - end diff --git a/spec/interactors/problem_merge_spec.rb b/spec/interactors/problem_merge_spec.rb index 6da3964..9dcf653 100644 --- a/spec/interactors/problem_merge_spec.rb +++ b/spec/interactors/problem_merge_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe ProblemMerge do let(:problem) { Fabricate(:problem_with_errs) } let(:problem_1) { Fabricate(:problem_with_errs) } diff --git a/spec/interactors/problem_updater_cache_spec.rb b/spec/interactors/problem_updater_cache_spec.rb index 679a95b..5b56166 100644 --- a/spec/interactors/problem_updater_cache_spec.rb +++ b/spec/interactors/problem_updater_cache_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe ProblemUpdaterCache do let(:problem) { Fabricate(:problem_with_errs) } let(:first_errs) { problem.errs } diff --git a/spec/interactors/resolved_problem_clearer_spec.rb b/spec/interactors/resolved_problem_clearer_spec.rb index 983812f..5738b12 100644 --- a/spec/interactors/resolved_problem_clearer_spec.rb +++ b/spec/interactors/resolved_problem_clearer_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe ResolvedProblemClearer do let(:resolved_problem_clearer) { ResolvedProblemClearer.new @@ -21,7 +19,7 @@ describe ResolvedProblemClearer do } end it 'not repair database' do - Mongoid.default_session.stub(:command).and_call_original + allow(Mongoid.default_session).to receive(:command).and_call_original expect(Mongoid.default_session).to_not receive(:command).with({:repairDatabase => 1}) resolved_problem_clearer.execute end @@ -29,8 +27,8 @@ describe ResolvedProblemClearer do context "with problem resolve" do before do - Mongoid.default_session.stub(:command).and_call_original - Mongoid.default_session.stub(:command).with({:repairDatabase => 1}) + allow(Mongoid.default_session).to receive(:command).and_call_original + allow(Mongoid.default_session).to receive(:command).with({:repairDatabase => 1}) problems.first.resolve! problems.second.resolve! end @@ -46,7 +44,6 @@ describe ResolvedProblemClearer do end it 'repair database' do - Mongoid.default_session.stub(:command).and_call_original expect(Mongoid.default_session).to receive(:command).with({:repairDatabase => 1}) resolved_problem_clearer.execute end diff --git a/spec/interactors/user_destroy_spec.rb b/spec/interactors/user_destroy_spec.rb index 3b10c8c..b3f9025 100644 --- a/spec/interactors/user_destroy_spec.rb +++ b/spec/interactors/user_destroy_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe UserDestroy do let(:app) { Fabricate( :app, diff --git a/spec/mailers/mailer_spec.rb b/spec/mailers/mailer_spec.rb index cf8fe18..c0d2798 100644 --- a/spec/mailers/mailer_spec.rb +++ b/spec/mailers/mailer_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - shared_examples "a notification email" do it "should have X-Mailer header" do expect(@email).to have_header('X-Mailer', 'Errbit') @@ -36,6 +34,7 @@ describe Mailer do let!(:user) { Fabricate(:admin) } before do + ActionMailer::Base.deliveries = [] notice.backtrace.lines.last.update_attributes(:file => "[PROJECT_ROOT]/path/to/file.js") notice.app.update_attributes( :asset_host => "http://example.com", @@ -78,12 +77,12 @@ describe Mailer do include EmailSpec::Matchers let!(:notice) { Fabricate(:notice) } - let!(:comment) { Fabricate.build(:comment, :err => notice.problem) } + let!(:comment) { Fabricate(:comment, :err => notice.problem) } let!(:watcher) { Fabricate(:watcher, :app => comment.app) } let(:recipients) { ['recipient@example.com', 'another@example.com']} before do - comment.stub(:notification_recipients).and_return(recipients) + expect(comment).to receive(:notification_recipients).and_return(recipients) Fabricate(:notice, :err => notice.err) @email = Mailer.comment_notification(comment).deliver end diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index 983dd32..7420f42 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe App do - +describe App, type: 'model' do context "Attributes" do it { should have_field(:_id).of_type(String) } it { should have_field(:name).of_type(String) } @@ -112,12 +109,12 @@ describe App do context '#github_repo?' do it 'is true when there is a github_repo' do app = Fabricate(:app, :github_repo => "errbit/errbit") - expect(app.github_repo?).to be_true + expect(app.github_repo?).to be(true) end it 'is false when no github_repo' do app = Fabricate(:app) - expect(app.github_repo?).to be_false + expect(app.github_repo?).to be(false) end end @@ -137,19 +134,19 @@ describe App do it "should be true if notify on errs and there are notification recipients" do app = Fabricate(:app, :notify_on_errs => true, :notify_all_users => false) 2.times { Fabricate(:watcher, :app => app) } - expect(app.emailable?).to be_true + expect(app.emailable?).to be(true) end it "should be false if notify on errs is disabled" do app = Fabricate(:app, :notify_on_errs => false, :notify_all_users => false) 2.times { Fabricate(:watcher, :app => app) } - expect(app.emailable?).to be_false + expect(app.emailable?).to be(false) end it "should be false if there are no notification recipients" do app = Fabricate(:app, :notify_on_errs => true, :notify_all_users => false) expect(app.watchers).to be_empty - expect(app.emailable?).to be_false + expect(app.emailable?).to be(false) end end diff --git a/spec/models/backtrace_line_normalizer_spec.rb b/spec/models/backtrace_line_normalizer_spec.rb index 0a1ab86..b3cd6ad 100644 --- a/spec/models/backtrace_line_normalizer_spec.rb +++ b/spec/models/backtrace_line_normalizer_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe BacktraceLineNormalizer do +describe BacktraceLineNormalizer, type: 'model' do subject { described_class.new(raw_line).call } describe "sanitize" do diff --git a/spec/models/backtrace_line_spec.rb b/spec/models/backtrace_line_spec.rb index 736a9ab..197b5cf 100644 --- a/spec/models/backtrace_line_spec.rb +++ b/spec/models/backtrace_line_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe BacktraceLine do +describe BacktraceLine, type: 'model' do subject { described_class.new(raw_line) } describe "root at the start of decorated filename" do diff --git a/spec/models/backtrace_spec.rb b/spec/models/backtrace_spec.rb index cdad627..1d93853 100644 --- a/spec/models/backtrace_spec.rb +++ b/spec/models/backtrace_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Backtrace do +describe Backtrace, type: 'model' do subject { described_class.new } its(:fingerprint) { should be_present } @@ -19,7 +17,7 @@ describe Backtrace do } let(:fingerprint) { "fingerprint" } - before { subject.stub(:fingerprint => fingerprint) } + before { allow(subject).to receive(:fingerprint).and_return(fingerprint) } its(:similar) { should == similar_backtrace } end @@ -30,10 +28,10 @@ describe Backtrace do let(:attributes) { double :attributes } let(:backtrace) { double :backtrace } - before { described_class.stub(:new => backtrace) } + before { allow(described_class).to receive(:new).and_return(backtrace) } context "no similar backtrace" do - before { backtrace.stub(:similar => nil) } + before { allow(backtrace).to receive(:similar).and_return(nil) } it "create new backtrace" do expect(described_class).to receive(:create).with(attributes) @@ -43,7 +41,7 @@ describe Backtrace do context "similar backtrace exist" do let(:similar_backtrace) { double :similar_backtrace } - before { backtrace.stub(:similar => similar_backtrace) } + before { allow(backtrace).to receive(:similar).and_return(similar_backtrace) } it { should == similar_backtrace } end diff --git a/spec/models/comment_observer_spec.rb b/spec/models/comment_observer_spec.rb index 4082822..bbf6621 100644 --- a/spec/models/comment_observer_spec.rb +++ b/spec/models/comment_observer_spec.rb @@ -1,11 +1,9 @@ -require 'spec_helper' - -describe "Callback on Comment" do +describe "Callback on Comment", type: 'model' do context 'when a Comment is saved' do let(:comment) { Fabricate.build(:comment) } context 'and it is emailable?' do - before { comment.stub(:emailable?).and_return(true) } + before { allow(comment).to receive(:emailable?).and_return(true) } it 'should send an email notification' do expect(Mailer).to receive(:comment_notification). @@ -16,7 +14,7 @@ describe "Callback on Comment" do end context 'and it is not emailable?' do - before { comment.stub(:emailable?).and_return(false) } + before { allow(comment).to receive(:emailable?).and_return(false) } it 'should not send an email notification' do expect(Mailer).to_not receive(:comment_notification) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 9cfffe1..8ad3fb4 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Comment do +describe Comment, type: 'model' do context 'validations' do it 'should require a body' do comment = Fabricate.build(:comment, :body => nil) @@ -37,19 +35,19 @@ describe Comment do end it 'should be true if app is emailable? and there are notification recipients' do - expect(comment.emailable?).to be_true + expect(comment.emailable?).to be(true) end it 'should be false if app is not emailable?' do app.update_attribute(:notify_on_errs, false) expect(comment.notification_recipients).to be_any - expect(comment.emailable?).to be_false + expect(comment.emailable?).to be(false) end it 'should be false if there are no notification recipients' do watcher.destroy - expect(app.emailable?).to be_true - expect(comment.emailable?).to be_false + expect(app.emailable?).to be(true) + expect(comment.emailable?).to be(false) end end end diff --git a/spec/models/deploy_observer_spec.rb b/spec/models/deploy_observer_spec.rb index 7972275..e7b6a54 100644 --- a/spec/models/deploy_observer_spec.rb +++ b/spec/models/deploy_observer_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe "Callback on Deploy" do +describe "Callback on Deploy", type: 'model' do context 'when a Deploy is saved' do context 'and the app should notify on deploys' do it 'should send an email notification' do diff --git a/spec/models/deploy_spec.rb b/spec/models/deploy_spec.rb index 856fd70..b6f329f 100644 --- a/spec/models/deploy_spec.rb +++ b/spec/models/deploy_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe Deploy do - +describe Deploy, type: 'model' do context 'validations' do it 'requires a username' do deploy = Fabricate.build(:deploy, :username => nil) @@ -36,7 +33,6 @@ describe Deploy do expect(@staging_errs.all?{|problem| problem.reload.resolved?}).to eq false end end - end it "should produce a shortened revision with 7 characters" do diff --git a/spec/models/err_spec.rb b/spec/models/err_spec.rb index 383ad16..07a7351 100644 --- a/spec/models/err_spec.rb +++ b/spec/models/err_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe Err do - +describe Err, type: 'model' do context 'validations' do it 'requires a fingerprint' do err = Fabricate.build(:err, :fingerprint => nil) @@ -15,5 +12,4 @@ describe Err do expect(err.errors[:problem_id]).to include("can't be blank") end end - end diff --git a/spec/models/error_report_spec.rb b/spec/models/error_report_spec.rb index f8237bd..de4d243 100644 --- a/spec/models/error_report_spec.rb +++ b/spec/models/error_report_spec.rb @@ -1,4 +1,3 @@ -require 'spec_helper' require 'airbrake/version' require 'airbrake/backtrace' require 'airbrake/notice' @@ -41,22 +40,22 @@ describe ErrorReport do end describe "#backtrace" do - it 'should have valid backtrace' do expect(error_report.backtrace).to be_valid end end describe "#fingerprint_strategy" do - after(:all) { - error_report.fingerprint_strategy = Fingerprint::Sha1 - } - it "should be possible to change how fingerprints are generated" do - strategy = double() - strategy.should_receive(:generate){ 'fingerprints' } - error_report.fingerprint_strategy = strategy - error_report.generate_notice! + def error_report.fingerprint_strategy + Class.new do + def self.generate(*args) + 'fingerprintzzz' + end + end + end + + expect(error_report.error.fingerprint).to eq('fingerprintzzz') end end @@ -68,6 +67,7 @@ describe ErrorReport do app.reload.problems.count }.by(1) end + context "with notice generate by Airbrake gem" do let(:xml) { Airbrake::Notice.new( :exception => Exception.new, @@ -112,73 +112,74 @@ describe ErrorReport do expect(subject.user_attributes['email']).to eq 'mr.bean@example.com' expect(subject.user_attributes['username']).to eq 'mrbean' end + it 'valid env_vars' do - # XML: - expect(subject.env_vars).to have_key('SCRIPT_NAME') - expect(subject.env_vars['SCRIPT_NAME']).to be_nil # blank ends up nil - - # XML representation: - # - # false - # true - # / - # - # - # - # - expected = { - 'secure' => 'false', - 'httponly' => 'true', - 'path' => '/', - 'expire_after' => nil, - 'domain' => nil, - 'id' => nil - } - expect(subject.env_vars).to have_key('rack_session_options') - expect(subject.env_vars['rack_session_options']).to eql(expected) - end + # XML: + expect(subject.env_vars).to have_key('SCRIPT_NAME') + expect(subject.env_vars['SCRIPT_NAME']).to be_nil # blank ends up nil + + # XML representation: + # + # false + # true + # / + # + # + # + # + expected = { + 'secure' => 'false', + 'httponly' => 'true', + 'path' => '/', + 'expire_after' => nil, + 'domain' => nil, + 'id' => nil + } + expect(subject.env_vars).to have_key('rack_session_options') + expect(subject.env_vars['rack_session_options']).to eql(expected) + end end + end + + it 'save a notice assignes to err' do + error_report.generate_notice! + expect(error_report.notice.err).to be_a(Err) + end - it 'save a notice assignes to err' do + it 'memoize the notice' do + expect { error_report.generate_notice! - expect(error_report.notice.err).to be_a(Err) - end + error_report.generate_notice! + }.to change { + Notice.count + }.by(1) + end - it 'memoize the notice' do - expect { - error_report.generate_notice! - error_report.generate_notice! - }.to change { - Notice.count - }.by(1) - end + it 'find the correct err for the notice' do + err = Fabricate(:err, :problem => Fabricate(:problem, :resolved => true)) - it 'find the correct err for the notice' do - err = Fabricate(:err, :problem => Fabricate(:problem, :resolved => true)) + allow(error_report).to receive(:fingerprint).and_return(err.fingerprint) - ErrorReport.any_instance.stub(:fingerprint).and_return(err.fingerprint) + expect { + error_report.generate_notice! + }.to change { + error_report.error.resolved? + }.from(true).to(false) + end - expect { - error_report.generate_notice! - }.to change { - error_report.error.resolved? - }.from(true).to(false) + context "with notification service configured" do + before do + app.notify_on_errs = true + app.watchers.build(:email => 'foo@example.com') + app.save end - - context "with notification service configured" do - before do - app.notify_on_errs = true - app.watchers.build(:email => 'foo@example.com') - app.save - end - it 'send email' do - notice = error_report.generate_notice! - email = ActionMailer::Base.deliveries.last - expect(email.to).to include(app.watchers.first.email) - expect(email.subject).to include(notice.message.truncate(50)) - expect(email.subject).to include("[#{app.name}]") - expect(email.subject).to include("[#{notice.environment_name}]") - end + it 'send email' do + notice = error_report.generate_notice! + email = ActionMailer::Base.deliveries.last + expect(email.to).to include(app.watchers.first.email) + expect(email.subject).to include(notice.message.truncate(50)) + expect(email.subject).to include("[#{app.name}]") + expect(email.subject).to include("[#{notice.environment_name}]") end context "with xml without request section" do @@ -270,8 +271,6 @@ describe ErrorReport do expect(error_report.should_keep?).to be false end end - end - end end diff --git a/spec/models/fabricators_spec.rb b/spec/models/fabricators_spec.rb index 9cf15ec..b06f091 100644 --- a/spec/models/fabricators_spec.rb +++ b/spec/models/fabricators_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - Fabrication::Config.fabricator_path.each do |folder| Dir.glob(File.join(Rails.root, folder, '**', '*.rb')).each do |file| require file diff --git a/spec/models/fingerprint/md5_spec.rb b/spec/models/fingerprint/md5_spec.rb index 63599be..3209de5 100644 --- a/spec/models/fingerprint/md5_spec.rb +++ b/spec/models/fingerprint/md5_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Fingerprint::MD5 do +describe Fingerprint::MD5, type: 'model' do context 'being created' do let(:backtrace) do Backtrace.create(:raw => [ diff --git a/spec/models/fingerprint/sha1_spec.rb b/spec/models/fingerprint/sha1_spec.rb index be834a9..fb06fb5 100644 --- a/spec/models/fingerprint/sha1_spec.rb +++ b/spec/models/fingerprint/sha1_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe Fingerprint::Sha1 do - +describe Fingerprint::Sha1, type: 'model' do context '#generate' do let(:backtrace) { Backtrace.create(:raw => [ @@ -80,8 +77,5 @@ describe Fingerprint::Sha1 do should eq "# #" end end - end - end - diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index c3a9c53..1fd3f9e 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -1,7 +1,4 @@ -require "spec_helper" - -describe Issue do - +describe Issue, type: 'model' do subject(:issue) { Issue.new(problem: problem, user: user, title: title, body: body) } let(:problem) { notice.problem } @@ -33,15 +30,13 @@ describe Issue do context "when has no title" do let(:body) { "barrr" } - pending "returns an error" do - end + pending "returns an error" end context "when has no body" do let(:title) { "Foo" } - pending "returns an error" do - end + pending "returns an error" end context "when app has a issue tracker" do diff --git a/spec/models/issue_tracker_spec.rb b/spec/models/issue_tracker_spec.rb index 4b046fe..3f56db7 100644 --- a/spec/models/issue_tracker_spec.rb +++ b/spec/models/issue_tracker_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe IssueTracker do +describe IssueTracker, type: 'model' do describe "Association" do it { should be_embedded_in(:app) } end diff --git a/spec/models/notice_observer_spec.rb b/spec/models/notice_observer_spec.rb index 97c2e75..1db584e 100644 --- a/spec/models/notice_observer_spec.rb +++ b/spec/models/notice_observer_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe "Callback on Notice" do +describe "Callback on Notice", type: 'model' do describe "email notifications (configured individually for each app)" do custom_thresholds = [2, 4, 8, 16, 32, 64] @@ -24,7 +22,6 @@ describe "Callback on Notice" do end end - describe "email notifications for a resolved issue" do before do Errbit::Config.per_app_email_at_notices = true diff --git a/spec/models/notice_spec.rb b/spec/models/notice_spec.rb index 97076ef..a3bacdb 100644 --- a/spec/models/notice_spec.rb +++ b/spec/models/notice_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Notice do +describe Notice, type: 'model' do context 'validations' do it 'requires a backtrace' do notice = Fabricate.build(:notice, :backtrace => nil) diff --git a/spec/models/notification_service/campfire_service_spec.rb b/spec/models/notification_service/campfire_service_spec.rb index 524a7b6..e0ef6fa 100644 --- a/spec/models/notification_service/campfire_service_spec.rb +++ b/spec/models/notification_service/campfire_service_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe NotificationService::CampfireService do +describe NotificationService::CampfireService, type: 'model' do it "it should send a notification to campfire" do # setup notice = Fabricate :notice @@ -9,8 +7,8 @@ describe NotificationService::CampfireService do #campy stubbing campy = double('CampfireService') - Campy::Room.stub(:new).and_return(campy) - campy.stub(:speak) { true } + allow(Campy::Room).to receive(:new).and_return(campy) + allow(campy).to receive(:speak).and_return(true) #assert expect(campy).to receive(:speak) @@ -18,4 +16,3 @@ describe NotificationService::CampfireService do notification_service.create_notification(problem) end end - diff --git a/spec/models/notification_service/flowdock_service_spec.rb b/spec/models/notification_service/flowdock_service_spec.rb index 54f252b..b77ab7a 100644 --- a/spec/models/notification_service/flowdock_service_spec.rb +++ b/spec/models/notification_service/flowdock_service_spec.rb @@ -1,17 +1,15 @@ -require 'spec_helper' - -describe NotificationServices::FlowdockService do +describe NotificationServices::FlowdockService, type: 'model' do let(:service) { Fabricate.build(:flowdock_notification_service) } let(:app) { Fabricate(:app, :name => 'App #3') } let(:problem) { Fabricate(:problem, :app => app, :message => '<3') } it 'sends message in appropriate format' do - Flowdock::Flow.any_instance.should_receive(:push_to_team_inbox) do |*args| - expect(args.first[:content]).to_not include('<3') - expect(args.first[:content]).to include('<3') - - expect(args.first[:project]).to eq('App3') + allow_any_instance_of(Flowdock::Flow).to receive(:push_to_team_inbox) do |*args| + expect(args[1][:content]).to_not include('<3') + expect(args[1][:content]).to include('<3') + expect(args[1][:project]).to eq('App3') end + service.create_notification(problem) end end diff --git a/spec/models/notification_service/gtalk_service_spec.rb b/spec/models/notification_service/gtalk_service_spec.rb index 08d0d9a..8420bff 100644 --- a/spec/models/notification_service/gtalk_service_spec.rb +++ b/spec/models/notification_service/gtalk_service_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe NotificationService::GtalkService do +describe NotificationService::GtalkService, type: 'model' do it "it should send a notification to gtalk" do # setup notice = Fabricate :notice @@ -47,8 +45,8 @@ describe NotificationService::GtalkService do expect(@gtalk).to receive(:connect) expect(@gtalk).to receive(:auth) jid = double("jid") - Jabber::JID.stub(:new).with(@notification_service.subdomain).and_return(jid) - Jabber::Client.stub(:new).with(jid).and_return(@gtalk) + allow(Jabber::JID).to receive(:new).with(@notification_service.subdomain).and_return(jid) + allow(Jabber::Client).to receive(:new).with(jid).and_return(@gtalk) end it "should send a notification to all ',' separated users" do expect(Jabber::Message).to receive(:new).with("first@domain.org", @error_msg) @@ -120,6 +118,4 @@ describe NotificationService::GtalkService do notification_service.create_notification(problem) end - end - diff --git a/spec/models/notification_service/hipchat_service_spec.rb b/spec/models/notification_service/hipchat_service_spec.rb index ebbce32..df5150e 100644 --- a/spec/models/notification_service/hipchat_service_spec.rb +++ b/spec/models/notification_service/hipchat_service_spec.rb @@ -1,12 +1,10 @@ -require 'spec_helper' - -describe NotificationServices::HipchatService do +describe NotificationServices::HipchatService, type: 'model' do let(:service) { Fabricate.build(:hipchat_notification_service) } let(:problem) { Fabricate(:problem) } let(:room) { double } before do - HipChat::Client.any_instance.stub(:[] => room) + allow_any_instance_of(HipChat::Client).to receive(:[]).and_return(room) end it 'sends message' do @@ -15,7 +13,7 @@ describe NotificationServices::HipchatService do end it 'escapes html in message' do - problem.stub(:message => '<3') + allow(problem).to receive(:message).and_return('<3') expect(room).to receive(:send) do |_, message| expect(message).to_not include('<3') expect(message).to include('<3') diff --git a/spec/models/notification_service/hoiio_service_spec.rb b/spec/models/notification_service/hoiio_service_spec.rb index 7959a75..869bad8 100644 --- a/spec/models/notification_service/hoiio_service_spec.rb +++ b/spec/models/notification_service/hoiio_service_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe NotificationService::HoiioService do +describe NotificationService::HoiioService, type: 'model' do it "it should send a notification to hoiio" do # setup notice = Fabricate :notice @@ -9,8 +7,8 @@ describe NotificationService::HoiioService do # hoi stubbing sms = double('HoiioService') - Hoi::SMS.stub(:new).and_return(sms) - sms.stub(:send) { true } + allow(Hoi::SMS).to receive(:new).and_return(sms) + allow(sms).to receive(:send).and_return(true) #assert expect(sms).to receive(:send) @@ -18,4 +16,3 @@ describe NotificationService::HoiioService do notification_service.create_notification(problem) end end - diff --git a/spec/models/notification_service/hubot_service_spec.rb b/spec/models/notification_service/hubot_service_spec.rb index 229a85e..3ee5c6f 100644 --- a/spec/models/notification_service/hubot_service_spec.rb +++ b/spec/models/notification_service/hubot_service_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe NotificationService::HubotService do +describe NotificationService::HubotService, type: 'model' do it "it should send a notification to Hubot" do # setup notice = Fabricate :notice diff --git a/spec/models/notification_service/notification_service_spec.rb b/spec/models/notification_service/notification_service_spec.rb index 4c04723..c9fb3bf 100644 --- a/spec/models/notification_service/notification_service_spec.rb +++ b/spec/models/notification_service/notification_service_spec.rb @@ -1,18 +1,15 @@ -require 'spec_helper' - -describe NotificationService do +describe NotificationService, type: 'model' do let(:notice) { Fabricate :notice } let(:notification_service) { Fabricate :notification_service, :app => notice.app } let(:problem) { notice.problem } it "it should use http by default in #problem_url" do - notification_service.problem_url(problem).should start_with 'http://' + expect(notification_service.problem_url(problem)).to start_with 'http://' end it "it should use the protocol value specified in the config in #problem_url" do Errbit::Config.protocol = 'https' - notification_service.problem_url(problem).should start_with 'https://' + expect(notification_service.problem_url(problem)).to start_with 'https://' end - end diff --git a/spec/models/notification_service/pushover_service_spec.rb b/spec/models/notification_service/pushover_service_spec.rb index 4e2ae9c..32be10b 100644 --- a/spec/models/notification_service/pushover_service_spec.rb +++ b/spec/models/notification_service/pushover_service_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe NotificationService::PushoverService do +describe NotificationService::PushoverService, type: 'model' do it "it should send a notification to Pushover" do # setup notice = Fabricate :notice @@ -9,8 +7,8 @@ describe NotificationService::PushoverService do # hoi stubbing notification = double('PushoverService') - Rushover::Client.stub(:new).and_return(notification) - notification.stub(:notify) { true } + allow(Rushover::Client).to receive(:new).and_return(notification) + allow(notification).to receive(:notify).and_return(true) #assert expect(notification).to receive(:notify) diff --git a/spec/models/notification_service/slack_service_spec.rb b/spec/models/notification_service/slack_service_spec.rb index 07c7c27..e512ae8 100644 --- a/spec/models/notification_service/slack_service_spec.rb +++ b/spec/models/notification_service/slack_service_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe NotificationService::SlackService do +describe NotificationService::SlackService, type: 'model' do it "it should send a notification to Slack with channel" do # setup notice = Fabricate :notice diff --git a/spec/models/notification_service/webhook_service_spec.rb b/spec/models/notification_service/webhook_service_spec.rb index 045d805..ce73b8a 100644 --- a/spec/models/notification_service/webhook_service_spec.rb +++ b/spec/models/notification_service/webhook_service_spec.rb @@ -1,11 +1,9 @@ -require 'spec_helper' - -describe NotificationService::WebhookService do +describe NotificationService::WebhookService, type: 'model' do it "it should send a notification to a user-specified URL" do notice = Fabricate :notice notification_service = Fabricate :webhook_notification_service, :app => notice.app problem = notice.problem - + expect(HTTParty).to receive(:post).with(notification_service.api_token, :body => {:problem => problem.to_json}).and_return(true) notification_service.create_notification(problem) diff --git a/spec/models/problem_spec.rb b/spec/models/problem_spec.rb index 3b0f134..dd092e5 100644 --- a/spec/models/problem_spec.rb +++ b/spec/models/problem_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe Problem do - +describe Problem, type: 'model' do context 'validations' do it 'requires an environment' do err = Fabricate.build(:problem, :environment => nil) @@ -59,7 +56,7 @@ describe Problem do notice1 = Fabricate(:notice, :err => err) expect(problem.first_notice_at.to_i).to be_within(1).of(notice1.created_at.to_i) - notice2 = Fabricate(:notice, :err => err) + Fabricate(:notice, :err => err) expect(problem.first_notice_at.to_i).to be_within(1).of(notice1.created_at.to_i) end end @@ -128,12 +125,12 @@ describe Problem do it "should throw an err if it's not successful" do problem = Fabricate(:problem) expect(problem).to_not be_resolved - problem.stub(:valid?).and_return(false) + allow(problem).to receive(:valid?).and_return(false) ## update_attributes not test #valid? but #errors.any? # https://github.com/mongoid/mongoid/blob/master/lib/mongoid/persistence.rb#L137 er = ActiveModel::Errors.new(problem) er.add_on_blank(:resolved) - problem.stub(:errors).and_return(er) + allow(problem).to receive(:errors).and_return(er) expect(problem).to_not be_valid expect { problem.resolve! @@ -210,7 +207,7 @@ describe Problem do end it "removing a notice decreases #notices_count by 1" do - notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1') + Fabricate(:notice, :err => @err, :message => 'ERR 1') expect { @err.notices.first.destroy @problem.reload @@ -240,7 +237,7 @@ describe Problem do before do @app = Fabricate(:app) @last_deploy = Time.at(10.days.ago.localtime.to_i) - deploy = Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production") + Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production") end it "is set when a problem is created" do @@ -276,7 +273,7 @@ describe Problem do end it "removing a notice removes string from #messages" do - notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1') + Fabricate(:notice, :err => @err, :message => 'ERR 1') expect { @err.notices.first.destroy @problem.reload @@ -284,7 +281,7 @@ describe Problem do end it "removing a notice from the problem with broken counter should not raise an error" do - notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1') + Fabricate(:notice, :err => @err, :message => 'ERR 1') @problem.messages = {} @problem.save! expect {@err.notices.first.destroy}.not_to raise_error @@ -309,7 +306,7 @@ describe Problem do end it "removing a notice removes string from #hosts" do - notice1 = Fabricate(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"}) + Fabricate(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"}) expect { @err.notices.first.destroy @problem.reload @@ -335,7 +332,7 @@ describe Problem do end it "removing a notice removes string from #user_agents" do - 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'}}) + 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'}}) expect { @err.notices.first.destroy @problem.reload @@ -362,7 +359,7 @@ describe Problem do end it "removing a comment decreases #comments_count by 1" do - comment1 = Fabricate(:comment, :err => @problem) + Fabricate(:comment, :err => @problem) expect { @problem.reload.comments.first.destroy @problem.reload @@ -418,7 +415,4 @@ describe Problem do end end end - - end - diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1c87460..2f65512 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - describe User do - context 'validations' do it 'require that a name is present' do user = Fabricate.build(:user, :name => nil) @@ -41,7 +38,6 @@ describe User do end context 'Watchers' do - it 'has many watchers' do user = Fabricate(:user) watcher = Fabricate(:user_watcher, :user => user) @@ -53,23 +49,20 @@ describe User do user = Fabricate(:user) watched_app = Fabricate(:app) unwatched_app = Fabricate(:app) - watcher = Fabricate(:user_watcher, :app => watched_app, :user => user) + Fabricate(:user_watcher, :app => watched_app, :user => user) expect(user.apps.all).to include(watched_app) expect(user.apps.all).to_not include(unwatched_app) end - end context "First user" do it "should be created this admin access via db:seed" do expect { - $stdout.stub(:puts => true) + allow($stdout).to receive(:puts).and_return(true) require Rails.root.join('db/seeds.rb') }.to change { User.where(:admin => true).count }.from(0).to(1) end end - end - diff --git a/spec/models/watcher_spec.rb b/spec/models/watcher_spec.rb index 315e081..0b2f10d 100644 --- a/spec/models/watcher_spec.rb +++ b/spec/models/watcher_spec.rb @@ -1,7 +1,4 @@ -require 'spec_helper' - -describe Watcher do - +describe Watcher, type: 'model' do context 'validations' do it 'requires an email address or an associated user' do watcher = Fabricate.build(:watcher, :email => nil, :user => nil) @@ -32,6 +29,4 @@ describe Watcher do expect(watcher.address).to eq 'widgets@acme.com' end end - end - diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..826c753 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,38 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require 'spec_helper' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } + +RSpec.configure do |config| + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! +end diff --git a/spec/requests/notices_controller_spec.rb b/spec/requests/notices_controller_spec.rb index 6a173fa..565f70b 100644 --- a/spec/requests/notices_controller_spec.rb +++ b/spec/requests/notices_controller_spec.rb @@ -1,9 +1,5 @@ -require 'spec_helper' - -describe "Notices management" do - - let(:errbit_app) { Fabricate(:app, - :api_key => 'APIKEY') } +describe "Notices management", type: 'request' do + let(:errbit_app) { Fabricate(:app, :api_key => 'APIKEY') } describe "create a new notice" do context "with valide notice" do @@ -38,11 +34,8 @@ describe "Notices management" do post '/notifier_api/v2/notices', :data => xml expect(response.status).to eq 422 expect(response.body).to eq "Your API key is unknown" - }.to_not change { - errbit_app.problems.count - }.by(1) + }.to_not change(errbit_app.problems, :count) end - end context "with GET request" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6d26852..c2a77cf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,11 +19,13 @@ end require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' +require 'rspec/its' require 'email_spec' require 'database_cleaner' require 'xmpp4r' require 'xmpp4r/muc' require 'mongoid-rspec' +require 'fabrication' require 'errbit_plugin/mock_issue_tracker' # Requires supporting files with custom matchers and macros, etc, @@ -31,11 +33,8 @@ require 'errbit_plugin/mock_issue_tracker' Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |config| - config.mock_with :rspec config.include Devise::TestHelpers, :type => :controller config.include Mongoid::Matchers, :type => :model - config.filter_run :focused => true - config.run_all_when_everything_filtered = true config.alias_example_to :fit, :focused => true config.before(:each) do diff --git a/spec/support/macros.rb b/spec/support/macros.rb index 8271b59..c1d15d0 100644 --- a/spec/support/macros.rb +++ b/spec/support/macros.rb @@ -21,13 +21,13 @@ def it_requires_authentication(options = {}) options[:for].each do |action, method| it "#{method.to_s.upcase} #{action} redirects to the sign in page" do send(method, action, options[:params]) - response.should redirect_to(new_user_session_path) + expect(response).to redirect_to(new_user_session_path) end end end end -def it_requires_admin_privileges(options = {}) +def it_requires_admin_privileges(options = {}) default_options = { :for => { :index => :get, @@ -51,7 +51,7 @@ def it_requires_admin_privileges(options = {}) options[:for].each do |action, method| it "#{method.to_s.upcase} #{action} redirects to the root path" do send(method, action, options[:params]) - response.should redirect_to(root_path) + expect(response).to redirect_to(root_path) end end end diff --git a/spec/views/apps/edit.html.haml_spec.rb b/spec/views/apps/edit.html.haml_spec.rb index 86149f5..3515214 100644 --- a/spec/views/apps/edit.html.haml_spec.rb +++ b/spec/views/apps/edit.html.haml_spec.rb @@ -1,12 +1,11 @@ -require 'spec_helper' - -describe "apps/edit.html.haml" do +describe "apps/edit.html.haml", type: 'view' do let(:app) { stub_model(App) } let(:app_decorate) { AppDecorator.new(app) } + before do - view.stub(:app).and_return(app) - view.stub(:app_decorate).and_return(app_decorate) - controller.stub(:current_user) { stub_model(User) } + allow(view).to receive(:app).and_return(app) + allow(view).to receive(:app_decorate).and_return(app_decorate) + allow(controller).to receive(:current_user).and_return(stub_model(User)) end describe "content_for :action_bar" do @@ -23,7 +22,6 @@ describe "apps/edit.html.haml" do render expect(action_bar).to have_selector('a.button[data-confirm="%s"]' % I18n.t('apps.confirm_delete')) end - end context "with unvalid app" do @@ -38,6 +36,4 @@ describe "apps/edit.html.haml" do expect(rendered).to match(/You must specify your/) end end - end - diff --git a/spec/views/apps/index.html.haml_spec.rb b/spec/views/apps/index.html.haml_spec.rb index 0012a6c..2818a07 100644 --- a/spec/views/apps/index.html.haml_spec.rb +++ b/spec/views/apps/index.html.haml_spec.rb @@ -1,10 +1,8 @@ -require 'spec_helper' - -describe "apps/index.html.haml" do +describe "apps/index.html.haml", type: 'view' do before do app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.now, :revision => "123456789abcdef")]) - view.stub(:apps).and_return([app]) - controller.stub(:current_user) { stub_model(User) } + allow(view).to receive(:apps).and_return([app]) + allow(controller).to receive(:current_user).and_return(stub_model(User)) end describe "deploy column" do @@ -14,4 +12,3 @@ describe "apps/index.html.haml" do end end end - diff --git a/spec/views/apps/new.html.haml_spec.rb b/spec/views/apps/new.html.haml_spec.rb index 1f9b5d4..0ef5502 100644 --- a/spec/views/apps/new.html.haml_spec.rb +++ b/spec/views/apps/new.html.haml_spec.rb @@ -1,12 +1,11 @@ -require 'spec_helper' - -describe "apps/new.html.haml" do +describe "apps/new.html.haml", type: 'view' do let(:app) { stub_model(App) } let(:app_decorate) { AppDecorator.new(app) } + before do - view.stub(:app).and_return(app) - view.stub(:app_decorate).and_return(app_decorate) - controller.stub(:current_user) { stub_model(User) } + allow(view).to receive(:app).and_return(app) + allow(view).to receive(:app_decorate).and_return(app_decorate) + allow(controller).to receive(:current_user).and_return(stub_model(User)) end describe "content_for :action_bar" do @@ -34,6 +33,4 @@ describe "apps/new.html.haml" do expect(rendered).to match(/You must specify your/) end end - end - diff --git a/spec/views/apps/show.atom.builder_spec.rb b/spec/views/apps/show.atom.builder_spec.rb index 4894160..341d768 100644 --- a/spec/views/apps/show.atom.builder_spec.rb +++ b/spec/views/apps/show.atom.builder_spec.rb @@ -1,14 +1,12 @@ -require 'spec_helper' - -describe "apps/show.atom.builder" do +describe "apps/show.atom.builder", type: 'view' do let(:app) { stub_model(App) } let(:problems) { [ stub_model(Problem, :message => 'foo', :app => app) ]} before do - view.stub(:app).and_return(app) - view.stub(:problems).and_return(problems) + allow(view).to receive(:app).and_return(app) + allow(view).to receive(:problems).and_return(problems) end context "with errs" do @@ -17,5 +15,4 @@ describe "apps/show.atom.builder" do expect(rendered).to match(problems.first.message) end end - end diff --git a/spec/views/apps/show.html.haml_spec.rb b/spec/views/apps/show.html.haml_spec.rb index 87aeaf7..11bece6 100644 --- a/spec/views/apps/show.html.haml_spec.rb +++ b/spec/views/apps/show.html.haml_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe "apps/show.html.haml" do +describe "apps/show.html.haml", type: 'view' do let(:app) { stub_model(App) } let(:user) { stub_model(User) } @@ -9,20 +7,18 @@ describe "apps/show.html.haml" do end before do - view.stub(:app).and_return(app) - view.stub(:all_errs).and_return(false) - view.stub(:deploys).and_return([]) - controller.stub(:current_user) { user } + allow(view).to receive(:app).and_return(app) + allow(view).to receive(:all_errs).and_return(false) + allow(view).to receive(:deploys).and_return([]) + allow(controller).to receive(:current_user).and_return(user) end describe "content_for :action_bar" do - it "should confirm the 'cancel' link" do render expect(action_bar).to have_selector('a.button', :text => 'all errs') end - end context "without errs" do @@ -34,7 +30,7 @@ describe "apps/show.html.haml" do context "with user watch application" do before do - user.stub(:watching?).with(app).and_return(true) + allow(user).to receive(:watching?).with(app).and_return(true) end it 'see the unwatch button' do render @@ -44,13 +40,11 @@ describe "apps/show.html.haml" do context "with user not watch application" do before do - user.stub(:watching?).with(app).and_return(false) + allow(user).to receive(:watching?).with(app).and_return(false) end it 'not see the unwatch button' do render expect(action_bar).to_not include(I18n.t('apps.show.unwatch')) end end - end - diff --git a/spec/views/notices/_summary.html.haml_spec.rb b/spec/views/notices/_summary.html.haml_spec.rb index aac281d..0ea37b2 100644 --- a/spec/views/notices/_summary.html.haml_spec.rb +++ b/spec/views/notices/_summary.html.haml_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe "notices/_summary.html.haml" do +describe "notices/_summary.html.haml", type: 'view' do let(:notice) { Fabricate(:notice, :framework => 'Rails 3.2.11') } it "renders application framework" do @@ -9,4 +7,3 @@ describe "notices/_summary.html.haml" do expect(rendered).to have_content('Rails 3.2.11') end end - diff --git a/spec/views/notices/_user_attributes.html.haml_spec.rb b/spec/views/notices/_user_attributes.html.haml_spec.rb index 387a7c3..fc3c315 100644 --- a/spec/views/notices/_user_attributes.html.haml_spec.rb +++ b/spec/views/notices/_user_attributes.html.haml_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe "notices/_user_attributes.html.haml" do +describe "notices/_user_attributes.html.haml", type: 'view' do describe 'autolink' do let(:notice) do user_attributes = { 'foo' => {'bar' => 'http://example.com'} } @@ -15,4 +13,3 @@ describe "notices/_user_attributes.html.haml" do end end end - diff --git a/spec/views/problems/index.atom.builder_spec.rb b/spec/views/problems/index.atom.builder_spec.rb index 73921df..861ce4b 100644 --- a/spec/views/problems/index.atom.builder_spec.rb +++ b/spec/views/problems/index.atom.builder_spec.rb @@ -1,14 +1,10 @@ -require 'spec_helper' - -describe "problems/index.atom.builder" do - +describe "problems/index.atom.builder", type: 'view' do it 'display problem message' do app = App.new(:new_record => false) - view.stub(:problems).and_return([Problem.new( + allow(view).to receive(:problems).and_return([Problem.new( :message => 'foo', :new_record => false, :app => app), Problem.new(:new_record => false, :app => app)]) render expect(rendered).to match('foo') end - end diff --git a/spec/views/problems/index.html.haml_spec.rb b/spec/views/problems/index.html.haml_spec.rb index 70c2a5e..c6d0f53 100644 --- a/spec/views/problems/index.html.haml_spec.rb +++ b/spec/views/problems/index.html.haml_spec.rb @@ -1,15 +1,14 @@ -require 'spec_helper' - -describe "problems/index.html.haml" do +describe "problems/index.html.haml", type: 'view' do let(:problem_1) { Fabricate(:problem) } let(:problem_2) { Fabricate(:problem, :app => problem_1.app) } before do - # view.stub(:app).and_return(problem.app) - view.stub(:selected_problems).and_return([]) - view.stub(:problems).and_return(Kaminari.paginate_array([problem_1, problem_2]).page(1).per(10)) - view.stub(:params_sort).and_return('asc') - controller.stub(:current_user) { Fabricate(:user) } + allow(view).to receive(:selected_problems).and_return([]) + allow(view).to receive(:problems).and_return( + Kaminari.paginate_array([problem_1, problem_2]).page(1).per(10) + ) + allow(view).to receive(:params_sort).and_return('asc') + allow(controller).to receive(:current_user).and_return(Fabricate(:user)) end describe "with problem" do @@ -20,6 +19,4 @@ describe "problems/index.html.haml" do expect(rendered).to have_selector('div#problem_table.problem_table') end end - end - diff --git a/spec/views/problems/show.html.haml_spec.rb b/spec/views/problems/show.html.haml_spec.rb index 048181f..5501e41 100644 --- a/spec/views/problems/show.html.haml_spec.rb +++ b/spec/views/problems/show.html.haml_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe "problems/show.html.haml" do +describe "problems/show.html.haml", type: 'view' do let(:problem) { Fabricate(:problem) } let(:comment) { Fabricate(:comment) } let(:pivotal_tracker) { @@ -23,22 +21,19 @@ describe "problems/show.html.haml" do } before do - view.stub(:app).and_return(problem.app) - view.stub(:problem).and_return(problem) + allow(view).to receive(:app).and_return(problem.app) + allow(view).to receive(:problem).and_return(problem) assign :comment, comment assign :notices, problem.notices.page(1).per(1) assign :notice, problem.notices.first - controller.stub(:current_user) { Fabricate(:user) } + allow(controller).to receive(:current_user).and_return(Fabricate(:user)) end def with_issue_tracker(tracker, problem) - ErrbitPlugin::Registry.stub(:issue_trackers).and_return(trackers) + allow(ErrbitPlugin::Registry).to receive(:issue_trackers).and_return(trackers) problem.app.issue_tracker = IssueTracker.new :type_tracker => tracker, :options => {:api_token => "token token token", :project_id => "1234"} - - view.stub(:problem).and_return(problem) - view.stub(:app).and_return(problem.app) end describe "content_for :action_bar" do @@ -52,13 +47,13 @@ describe "problems/show.html.haml" do end it "should confirm the 'resolve' link if configuration is unset" do - Errbit::Config.stub(:confirm_err_actions).and_return(nil) + allow(Errbit::Config).to receive(:confirm_err_actions).and_return(nil) render expect(action_bar).to have_selector('a.resolve[data-confirm="%s"]' % I18n.t('problems.confirm.resolve_one')) end it "should not confirm the 'resolve' link if configured not to" do - Errbit::Config.stub(:confirm_err_actions).and_return(false) + allow(Errbit::Config).to receive(:confirm_err_actions).and_return(false) render expect(action_bar).to have_selector('a.resolve[data-confirm="null"]') end @@ -73,8 +68,9 @@ describe "problems/show.html.haml" do it "should link 'up' to app_problems_path if HTTP_REFERER isn't set'" do controller.request.env['HTTP_REFERER'] = nil problem = Fabricate(:problem_with_comments) - view.stub(:problem).and_return(problem) - view.stub(:app).and_return(problem.app) + + allow(view).to receive(:problem).and_return(problem) + allow(view).to receive(:app).and_return(problem.app) render expect(action_bar).to have_selector("span a.up[href='#{app_problems_path(problem.app)}']", :text => 'up') @@ -86,8 +82,8 @@ describe "problems/show.html.haml" do it 'should allow creating issue for github if application has a github tracker' do problem = Fabricate(:problem_with_comments, app: app) with_issue_tracker("github", problem) - view.stub(:problem).and_return(problem) - view.stub(:app).and_return(problem.app) + allow(view).to receive(:problem).and_return(problem) + allow(view).to receive(:app).and_return(problem.app) render expect(action_bar).to have_selector("span a.github_create.create-issue", text: 'create issue') @@ -98,8 +94,6 @@ describe "problems/show.html.haml" do let(:app) { App.new(:new_record => false) } it 'not see link to create issue' do - view.stub(:problem).and_return(problem) - view.stub(:app).and_return(problem.app) render expect(view.content_for(:action_bar)).to_not match(/create issue/) end @@ -118,7 +112,8 @@ describe "problems/show.html.haml" do before do problem.issue_link = nil user = Fabricate(:user, :github_login => 'test_user', :github_oauth_token => 'abcdef') - controller.stub(:current_user) { user } + + allow(controller).to receive(:current_user).and_return(user) end it 'links to the associated tracker' do @@ -161,13 +156,13 @@ describe "problems/show.html.haml" do describe "content_for :comments" do before do - Errbit::Config.stub(:use_gravatar).and_return(true) + problem = Fabricate(:problem_with_comments) + allow(view).to receive(:problem).and_return(problem) + allow(view).to receive(:app).and_return(problem.app) + allow(Errbit::Config).to receive(:use_gravatar).and_return(true) end it 'should display comments and new comment form' do - problem = Fabricate(:problem_with_comments) - view.stub(:problem).and_return(problem) - view.stub(:app).and_return(problem.app) render expect(view.content_for(:comments)).to include('Test comment') @@ -175,9 +170,7 @@ describe "problems/show.html.haml" do expect(view.content_for(:comments)).to include('Add a comment') end - it 'should display existing comments' do - problem = Fabricate(:problem_with_comments) - problem.reload + it 'should display existing comments with configured tracker' do with_issue_tracker("pivotal", problem) render diff --git a/spec/views/problems/show.ics.haml_spec.rb b/spec/views/problems/show.ics.haml_spec.rb index 81d61fe..1ae8de8 100644 --- a/spec/views/problems/show.ics.haml_spec.rb +++ b/spec/views/problems/show.ics.haml_spec.rb @@ -1,14 +1,11 @@ -require 'spec_helper' - -describe "problems/show.html.ics" do +describe "problems/show.html.ics", type: 'view' do let(:problem) { Fabricate(:problem) } + before do - view.stub(:problem).and_return(problem) + allow(view).to receive(:problem).and_return(problem) end it 'should work' do render :template => 'problems/show', :formats => [:ics], :handlers => [:haml] end - - end diff --git a/spec/views/users/edit.html.haml_spec.rb b/spec/views/users/edit.html.haml_spec.rb index 4edf49a..018a8cb 100644 --- a/spec/views/users/edit.html.haml_spec.rb +++ b/spec/views/users/edit.html.haml_spec.rb @@ -1,10 +1,8 @@ -require 'spec_helper' - -describe 'users/edit.html.haml' do +describe 'users/edit.html.haml', type: 'view' do let(:user) { stub_model(User, :name => 'shingara') } before { - view.stub(:current_user).and_return(user) - view.stub(:user).and_return(user) + allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:user).and_return(user) } it 'should have per_page option' do render diff --git a/spec/views/users/index.html.haml_spec.rb b/spec/views/users/index.html.haml_spec.rb index 59ce22b..6d32479 100644 --- a/spec/views/users/index.html.haml_spec.rb +++ b/spec/views/users/index.html.haml_spec.rb @@ -1,10 +1,8 @@ -require 'spec_helper' - -describe 'users/index.html.haml' do +describe 'users/index.html.haml', type: 'view' do let(:user) { stub_model(User) } before { - view.stub(:current_user).and_return(user) - view.stub(:users).and_return( + allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:users).and_return( Kaminari.paginate_array([user], :total_count => 1).page(1) ) } @@ -12,5 +10,4 @@ describe 'users/index.html.haml' do render expect(rendered).to match(/class='user_list'/) end - end diff --git a/spec/views/users/new.html.haml_spec.rb b/spec/views/users/new.html.haml_spec.rb index 63c75e7..73ee8d5 100644 --- a/spec/views/users/new.html.haml_spec.rb +++ b/spec/views/users/new.html.haml_spec.rb @@ -1,10 +1,8 @@ -require 'spec_helper' - -describe 'users/new.html.haml' do +describe 'users/new.html.haml', type: 'view' do let(:user) { stub_model(User) } before { - view.stub(:current_user).and_return(user) - view.stub(:user).and_return(user) + allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:user).and_return(user) } it 'should have per_page option' do render diff --git a/spec/views/users/show.html.haml_spec.rb b/spec/views/users/show.html.haml_spec.rb index 9a60b5b..02e88a7 100644 --- a/spec/views/users/show.html.haml_spec.rb +++ b/spec/views/users/show.html.haml_spec.rb @@ -1,15 +1,12 @@ -require 'spec_helper' - -describe 'users/show.html.haml' do - +describe 'users/show.html.haml', type: 'view' do let(:user) do stub_model(User, :created_at => Time.now, :email => "test@example.com") end before do - Errbit::Config.stub(:github_authentication) { true } - controller.stub(:current_user) { stub_model(User) } - view.stub(:user) { user } + allow(Errbit::Config).to receive(:github_authentication).and_return(true) + allow(controller).to receive(:current_user).and_return(stub_model(User)) + allow(view).to receive(:user).and_return(user) end context 'with GitHub authentication' do @@ -38,7 +35,7 @@ describe 'users/show.html.haml' do context 'viewing own user page' do before do - controller.stub(:current_user) { user } + allow(controller).to receive(:current_user).and_return(user) end it 'shows link github button when no login or token' do -- libgit2 0.21.2