Skip to content

Commit

Permalink
Merge pull request #375 from dgmstuart/dgms/stricter-rspec
Browse files Browse the repository at this point in the history
Stricter RSpec tests
  • Loading branch information
dgmstuart authored Sep 1, 2024
2 parents 2c98538 + 4cf6f0a commit cad63e9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
1 change: 0 additions & 1 deletion app/forms/edit_event_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def initialize(event)
:url,
:venue_id,
:social_organiser_id,
:social_organiser_id,
:class_style,
:course_length,
:class_organiser_id,
Expand Down
4 changes: 2 additions & 2 deletions spec/models/info_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
content: %w[about_bristol bristol_history]
}
}
pages = instance_double("InfoPages", page: config)
pages = instance_double("InfoPage::InfoPages", page: config)

page = described_class.new(:about, pages:, city: :london)

Expand All @@ -40,7 +40,7 @@
sidebar: %w[lindy_hop about_us_bristol]
}
}
pages = instance_double("InfoPages", page: config)
pages = instance_double("InfoPage::InfoPages", page: config)

page = described_class.new(:about, pages:, city: :bristol)

Expand Down
2 changes: 1 addition & 1 deletion spec/presenters/associated_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
describe "#link" do
it "links to the event" do
event = instance_double("Event")
url_helpers = instance_double("Rails.application.routes.url_helpers")
url_helpers = double("Rails.application.routes.url_helpers") # rubocop:disable RSpec/VerifiedDoubles
allow(url_helpers).to receive(:event_path).with(event).and_return("/path/to/event")

associated_event = described_class.new(event, summarizer: double, url_helpers:)
Expand Down
4 changes: 2 additions & 2 deletions spec/presenters/maps/social_listing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RSpec.describe Maps::SocialListing do
describe ".has_class?" do
it "delegates to the given event" do
has_class = instance_double("Boolean")
has_class = double("Boolean") # rubocop:disable RSpec/VerifiedDoubles
event = instance_double("Event", has_class?: has_class)

social_listing = described_class.new(event, url_helpers: double)
Expand All @@ -20,7 +20,7 @@

describe ".has_taster?" do
it "delegates to the given event" do
has_taster = instance_double("Boolean")
has_taster = double("Boolean") # rubocop:disable RSpec/VerifiedDoubles
event = instance_double("Event", has_taster?: has_taster)

social_listing = described_class.new(event, url_helpers: double)
Expand Down
2 changes: 1 addition & 1 deletion spec/presenters/social_listing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@

describe ".new?" do
it "delegates to the given event" do
new = instance_double("Boolean")
new = double("Boolean") # rubocop:disable RSpec/VerifiedDoubles
event = instance_double("Event", new?: new)

social_listing = described_class.new(event, url_helpers: double)
Expand Down
10 changes: 5 additions & 5 deletions spec/services/session_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
describe "#create" do
context "when the user has a role in the system" do
it "logs the user in" do
authoriser = instance_double("described_class::Authoriser", authorised?: true)
authoriser = instance_double("SessionCreator::Authoriser", authorised?: true)
login_session = instance_double("LoginSession", log_in!: double)
creator = described_class.new(authoriser:, login_session:, logger: fake_logger)

Expand All @@ -25,7 +25,7 @@
end

it "returns true" do
authoriser = instance_double("described_class::Authoriser", authorised?: true)
authoriser = instance_double("SessionCreator::Authoriser", authorised?: true)
login_session = instance_double("LoginSession", log_in!: double)
creator = described_class.new(authoriser:, login_session:, logger: fake_logger)

Expand All @@ -38,7 +38,7 @@

context "when the user doesn't have a role in the system" do
it "does not log the user in" do
authoriser = instance_double("described_class::Authoriser", authorised?: false)
authoriser = instance_double("SessionCreator::Authoriser", authorised?: false)
login_session = instance_double("LoginSession", log_in!: double)
creator = described_class.new(authoriser:, login_session:, logger: fake_logger)

Expand All @@ -49,7 +49,7 @@
end

it "returns false" do
authoriser = instance_double("described_class::Authoriser", authorised?: false)
authoriser = instance_double("SessionCreator::Authoriser", authorised?: false)
login_session = instance_double("LoginSession", log_in!: double)
creator = described_class.new(authoriser:, login_session:, logger: fake_logger)

Expand All @@ -60,7 +60,7 @@
end

it "logs" do
authoriser = instance_double("described_class::Authoriser", authorised?: false)
authoriser = instance_double("SessionCreator::Authoriser", authorised?: false)
login_session = instance_double("LoginSession", log_in!: double)
logger = fake_logger
creator = described_class.new(authoriser:, login_session:, logger:)
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
if config.files_to_run.count > 1
# Don't verify that doubled objects exist if only runnig one file
mocks.verify_doubled_constant_names = true
end
end

# used for --seed when randomising specs
Expand Down
13 changes: 8 additions & 5 deletions spec/support/time_formats_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
require "active_support/core_ext/time/conversions"
require "active_support/core_ext/integer/inflections"

# Allow reference to translations in isolated specs:
%w[en.yml en.rb].each do |locale_file|
I18n.load_path.push(
File.expand_path(locale_file, File.expand_path("../../config/locales", __dir__))
)
locale_files = %w[en.yml en.rb].map do |locale_file|
File.expand_path(locale_file, File.expand_path("../../config/locales", __dir__))
end

# Allow reference to translations in isolated specs,
# but only load the files if they're not already in the load path
locale_files.each do |file|
I18n.load_path.push(file) unless I18n.load_path.include?(file)
end

0 comments on commit cad63e9

Please sign in to comment.