From 19df608c203a59119cb3e313c0fa46b490c149ab Mon Sep 17 00:00:00 2001 From: Max Jacobson Date: Wed, 22 May 2024 16:54:33 -0400 Subject: [PATCH] Add rubocop-rspec --- .rubocop.yml | 16 ++++++++++++ Gemfile | 2 ++ Gemfile.lock | 13 ++++++++++ spec/models/episode_spec.rb | 6 ++--- spec/models/season_review_spec.rb | 36 +++++++++++++------------- spec/services/refresh_episodes_spec.rb | 8 +++--- 6 files changed, 56 insertions(+), 25 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 00f357d8..2ed71420 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,8 @@ inherit_from: .rubocop_todo.yml require: - rubocop-rails + - rubocop-rspec + - rubocop-rspec_rails AllCops: Exclude: @@ -14,5 +16,19 @@ AllCops: Metrics: Enabled: false +RSpec/ContextWording: + Prefixes: + - and + - when + +RSpec/ExampleLength: + Enabled: false + +RSpec/MultipleExpectations: + Enabled: false + +RSpec/NestedGroups: + Enabled: false + Style/StringLiterals: EnforcedStyle: double_quotes diff --git a/Gemfile b/Gemfile index 81094f01..c79bbd6e 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,8 @@ group :development do gem "listen" gem "rubocop" gem "rubocop-rails" + gem "rubocop-rspec" + gem "rubocop-rspec_rails" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 8be50ca2..3af07229 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -269,11 +269,22 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.31.3) parser (>= 3.3.1.0) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) rubocop-rails (2.25.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rspec (2.29.2) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.3) + rubocop (~> 1.40) ruby-progressbar (1.13.0) stringio (3.1.0) strscan (3.1.0) @@ -323,6 +334,8 @@ DEPENDENCIES rspec-rails rubocop rubocop-rails + rubocop-rspec + rubocop-rspec_rails sucker_punch vite_rails webmock diff --git a/spec/models/episode_spec.rb b/spec/models/episode_spec.rb index 954416b4..13c588f8 100644 --- a/spec/models/episode_spec.rb +++ b/spec/models/episode_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Episode do let(:show) { Show.create!(title: "Not Dead Yet", tmdb_tv_id: 42) } let(:season) { Season.create!(show:, tmdb_id: 42, name: "Season 1", season_number: 1, episode_count: 1) } - let(:episode) { Episode.create!(season:, air_date:, name: "Pilot", tmdb_id: 42, episode_number: 1) } + let(:episode) { described_class.create!(season:, air_date:, name: "Pilot", tmdb_id: 42, episode_number: 1) } describe "#available?" do context "when there is an air_date" do @@ -29,7 +29,7 @@ let(:air_date) { 3.days.from_now.to_date } it "returns false" do - expect(episode).to_not be_available + expect(episode).not_to be_available end end end @@ -38,7 +38,7 @@ let(:air_date) { nil } it "returns false" do - expect(episode).to_not be_available + expect(episode).not_to be_available end end end diff --git a/spec/models/season_review_spec.rb b/spec/models/season_review_spec.rb index c782d0e8..32739044 100644 --- a/spec/models/season_review_spec.rb +++ b/spec/models/season_review_spec.rb @@ -10,11 +10,11 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "anybody") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "anybody") other_human = Human.create!(handle: "Ashley", email: "ashley@example.com") - expect(SeasonReview.viewable_by(other_human)).to include(review) + expect(described_class.viewable_by(other_human)).to include(review) end end @@ -23,9 +23,9 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "anybody") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "anybody") - expect(SeasonReview.viewable_by(nil)).to include(review) + expect(described_class.viewable_by(nil)).to include(review) end end end @@ -36,9 +36,9 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "myself") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "myself") - expect(SeasonReview.viewable_by(human)).to include(review) + expect(described_class.viewable_by(human)).to include(review) end end @@ -47,10 +47,10 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "myself") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "myself") other_human = Human.create!(handle: "Ashley", email: "ashley@example.com") - expect(SeasonReview.viewable_by(other_human)).not_to include(review) + expect(described_class.viewable_by(other_human)).not_to include(review) end end @@ -59,9 +59,9 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "myself") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "myself") - expect(SeasonReview.viewable_by(nil)).not_to include(review) + expect(described_class.viewable_by(nil)).not_to include(review) end end end @@ -72,13 +72,13 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "mutuals") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "mutuals") other_human = Human.create!(handle: "ashley", email: "ashley@example.com") Follow.create!(follower_id: human.id, followee_id: other_human.id) Follow.create!(follower_id: other_human.id, followee_id: human.id) - expect(SeasonReview.viewable_by(other_human)).to include(review) + expect(described_class.viewable_by(other_human)).to include(review) end end @@ -87,12 +87,12 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "mutuals") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "mutuals") other_human = Human.create!(handle: "ashley", email: "ashley@example.com") Follow.create!(follower_id: other_human.id, followee_id: human.id) - expect(SeasonReview.viewable_by(other_human)).not_to include(review) + expect(described_class.viewable_by(other_human)).not_to include(review) end end @@ -101,12 +101,12 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "mutuals") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "mutuals") other_human = Human.create!(handle: "ashley", email: "ashley@example.com") Follow.create!(follower_id: human.id, followee_id: other_human.id) - expect(SeasonReview.viewable_by(other_human)).not_to include(review) + expect(described_class.viewable_by(other_human)).not_to include(review) end end @@ -115,9 +115,9 @@ human = Human.create!(handle: "marc", email: "marc@example.com") show = Show.create!(title: "Home Economics", tmdb_tv_id: 1) season = Season.create!(show:, name: "Season 1", season_number: 1, episode_count: 10, tmdb_id: 1) - review = SeasonReview.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "mutuals") + review = described_class.create!(author: human, season:, viewing: 1, body: "Not bad", visibility: "mutuals") - expect(SeasonReview.viewable_by(nil)).not_to include(review) + expect(described_class.viewable_by(nil)).not_to include(review) end end end diff --git a/spec/services/refresh_episodes_spec.rb b/spec/services/refresh_episodes_spec.rb index 876b4b61..b28bf886 100644 --- a/spec/services/refresh_episodes_spec.rb +++ b/spec/services/refresh_episodes_spec.rb @@ -26,7 +26,7 @@ tmdb_poster_path: "/ctTaOOAg9iZtvVBOyH2UE5ifBHg.jpg" ) - RefreshEpisodes.call(show, season) + described_class.call(show, season) expect(request).to have_been_requested expect(season.episodes.count).to be 3 @@ -76,7 +76,7 @@ episode_number: 3 ) - RefreshEpisodes.call(show, season) + described_class.call(show, season) expect(request).to have_been_requested expect(season.episodes.count).to be 3 @@ -120,7 +120,7 @@ episode_number: 2 ) - RefreshEpisodes.call(show, season) + described_class.call(show, season) expect(request).to have_been_requested expect(season.episodes.count).to be 3 @@ -170,7 +170,7 @@ episode_number: 3 ) - RefreshEpisodes.call(show, season) + described_class.call(show, season) expect(request).to have_been_requested expect(season.episodes.count).to be 3