From cb5be1fe8f7032d4d648a375e5fcb516ba3a1541 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 30 May 2016 11:38:04 +0800 Subject: [PATCH] Upgrade rspec to 3.4.0. --- Gemfile | 2 +- Gemfile.lock | 34 +++++++++---------- app/models/user.rb | 7 ++-- lib/plugin/filter_manager.rb | 2 +- spec/components/plugin/filter_manager_spec.rb | 4 +-- spec/components/topic_query_spec.rb | 2 +- .../directory_items_controller_spec.rb | 2 +- .../omniauth_callbacks_controller_spec.rb | 4 +-- .../user_actions_controller_spec.rb | 2 +- .../user_badges_controller_spec.rb | 4 +-- spec/jobs/jobs_base_spec.rb | 2 +- spec/models/post_action_spec.rb | 2 +- spec/models/topic_spec.rb | 6 ++-- spec/models/user_spec.rb | 4 +-- spec/rails_helper.rb | 7 ---- 15 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Gemfile b/Gemfile index 29c9292d08d..ab8d2856f4d 100644 --- a/Gemfile +++ b/Gemfile @@ -125,7 +125,7 @@ group :test do end group :test, :development do - gem 'rspec', '~> 3.2.0' + gem 'rspec' gem 'mock_redis' gem 'listen', '0.7.3', require: false gem 'certified', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 995efb13e07..f54b09ea2dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -294,33 +294,33 @@ GEM netrc (~> 0.7) rinku (2.0.0) rmmseg-cpp (0.2.9) - rspec (3.2.0) - rspec-core (~> 3.2.0) - rspec-expectations (~> 3.2.0) - rspec-mocks (~> 3.2.0) - rspec-core (3.2.3) - rspec-support (~> 3.2.0) - rspec-expectations (3.2.1) + rspec (3.4.0) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-core (3.4.4) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.2.0) + rspec-support (~> 3.4.0) rspec-given (3.7.1) given_core (= 3.7.1) rspec (>= 2.14.0) rspec-html-matchers (0.7.0) nokogiri (~> 1) rspec (~> 3) - rspec-mocks (3.2.1) + rspec-mocks (3.4.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.2.0) - rspec-rails (3.2.3) + rspec-support (~> 3.4.0) + rspec-rails (3.4.2) actionpack (>= 3.0, < 4.3) activesupport (>= 3.0, < 4.3) railties (>= 3.0, < 4.3) - rspec-core (~> 3.2.0) - rspec-expectations (~> 3.2.0) - rspec-mocks (~> 3.2.0) - rspec-support (~> 3.2.0) - rspec-support (3.2.2) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) rtlit (0.0.5) ruby-openid (2.7.0) ruby-readability (0.7.0) @@ -475,7 +475,7 @@ DEPENDENCIES rest-client rinku rmmseg-cpp - rspec (~> 3.2.0) + rspec rspec-given rspec-html-matchers rspec-rails diff --git a/app/models/user.rb b/app/models/user.rb index a4917e0eed9..bff29252386 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -613,7 +613,10 @@ class User < ActiveRecord::Base # Use this helper to determine if the user has a particular trust level. # Takes into account admin, etc. def has_trust_level?(level) - raise "Invalid trust level #{level}" unless TrustLevel.valid?(level) + unless TrustLevel.valid?(level) + raise InvalidTrustLevel.new("Invalid trust level #{level}") + end + admin? || moderator? || staged? || TrustLevel.compare(trust_level, level) end @@ -907,7 +910,7 @@ class User < ActiveRecord::Base end def hash_password(password, salt) - raise "password is too long" if password.size > User.max_password_length + raise StandardError.new("password is too long") if password.size > User.max_password_length Pbkdf2.hash_password(password, salt, Rails.configuration.pbkdf2_iterations, Rails.configuration.pbkdf2_algorithm) end diff --git a/lib/plugin/filter_manager.rb b/lib/plugin/filter_manager.rb index 10da578bd9c..34b76a1e1e3 100644 --- a/lib/plugin/filter_manager.rb +++ b/lib/plugin/filter_manager.rb @@ -6,7 +6,7 @@ module Plugin end def register(name, &blk) - raise ArgumentException unless blk && blk.arity == 2 + raise ArgumentError unless blk && blk.arity == 2 filters = @map[name] ||= [] filters << blk end diff --git a/spec/components/plugin/filter_manager_spec.rb b/spec/components/plugin/filter_manager_spec.rb index 44e98d530e5..285a2c8df43 100644 --- a/spec/components/plugin/filter_manager_spec.rb +++ b/spec/components/plugin/filter_manager_spec.rb @@ -20,7 +20,7 @@ describe Plugin::FilterManager do expect do instance.register(:test) do end - end.to raise_exception + end.to raise_error(ArgumentError) end it "should return the original if no filters exist" do @@ -30,6 +30,6 @@ describe Plugin::FilterManager do it "should raise an exception if no block is passed in" do expect do instance.register(:test) - end.to raise_exception + end.to raise_error(ArgumentError) end end diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index d3298a9dcdd..8874bcabbe5 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -416,7 +416,7 @@ describe TopicQuery do TopicList.preloaded_custom_fields.clear # if we attempt to access non preloaded fields explode - expect{new_topic.custom_fields["boom"]}.to raise_error + expect{new_topic.custom_fields["boom"]}.to raise_error(StandardError) end end diff --git a/spec/controllers/directory_items_controller_spec.rb b/spec/controllers/directory_items_controller_spec.rb index 38132d8e211..fa33e8af9a1 100644 --- a/spec/controllers/directory_items_controller_spec.rb +++ b/spec/controllers/directory_items_controller_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe DirectoryItemsController do it "requires a `period` param" do - expect{ xhr :get, :index }.to raise_error + expect{ xhr :get, :index }.to raise_error(ActionController::ParameterMissing) end it "requires a proper `period` param" do diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index 62f803cea41..de2a7d8f4d1 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -7,13 +7,13 @@ describe Users::OmniauthCallbacksController do SiteSetting.stubs("enable_twitter_logins?").returns(false) expect(lambda { Users::OmniauthCallbacksController.find_authenticator("twitter") - }).to raise_error + }).to raise_error(Discourse::InvalidAccess) end it "fails for unknown" do expect(lambda { Users::OmniauthCallbacksController.find_authenticator("twitter1") - }).to raise_error + }).to raise_error(Discourse::InvalidAccess) end it "finds an authenticator when enabled" do diff --git a/spec/controllers/user_actions_controller_spec.rb b/spec/controllers/user_actions_controller_spec.rb index b1914dea233..a161c2f90d3 100644 --- a/spec/controllers/user_actions_controller_spec.rb +++ b/spec/controllers/user_actions_controller_spec.rb @@ -5,7 +5,7 @@ describe UserActionsController do context 'index' do it 'fails if username is not specified' do - expect { xhr :get, :index }.to raise_error + expect { xhr :get, :index }.to raise_error(ActionController::ParameterMissing) end it 'renders list correctly' do diff --git a/spec/controllers/user_badges_controller_spec.rb b/spec/controllers/user_badges_controller_spec.rb index 0046f614049..8047d857154 100644 --- a/spec/controllers/user_badges_controller_spec.rb +++ b/spec/controllers/user_badges_controller_spec.rb @@ -24,7 +24,7 @@ describe UserBadgesController do let!(:user_badge) { UserBadge.create(badge: badge, user: user, granted_by: Discourse.system_user, granted_at: Time.now) } it 'requires username or badge_id to be specified' do - expect { xhr :get, :index }.to raise_error + expect { xhr :get, :index }.to raise_error(ActionController::ParameterMissing) end it 'returns user_badges for a user' do @@ -54,7 +54,7 @@ describe UserBadgesController do context 'create' do it 'requires username to be specified' do - expect { xhr :post, :create, badge_id: badge.id }.to raise_error + expect { xhr :post, :create, badge_id: badge.id }.to raise_error(ActionController::ParameterMissing) end it 'does not allow regular users to grant badges' do diff --git a/spec/jobs/jobs_base_spec.rb b/spec/jobs/jobs_base_spec.rb index c8ab2ab56aa..4388dc4886f 100644 --- a/spec/jobs/jobs_base_spec.rb +++ b/spec/jobs/jobs_base_spec.rb @@ -32,7 +32,7 @@ describe Jobs::Base do Discourse.expects(:handle_job_exception).times(3) bad = BadJob.new - expect{bad.perform({})}.to raise_error + expect{bad.perform({})}.to raise_error(Jobs::HandledExceptionWrapper) expect(bad.fail_count).to eq(3) end diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index e5809521e75..9321dedd81e 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -29,7 +29,7 @@ describe PostAction do expect { PostAction.act(eviltrout, post, PostActionType.types[:like]) - }.to raise_error + }.to raise_error(RateLimiter::LimitExceeded) end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index e9b8b84cffe..e1f48980ffd 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -443,7 +443,7 @@ describe Topic do expect { topic.invite(topic.user, "user@example.com") - }.to raise_exception + }.to raise_error(RateLimiter::LimitExceeded) end context 'bumping topics' do @@ -1483,7 +1483,7 @@ describe Topic do freeze_time(start + 10.minutes) expect { create_post(user: user) - }.to raise_exception + }.to raise_error(RateLimiter::LimitExceeded) freeze_time(start + 20.minutes) create_post(user: user, topic_id: topic_id) @@ -1492,7 +1492,7 @@ describe Topic do expect { create_post(user: user, topic_id: topic_id) - }.to raise_exception + }.to raise_error(RateLimiter::LimitExceeded) end describe ".count_exceeds_minimun?" do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 63a0dcfb2a2..4fbd120a68a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -204,7 +204,7 @@ describe User do describe 'has_trust_level?' do it "raises an error with an invalid level" do - expect { user.has_trust_level?(:wat) }.to raise_error + expect { user.has_trust_level?(:wat) }.to raise_error(InvalidTrustLevel) end it "is true for your basic level" do @@ -1106,7 +1106,7 @@ describe User do end it "raises an error when passwords are too long" do - expect { hash(too_long, 'gravy') }.to raise_error + expect { hash(too_long, 'gravy') }.to raise_error(StandardError) end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 354cb630dd4..30921a6e3f4 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -78,13 +78,6 @@ Spork.prefork do SiteSetting.defaults[k] = v end - # Monkey patch for NoMethodError: undefined method `cache' for nil:NilClass - # https://github.com/rspec/rspec-rails/issues/1532#issuecomment-174679485 - # fixed in Rspec 3.4.1 - RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator.class_eval do - alias_method :find_all_anywhere, :find_all - end - require_dependency 'site_settings/local_process_provider' SiteSetting.provider = SiteSettings::LocalProcessProvider.new end