Enable RSpec/VerifiedDoubles cop, fix issues & stash one

Can't figureout solution for offense at spec/models/verification/management/email_spec.rb
 so its stashed at .rubocop_todo.yml

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubles
This commit is contained in:
Bertocq
2018-01-07 18:47:19 +01:00
parent 95e86eafbb
commit 830bb37189
4 changed files with 24 additions and 13 deletions

View File

@@ -180,3 +180,6 @@ RSpec/SingleArgumentMessageChain:
RSpec/SubjectStub: RSpec/SubjectStub:
Enabled: true Enabled: true
RSpec/VerifiedDoubles:
Enabled: true

View File

@@ -805,3 +805,9 @@ RSpec/DescribedClass:
Exclude: Exclude:
- 'spec/controllers/concerns/has_filters_spec.rb' - 'spec/controllers/concerns/has_filters_spec.rb'
- 'spec/controllers/concerns/has_orders_spec.rb' - 'spec/controllers/concerns/has_orders_spec.rb'
# Offense count: 1
# Configuration parameters: IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/models/verification/management/email_spec.rb'

View File

@@ -15,8 +15,8 @@ RSpec.describe CommentsHelper, type: :helper do
describe '#user_level_class' do describe '#user_level_class' do
def comment_double(as_administrator: false, as_moderator: false, official: false) def comment_double(as_administrator: false, as_moderator: false, official: false)
user = double official?: official, official_level: 'Y' user = instance_double('User', official?: official, official_level: 'Y')
double as_administrator?: as_administrator, as_moderator?: as_moderator, user: user instance_double('Comment', as_administrator?: as_administrator, as_moderator?: as_moderator, user: user)
end end
it 'returns is-admin for comment done as administrator' do it 'returns is-admin for comment done as administrator' do
@@ -47,14 +47,14 @@ RSpec.describe CommentsHelper, type: :helper do
describe '#comment_author_class' do describe '#comment_author_class' do
it 'returns is-author if author is the commenting user' do it 'returns is-author if author is the commenting user' do
author_id = 42 author_id = 42
comment = double user_id: author_id comment = instance_double('Comment', user_id: author_id)
expect(helper.comment_author_class(comment, author_id)).to eq('is-author') expect(helper.comment_author_class(comment, author_id)).to eq('is-author')
end end
it 'returns an empty string if commenter is not the author' do it 'returns an empty string if commenter is not the author' do
author_id = 42 author_id = 42
comment = double user_id: author_id - 1 comment = instance_double('Comment', user_id: author_id - 1)
expect(helper.comment_author_class(comment, author_id)).to eq('') expect(helper.comment_author_class(comment, author_id)).to eq('')
end end

View File

@@ -1,39 +1,41 @@
require 'rails_helper' require 'rails_helper'
describe Verification::Management::Document do describe Verification::Management::Document do
let(:min_age) { User.minimum_required_age }
let(:over_minium_age_date_of_birth) { Date.new((min_age + 10).years.ago.year, 12, 31) }
let(:under_minium_age_date_of_birth) { Date.new(min_age.years.ago.year, 12, 31) }
let(:just_minium_age_date_of_birth) { Date.new(min_age.years.ago.year, min_age.years.ago.month, min_age.years.ago.day) }
describe "#valid_age?" do describe "#valid_age?" do
it "returns false when the user is younger than the user's minimum required age" do it "returns false when the user is younger than the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31)) census_response = instance_double('CensusApi::Response', date_of_birth: under_minium_age_date_of_birth)
expect(described_class.new.valid_age?(census_response)).to be false expect(described_class.new.valid_age?(census_response)).to be false
end end
it "returns true when the user has the user's minimum required age" do it "returns true when the user has the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 16.years.ago.month, 16.years.ago.day)) census_response = instance_double('CensusApi::Response', date_of_birth: just_minium_age_date_of_birth)
expect(described_class.new.valid_age?(census_response)).to be true expect(described_class.new.valid_age?(census_response)).to be true
end end
it "returns true when the user is older than the user's minimum required age" do it "returns true when the user is older than the user's minimum required age" do
census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31)) census_response = instance_double('CensusApi::Response', date_of_birth: over_minium_age_date_of_birth)
expect(described_class.new.valid_age?(census_response)).to be true expect(described_class.new.valid_age?(census_response)).to be true
end end
end end
describe "#under_age?" do describe "#under_age?" do
it "returns true when the user is younger than the user's minimum required age" do it "returns true when the user is younger than the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31)) census_response = instance_double('CensusApi::Response', date_of_birth: under_minium_age_date_of_birth)
expect(described_class.new.under_age?(census_response)).to be true expect(described_class.new.under_age?(census_response)).to be true
end end
it "returns false when the user is user's minimum required age" do it "returns false when the user is user's minimum required age" do
date_of_birth = Date.new(User.minimum_required_age.years.ago.year, census_response = instance_double('CensusApi::Response', date_of_birth: just_minium_age_date_of_birth)
User.minimum_required_age.years.ago.month,
User.minimum_required_age.years.ago.day)
census_response = double(date_of_birth: date_of_birth)
expect(described_class.new.under_age?(census_response)).to be false expect(described_class.new.under_age?(census_response)).to be false
end end
it "returns false when the user is older than user's minimum required age" do it "returns false when the user is older than user's minimum required age" do
census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31)) census_response = instance_double('CensusApi::Response', date_of_birth: over_minium_age_date_of_birth)
expect(described_class.new.under_age?(census_response)).to be false expect(described_class.new.under_age?(census_response)).to be false
end end
end end