Skip to content

Commit

Permalink
Enable RSpec/SubjectDeclaration Rubocop (decidim#9213)
Browse files Browse the repository at this point in the history
* Enabling Rubocop RSpec/SubjectDeclaration

* Running linters

* Fixing failing spec
  • Loading branch information
alecslupu authored May 4, 2022
1 parent 45c74ca commit 9ef90b4
Show file tree
Hide file tree
Showing 66 changed files with 112 additions and 104 deletions.
3 changes: 0 additions & 3 deletions .rubocop-disabled.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
RSpec/SubjectDeclaration:
Enabled: false

RSpec/ExcessiveDocstringSpacing:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion decidim-admin/spec/lib/admin/form_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module Decidim
describe Admin::FormBuilder do
let(:subject) { Nokogiri::HTML(output) }
subject { Nokogiri::HTML(output) }

let(:helper) { Class.new(ActionView::Base).new(ActionView::LookupContext.new(ActionController::Base.view_paths), {}, []) }
let(:available_locales) { %w(ca en de-CH) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim::Admin::Import
describe Creator do
let(:subject) { described_class.new(unknown_resource) }
subject { described_class.new(unknown_resource) }
let(:unknown_resource) { { field: "foo" } }

it "cant finish without implementation for a resource" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim::Admin::Import::Readers
describe Base do
let(:subject) { described_class.new(file) }
subject { described_class.new(file) }
let(:file) { Decidim::Dev.test_file("Exampledocument.pdf", "application/pdf") }

describe "#read_rows" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim::Admin::Import::Readers
describe CSV do
let(:subject) { described_class.new(file) }
subject { described_class.new(file) }
let(:csv_data) do
<<~CSV
id;title;detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim::Admin::Import::Readers
describe JSON do
let(:subject) { described_class.new(file) }
subject { described_class.new(file) }
let(:json_data) do
<<~JSON
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim::Admin::Import::Readers
describe XLSX do
let(:subject) { described_class.new(file) }
subject { described_class.new(file) }
let(:file) { Decidim::Dev.test_file("test_excel.xlsx", Decidim::Admin::Import::Readers::XLSX::MIME_TYPE) }

describe "#read_rows" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ module Decidim
module Assemblies
describe CurrentComponent do
let(:request) { double(params: params, env: env) }
let(:subject) { described_class.new(manifest) }
let(:params) { {} }
let(:manifest) { Decidim.find_component_manifest("dummy") }

let(:organization) do
create(:organization)
end

let(:current_assembly) { create(:assembly, organization: organization) }
let(:other_assembly) { create(:assembly, organization: organization) }

let(:env) do
{ "decidim.current_organization" => organization }
end

subject { described_class.new(manifest) }

context "when the params contain an assembly id" do
before do
params["assembly_slug"] = current_assembly.id.to_s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
module Decidim::Assemblies
describe AssemblySerializer do
let(:resource) { create(:assembly) }
let(:subject) { described_class.new(resource) }

subject { described_class.new(resource) }

describe "#serialize" do
it "includes the assembly data" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
module Decidim::Budgets
describe DownloadYourDataBudgetsOrderSerializer do
let(:resource) { create(:order) }
let(:serialized) { subject.serialize }
let!(:projects) { create_list(:project, 2, budget: resource.budget, budget_amount: 25_000_000) }

let(:subject) { described_class.new(resource) }
let(:serialized) { subject.serialize }
subject { described_class.new(resource) }

describe "#serialize" do
it "includes the id" do
Expand Down
9 changes: 5 additions & 4 deletions decidim-budgets/spec/serializers/project_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
module Decidim::Budgets
describe ProjectSerializer do
let(:budget) { create(:budget) }
let(:category) { create(:category, participatory_space: budget.component.participatory_space) }
let(:scope) { create(:scope, organization: category.participatory_space.organization) }
let(:project) { create(:project, budget: budget, category: category, scope: scope) }
let(:subject) { described_class.new(project) }
let(:serialized) { subject.run }
let(:attachment) { create :attachment, attached_to: project }
let(:proposals_component) { create(:component, manifest_name: "proposals", participatory_space: project.participatory_space) }
let(:proposals) { create_list(:proposal, 3, component: proposals_component) }
let(:category) { create(:category, participatory_space: budget.component.participatory_space) }
let(:scope) { create(:scope, organization: category.participatory_space.organization) }
let(:project) { create(:project, budget: budget, category: category, scope: scope) }

subject { described_class.new(project) }

describe "#serializer" do
before { project.link_resources(proposals, "included_proposals") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Decidim
module Comments
describe CommentSerializer do
let(:comment) { create(:comment) }
let(:subject) { described_class.new(comment) }

subject { described_class.new(comment) }

describe "#serialize" do
it "includes the id" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module Decidim
module Comments
describe CommentVoteSerializer do
let(:comment) { create(:comment) }
let(:serialized) { subject.serialize }
let(:resource) { create(:comment_vote, comment: comment) }

let(:subject) { described_class.new(resource) }
let(:serialized) { subject.serialize }
subject { described_class.new(resource) }

describe "#serialize" do
it "includes the id" do
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/spec/lib/decidim/comments/export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Decidim
module Comments
describe Export do
let(:subject) { described_class }
subject { described_class }
let!(:component) { create(:component, manifest_name: "dummy") }
let!(:dummy_resources) { create_list(:dummy_resource, 2, component: component) }
let!(:comments) { create_list(:comment, 5, commentable: dummy_resources[1], root_commentable: dummy_resources[1]) }
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/spec/models/seed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Decidim
module Comments
describe Seed do
let(:subject) { Decidim::Comments::Seed }
subject { described_class }

describe "#comments_for(resource)" do
it "creates comments for a page if one is given" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ module Decidim
module Conferences
describe CurrentComponent do
let(:request) { double(params: params, env: env) }
let(:subject) { described_class.new(manifest) }
let(:params) { {} }
let(:manifest) { Decidim.find_component_manifest("dummy") }

let(:organization) do
create(:organization)
end

let(:current_conference) { create(:conference, organization: organization) }
let(:other_conference) { create(:conference, organization: organization) }

let(:env) do
{ "decidim.current_organization" => organization }
end

subject { described_class.new(manifest) }

context "when the params contain an conference id" do
before do
params["conference_slug"] = current_conference.id.to_s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ module Decidim::Conferences
let(:mail) { described_class.diploma(conference, user) }

describe "diploma" do
let(:subject) { "has been sent" }
let(:mail_subject) { "has been sent" }
let(:body) { "in the attachment" }

it "expect subject and body" do
expect(mail.subject).to include(subject)
expect(mail.subject).to include(mail_subject)
expect(mail.body.encoded).to match(body)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
module Decidim::Conferences
describe ConferenceRegistrationSerializer do
let(:conference_registration) { create(:conference_registration) }
let(:subject) { described_class.new(conference_registration) }

subject { described_class.new(conference_registration) }

describe "#serialize" do
it "includes the id" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
module Decidim::Conferences
describe DownloadYourDataConferenceInviteSerializer do
let(:resource) { build_stubbed(:conference_invite) }
let(:subject) { described_class.new(resource) }

subject { described_class.new(resource) }

describe "#serialize" do
it "includes the invite data" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
module Decidim::Conferences
describe DownloadYourDataConferenceRegistrationSerializer do
let(:resource) { create(:conference_registration) }
let(:subject) { described_class.new(resource) }

subject { described_class.new(resource) }

describe "#serialize" do
it "includes the id" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Decidim
module Consultations
describe MultipleVoteQuestion do
let(:subject) { described_class.new(form, user) }
subject { described_class.new(form, user) }

let(:organization) { create :organization }
let(:consultation) { create :consultation, organization: organization }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Decidim
module Consultations
describe UnvoteQuestion do
let(:subject) { described_class.new(question, user) }
subject { described_class.new(question, user) }

let(:organization) { create :organization }
let(:consultation) { create :consultation, organization: organization }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Decidim
module Consultations
describe VoteQuestion do
let(:subject) { described_class.new(form) }
subject { described_class.new(form) }

let(:organization) { create :organization }
let(:consultation) { create :consultation, organization: organization }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:locale) { "ca" }

it "uses the user's locale" do
expect(mail.subject).to eq(subject)
expect(mail.subject).to eq(mail_subject)
expect(mail.body.encoded).to match(body)
end
end
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/spec/lib/common_passwords_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe CommonPasswords do
let(:subject) do
subject do
Class.new(described_class) do
def self.common_passwords_path
Rails.root.join("tmp/common-passwords.txt")
Expand Down
3 changes: 2 additions & 1 deletion decidim-core/spec/lib/components/current_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
module Decidim
describe CurrentComponent do
let(:request) { double(params: params, env: env) }
let(:subject) { described_class.new(manifest) }
let(:params) { {} }
let(:manifest) { Decidim.find_component_manifest("dummy") }

subject { described_class.new(manifest) }

context "when the env does not contain a current organization" do
let(:env) do
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe DownloadYourDataSerializers::DownloadYourDataConversationSerializer do
let(:subject) { described_class.new(conversation) }
subject { described_class.new(conversation) }

let(:organization) { create(:organization) }
let(:user) { create :user, :confirmed, organization: organization }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe DownloadYourDataSerializers::DownloadYourDataFollowSerializer do
let(:subject) { described_class.new(resource) }
subject { described_class.new(resource) }
let(:resource) { build(:follow) }

let(:serialized) { subject.serialize }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe DownloadYourDataSerializers::DownloadYourDataIdentitySerializer do
let(:subject) { described_class.new(resource) }
subject { described_class.new(resource) }
let(:user) { create(:user) }
let(:organization) { user&.organization }
let(:provider) { "facebook" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe DownloadYourDataSerializers::DownloadYourDataNotificationSerializer do
let(:subject) { described_class.new(resource) }
subject { described_class.new(resource) }
let(:resource) { build(:notification) }

let(:serialized) { subject.serialize }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe DownloadYourDataSerializers::DownloadYourDataParticipatorySpacePrivateUserSerializer do
let(:subject) { described_class.new(resource) }
subject { described_class.new(resource) }
let(:resource) { build(:participatory_space_private_user) }

let(:serialized) { subject.serialize }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe DownloadYourDataSerializers::DownloadYourDataReportSerializer do
let(:subject) { described_class.new(resource) }
subject { described_class.new(resource) }

let(:organization) { create(:organization) }
let(:user) { create(:user, organization: organization) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe DownloadYourDataSerializers::DownloadYourDataUserGroupSerializer do
let(:subject) { described_class.new(resource) }
subject { described_class.new(resource) }
let(:resource) { create(:user_group) }

let(:serialized) { subject.serialize }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe DownloadYourDataSerializers::DownloadYourDataUserSerializer do
let(:subject) { described_class.new(resource) }
subject { described_class.new(resource) }
let(:resource) { create(:user) }

let(:serialized) { subject.serialize }
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/spec/lib/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe Env do
let(:subject) { described_class.new(name, default) }
subject { described_class.new(name, default) }
let(:name) { "TEST_ENV_VAR" }
let(:value) { nil }
let(:default) { nil }
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/spec/lib/exporters/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Decidim
describe Exporters::Serializer do
let(:subject) { described_class.new(resource) }
subject { described_class.new(resource) }
let(:resource) { OpenStruct.new(id: 1, name: "John") }

describe "#serialize" do
Expand Down
4 changes: 1 addition & 3 deletions decidim-core/spec/lib/fingerprintable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def body
end
end

let(:subject) do
klass.new
end
subject { klass.new }

context "when provided with fields" do
before do
Expand Down
Loading

0 comments on commit 9ef90b4

Please sign in to comment.