Compare commits

..

1 Commits

Author SHA1 Message Date
Daniel O'Connor
b76cfd3957 Rubocop: RSpec/IncludeExamples 2026-04-23 13:31:16 +00:00
29 changed files with 66 additions and 56 deletions

View File

@@ -242,6 +242,12 @@ RSpec/BeforeAfterAll:
Exclude:
- 'spec/tasks/import_spec.rb'
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
RSpec/ContextMethod:
Exclude:
- 'spec/requests/api/v1/activities_request_spec.rb'
# Offense count: 299
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
@@ -293,6 +299,14 @@ RSpec/EmptyLineAfterExample:
RSpec/ExampleLength:
Max: 27
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: method_call, block
RSpec/ExpectChange:
Exclude:
- 'spec/models/crop_spec.rb'
# Offense count: 32
RSpec/ExpectInHook:
Exclude:
@@ -320,26 +334,6 @@ RSpec/HooksBeforeExamples:
Exclude:
- 'spec/features/crops/creating_a_crop_spec.rb'
# Offense count: 53
# This cop supports unsafe autocorrection (--autocorrect-all).
RSpec/IncludeExamples:
Exclude:
- 'spec/features/conversations/index_spec.rb'
- 'spec/features/crops/alternate_name_spec.rb'
- 'spec/features/crops/browse_crops_spec.rb'
- 'spec/features/crops/creating_a_crop_spec.rb'
- 'spec/features/crops/crop_photos_spec.rb'
- 'spec/features/crops/delete_crop_spec.rb'
- 'spec/features/gardens/actions_spec.rb'
- 'spec/features/gardens/adding_gardens_spec.rb'
- 'spec/features/gardens/index_spec.rb'
- 'spec/features/likeable_spec.rb'
- 'spec/features/signout_spec.rb'
- 'spec/models/crop_spec.rb'
- 'spec/support/feature_helpers.rb'
- 'spec/views/photos/show.html.haml_spec.rb'
- 'spec/views/seeds/index.rss.haml_spec.rb'
# Offense count: 37
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
RSpec/IndexedLet:
@@ -472,6 +466,23 @@ RSpec/VerifiedDoubles:
- 'spec/controllers/gardens_controller_spec.rb'
- 'spec/views/devise/shared/_links_spec.rb'
# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ResponseMethods.
# ResponseMethods: response, last_response
RSpecRails/HaveHttpStatus:
Exclude:
- 'spec/controllers/api/v1/plantings_controller_spec.rb'
- 'spec/controllers/harvests_controller_spec.rb'
- 'spec/controllers/likes_controller_spec.rb'
- 'spec/requests/harvests_spec.rb'
# Offense count: 17
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Inferences.
RSpecRails/InferredSpecType:
Enabled: false
# Offense count: 30
# Configuration parameters: Database.
# SupportedDatabases: mysql, postgresql
@@ -591,6 +602,7 @@ Rails/RedundantActiveRecordAllMethod:
- 'app/controllers/scientific_names_controller.rb'
- 'spec/features/members/deletion_spec.rb'
- 'spec/features/percy/percy_spec.rb'
- 'spec/models/harvest_spec.rb'
# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe Api::V1::PlantingsController do
RSpec.describe Api::V1::PlantingsController, type: :controller do
subject { JSON.parse response.body }
let!(:member) { create(:member) }
@@ -42,7 +42,7 @@ RSpec.describe Api::V1::PlantingsController do
it { expect(matching_planting).to include('id' => my_planting.id.to_s) }
it { expect(matching_planting['attributes']).to eq expected_attributes }
it { expect(response).to have_http_status :ok }
it { expect(response.status).to eq 200 }
end
context 'with photo' do
@@ -81,7 +81,7 @@ RSpec.describe Api::V1::PlantingsController do
it { expect(matching_planting).to include('id' => my_planting.id.to_s) }
it { expect(matching_planting['attributes']).to eq expected_attributes }
it { expect(response).to have_http_status :ok }
it { expect(response.status).to eq 200 }
end
end
end

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe GardenTypesController do
RSpec.describe GardenTypesController, type: :controller do
include Devise::Test::ControllerHelpers
let(:valid_params) { { name: 'My second GardenType' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe GardensController do
RSpec.describe GardensController, type: :controller do
include Devise::Test::ControllerHelpers
let(:valid_params) { { name: 'My second Garden' } }

View File

@@ -51,7 +51,7 @@ describe HarvestsController, :search do
describe "generates a csv" do
before { get :index, format: "csv" }
it { expect(response).to have_http_status :ok }
it { expect(response.status).to eq 200 }
end
end

View File

@@ -19,7 +19,7 @@ describe LikesController do
it { JSON.parse(response.body)["description"] == "1 like" }
describe "Liking someone else's post" do
it { expect(response).to have_http_status(:created) }
it { expect(response.code).to eq('201') }
end
end
@@ -29,14 +29,14 @@ describe LikesController do
it { expect(response.content_type).to eq "application/json; charset=utf-8" }
describe "un-liking something i liked before" do
it { expect(response).to have_http_status(:ok) }
it { expect(response.code).to eq('200') }
it { JSON.parse(response.body)["description"] == "0 likes" }
end
describe "Deleting someone else's like" do
let(:like) { create(:like) }
it { expect(response).to have_http_status(:forbidden) }
it { expect(response.code).to eq('403') }
it { JSON.parse(response.body)["error"] == "Unable to like" }
end
end

View File

@@ -2,7 +2,7 @@
FactoryBot.define do
factory :comment do
commentable factory: %i(post)
association :commentable, factory: :post
author
sequence(:body) { |n| "OMG LOL #{n}" }
# because our commenters are more polite than YouTube's

View File

@@ -1,5 +1,3 @@
# frozen_string_literal: true
FactoryBot.define do
factory :garden_collaborator do
garden

View File

@@ -10,7 +10,7 @@ FactoryBot.define do
body { "MyText" }
read { false }
notifiable factory: %i(post)
association :notifiable, factory: :post
factory :no_email_notification do
recipient { FactoryBot.create(:no_email_notifications_member) }

View File

@@ -26,7 +26,7 @@ describe "Harvesting a crop", :js, :search do
within "form#new_harvest" do
choose plant_part.name
fill_in "When?", with: Time.zone.local(2014, 6, 15)
fill_in "When?", with: Time.new(2014, 6, 15)
fill_in "How many?", with: 42
fill_in "Weighing (in total)", with: 42
fill_in "Notes", with: "It's killer."

View File

@@ -96,7 +96,7 @@ describe "member deletion", :flaky do
end
describe 'member exists but is marked deleted' do
subject { Member.find(member.id) }
subject { Member.all.find(member.id) }
it { expect(subject).to eq member }
it { expect(subject.discarded?).to be true }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
describe 'Test with visual testing', :js do
describe 'Test with visual testing', :js, type: :feature do
# Use the same random seed every time so our random data is the same
# on every run, so doesn't trigger percy to see changes
before { Faker::Config.random = Random.new(42) }

View File

@@ -12,7 +12,7 @@ require 'rails_helper'
# end
# end
# end
RSpec.describe ButtonsHelper do
RSpec.describe ButtonsHelper, type: :helper do
before { allow(self).to receive(:can?).and_return(true) }
let(:garden) { create(:garden) }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe EventHelper do
RSpec.describe EventHelper, type: :helper do
subject { resolve_model(event) }
let(:planting) { create(:planting) }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe CropCompanion do
RSpec.describe CropCompanion, type: :model do
it 'has a crop' do
cc = described_class.new
cc.crop_a = create :tomato

View File

@@ -554,7 +554,7 @@ describe Crop do
end
it "destroys companion links" do
expect { crop_a.destroy }.to change(CropCompanion, :count).from(2).to(0)
expect { crop_a.destroy }.to change { CropCompanion.count }.from(2).to(0)
end
end

View File

@@ -144,7 +144,7 @@ describe Harvest do
it 'lists most recent harvests first' do
@h1 = create(:harvest, created_at: 1.day.ago)
@h2 = create(:harvest, created_at: 1.hour.ago)
expect(described_class.order(created_at: :desc)).to eq [@h2, @h1]
expect(described_class.all.order(created_at: :desc)).to eq [@h2, @h1]
end
end

View File

@@ -70,8 +70,8 @@ include Warden::Test::Helpers
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Rails.root.glob("spec/support/**/*.rb").sort.each { |f| require f }
Rails.root.glob("spec/features/shared_examples/**/*.rb").sort.each { |f| require f }
Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }
Dir[Rails.root.join("spec/features/shared_examples/**/*.rb")].sort.each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.

View File

@@ -2,8 +2,8 @@
require 'rails_helper'
RSpec.describe 'Activities' do
subject { response.parsed_body }
RSpec.describe 'Activities', type: :request do
subject { JSON.parse response.body }
let(:member) { create(:member) }
let(:token) do
@@ -60,7 +60,7 @@ RSpec.describe 'Activities' do
end
end
describe '#update' do
context '#update' do
let(:params) do
{
'data' => {

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Crops' do
RSpec.describe 'Crops', type: :request do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Gardens' do
RSpec.describe 'Gardens', type: :request do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Harvests' do
RSpec.describe 'Harvests', type: :request do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Members' do
RSpec.describe 'Members', type: :request do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Photos' do
RSpec.describe 'Photos', type: :request do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Plantings' do
RSpec.describe 'Plantings', type: :request do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Seeds' do
RSpec.describe 'Seeds', type: :request do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe "GardenTypes" do
RSpec.describe "GardenTypes", type: :request do
describe "GET /garden_types" do
it "works! (now write some real specs)" do
get garden_types_path

View File

@@ -6,7 +6,7 @@ describe "Harvests" do
describe "GET /harvests" do
it "works! (now write some real specs)" do
get harvests_path
expect(response).to have_http_status :ok
expect(response.status).to be 200
end
end
end

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
describe "places/_map_attribution.html.haml" do
describe "places/_map_attribution.html.haml", type: :view do
before do
render
end