diff --git a/.rubocop.yml b/.rubocop.yml index 83e79bbaa..5e8ee7a68 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -567,6 +567,9 @@ RSpec/Rails/NegationBeValid: RSpec/Rails/TravelAround: Enabled: true +RSpec/ReceiveMessages: + Enabled: true + RSpec/RepeatedExample: Enabled: true diff --git a/spec/components/admin/budgets/index_component_spec.rb b/spec/components/admin/budgets/index_component_spec.rb index 5e7082c3e..c16bda636 100644 --- a/spec/components/admin/budgets/index_component_spec.rb +++ b/spec/components/admin/budgets/index_component_spec.rb @@ -2,8 +2,7 @@ require "rails_helper" describe Admin::Budgets::IndexComponent, controller: Admin::BudgetsController do before do - allow(vc_test_controller).to receive(:valid_filters).and_return(["all"]) - allow(vc_test_controller).to receive(:current_filter).and_return("all") + allow(vc_test_controller).to receive_messages(valid_filters: ["all"], current_filter: "all") end describe "#phase_progress_text" do diff --git a/spec/components/admin/organizations/table_actions_component_spec.rb b/spec/components/admin/organizations/table_actions_component_spec.rb index 4b9d0dd47..96e3f8e49 100644 --- a/spec/components/admin/organizations/table_actions_component_spec.rb +++ b/spec/components/admin/organizations/table_actions_component_spec.rb @@ -5,8 +5,7 @@ describe Admin::Organizations::TableActionsComponent, controller: Admin::Organiz let(:component) { Admin::Organizations::TableActionsComponent.new(organization) } it "renders buttons to verify and reject when it can" do - allow(component).to receive(:can_verify?).and_return(true) - allow(component).to receive(:can_reject?).and_return(true) + allow(component).to receive_messages(can_verify?: true, can_reject?: true) render_inline component @@ -17,8 +16,7 @@ describe Admin::Organizations::TableActionsComponent, controller: Admin::Organiz end it "renders button to verify when it cannot reject" do - allow(component).to receive(:can_verify?).and_return(true) - allow(component).to receive(:can_reject?).and_return(false) + allow(component).to receive_messages(can_verify?: true, can_reject?: false) render_inline component @@ -27,8 +25,7 @@ describe Admin::Organizations::TableActionsComponent, controller: Admin::Organiz end it "renders button to reject when it cannot verify" do - allow(component).to receive(:can_verify?).and_return(false) - allow(component).to receive(:can_reject?).and_return(true) + allow(component).to receive_messages(can_verify?: false, can_reject?: true) render_inline component @@ -37,8 +34,7 @@ describe Admin::Organizations::TableActionsComponent, controller: Admin::Organiz end it "does not render any actions when it cannot verify nor reject" do - allow(component).to receive(:can_verify?).and_return(false) - allow(component).to receive(:can_reject?).and_return(false) + allow(component).to receive_messages(can_verify?: false, can_reject?: false) render_inline component diff --git a/spec/components/sdg_management/relations/index_component_spec.rb b/spec/components/sdg_management/relations/index_component_spec.rb index 8f0f7ea78..d37e5576a 100644 --- a/spec/components/sdg_management/relations/index_component_spec.rb +++ b/spec/components/sdg_management/relations/index_component_spec.rb @@ -2,10 +2,10 @@ require "rails_helper" describe SDGManagement::Relations::IndexComponent, controller: SDGManagement::RelationsController do before do - allow(vc_test_controller).to receive(:valid_filters) - .and_return(SDGManagement::RelationsController::FILTERS) - allow(vc_test_controller).to receive(:current_filter) - .and_return(SDGManagement::RelationsController::FILTERS.first) + allow(vc_test_controller).to receive_messages( + valid_filters: SDGManagement::RelationsController::FILTERS, + current_filter: SDGManagement::RelationsController::FILTERS.first + ) end it "renders the search form" do diff --git a/spec/lib/manager_authenticator_spec.rb b/spec/lib/manager_authenticator_spec.rb index 0c456d0dd..4703ad900 100644 --- a/spec/lib/manager_authenticator_spec.rb +++ b/spec/lib/manager_authenticator_spec.rb @@ -39,22 +39,19 @@ describe ManagerAuthenticator do describe "#auth" do it "returns false if not manager_exists" do - allow(authenticator).to receive(:manager_exists?).and_return(false) - allow(authenticator).to receive(:application_authorized?).and_return(true) + allow(authenticator).to receive_messages(manager_exists?: false, application_authorized?: true) expect(authenticator.auth).to be false end it "returns false if not application_authorized" do - allow(authenticator).to receive(:manager_exists?).and_return(true) - allow(authenticator).to receive(:application_authorized?).and_return(false) + allow(authenticator).to receive_messages(manager_exists?: true, application_authorized?: false) expect(authenticator.auth).to be false end it "returns ok if manager_exists and application_authorized" do - allow(authenticator).to receive(:manager_exists?).and_return(true) - allow(authenticator).to receive(:application_authorized?).and_return(true) + allow(authenticator).to receive_messages(manager_exists?: true, application_authorized?: true) expect(authenticator.auth).to be_truthy end diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb index e24e42f0d..e61abf100 100644 --- a/spec/models/budget/stats_spec.rb +++ b/spec/models/budget/stats_spec.rb @@ -243,8 +243,7 @@ describe Budget::Stats do describe "#all_phases" do context "no phases are finished" do before do - allow(stats).to receive(:support_phase_finished?).and_return(false) - allow(stats).to receive(:vote_phase_finished?).and_return(false) + allow(stats).to receive_messages(support_phase_finished?: false, vote_phase_finished?: false) end it "returns an empty array" do @@ -254,8 +253,7 @@ describe Budget::Stats do context "one phase is finished" do before do - allow(stats).to receive(:support_phase_finished?).and_return(true) - allow(stats).to receive(:vote_phase_finished?).and_return(false) + allow(stats).to receive_messages(support_phase_finished?: true, vote_phase_finished?: false) end it "returns the finished phase" do @@ -265,8 +263,7 @@ describe Budget::Stats do context "all phases are finished" do before do - allow(stats).to receive(:support_phase_finished?).and_return(true) - allow(stats).to receive(:vote_phase_finished?).and_return(true) + allow(stats).to receive_messages(support_phase_finished?: true, vote_phase_finished?: true) end it "returns the finished phases and a total phase" do diff --git a/spec/models/newsletter_spec.rb b/spec/models/newsletter_spec.rb index c25f9d3a8..56fb2ae30 100644 --- a/spec/models/newsletter_spec.rb +++ b/spec/models/newsletter_spec.rb @@ -93,9 +93,11 @@ describe Newsletter do end it "sends batches in time intervals" do - allow(newsletter).to receive(:batch_size).and_return(1) - allow(newsletter).to receive(:batch_interval).and_return(1.second) - allow(newsletter).to receive(:first_batch_run_at).and_return(Time.current) + allow(newsletter).to receive_messages( + batch_size: 1, + batch_interval: 1.second, + first_batch_run_at: Time.current + ) newsletter.deliver diff --git a/spec/models/statisticable_spec.rb b/spec/models/statisticable_spec.rb index 1cc57ca2a..f9e4ffc9a 100644 --- a/spec/models/statisticable_spec.rb +++ b/spec/models/statisticable_spec.rb @@ -169,9 +169,7 @@ describe Statisticable do context "all gender, age and geozone stats" do before do - allow(stats).to receive(:gender?).and_return(true) - allow(stats).to receive(:age?).and_return(true) - allow(stats).to receive(:geozone?).and_return(true) + allow(stats).to receive_messages(gender?: true, age?: true, geozone?: true) end it "includes all stats methods" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d7a2b57fe..49717ba9e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -153,12 +153,9 @@ RSpec.configure do |config| config.before(:each, :application_zone_west_of_system_zone) do application_zone = ActiveSupport::TimeZone.new("Quito") system_zone = ActiveSupport::TimeZone.new("Madrid") - - allow(Time).to receive(:zone).and_return(application_zone) - system_time_at_application_end_of_day = Date.current.end_of_day.in_time_zone(system_zone) - allow(Time).to receive(:now).and_return(system_time_at_application_end_of_day) + allow(Time).to receive_messages(zone: application_zone, now: system_time_at_application_end_of_day) allow(Date).to receive(:today).and_return(system_time_at_application_end_of_day.to_date) end diff --git a/spec/system/notifications_spec.rb b/spec/system/notifications_spec.rb index 0da41cdf3..0d23d9b02 100644 --- a/spec/system/notifications_spec.rb +++ b/spec/system/notifications_spec.rb @@ -213,9 +213,11 @@ describe "Notifications" do end it "sends batches in time intervals" do - allow(Notification).to receive(:batch_size).and_return(1) - allow(Notification).to receive(:batch_interval).and_return(1.second) - allow(Notification).to receive(:first_batch_run_at).and_return(Time.current) + allow(Notification).to receive_messages( + batch_size: 1, + batch_interval: 1.second, + first_batch_run_at: Time.current + ) remove_users_without_pending_notifications