Add and apply RSpec/ReceiveMessages rubocop rule

This rule was added in rubocop-rspec 2.23.0. I didn't know this method
existed, and it makes the code more readable in some cases.
This commit is contained in:
Javi Martín
2023-09-08 13:26:15 +02:00
parent 9bb2bfdd06
commit 1d5f03be8c
10 changed files with 30 additions and 39 deletions

View File

@@ -567,6 +567,9 @@ RSpec/Rails/NegationBeValid:
RSpec/Rails/TravelAround:
Enabled: true
RSpec/ReceiveMessages:
Enabled: true
RSpec/RepeatedExample:
Enabled: true

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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