Lint: RSpec/DescribedClass

This commit is contained in:
Jared Beck 2017-04-01 00:51:21 -04:00
parent 3df7dc27d2
commit f7945086c5
4 changed files with 36 additions and 59 deletions

View File

@ -18,9 +18,6 @@ Style/FrozenStringLiteralComment:
RSpec/BeforeAfterAll:
Enabled: false
RSpec/DescribedClass:
Enabled: false
RSpec/ExampleWording:
Enabled: false

View File

@ -1,36 +1,16 @@
require "spec_helper"
describe PaperTrail::VERSION do
describe "Constants" do
subject { PaperTrail::VERSION }
describe "MAJOR" do
it { is_expected.to be_const_defined(:MAJOR) }
it { expect(subject::MAJOR).to be_a(Integer) }
end
describe "MINOR" do
it { is_expected.to be_const_defined(:MINOR) }
it { expect(subject::MINOR).to be_a(Integer) }
end
describe "TINY" do
it { is_expected.to be_const_defined(:TINY) }
it { expect(subject::TINY).to be_a(Integer) }
end
describe "PRE" do
it { is_expected.to be_const_defined(:PRE) }
if PaperTrail::VERSION::PRE
it { expect(subject::PRE).to be_instance_of(String) }
end
end
describe "STRING" do
it { is_expected.to be_const_defined(:STRING) }
it { expect(subject::STRING).to be_instance_of(String) }
it "should join the numbers into a period separated string" do
expect(subject::STRING).to eq(
[subject::MAJOR, subject::MINOR, subject::TINY, subject::PRE].compact.join(".")
)
end
RSpec.describe PaperTrail::VERSION do
describe "STRING" do
it "should join the numbers into a period separated string" do
expect(described_class::STRING).to eq(
[
described_class::MAJOR,
described_class::MINOR,
described_class::TINY,
described_class::PRE
].compact.join(".")
)
end
end
end

View File

@ -29,7 +29,7 @@ RSpec.describe CustomYamlSerializer do
context(".load") do
it("deserializes YAML to Ruby, removing pairs with blank keys or values") do
expect(CustomYamlSerializer.load(word_hash.to_yaml)).to eq(
expect(described_class.load(word_hash.to_yaml)).to eq(
word_hash.reject { |k, v| (k.blank? || v.blank?) }
)
end
@ -37,7 +37,7 @@ RSpec.describe CustomYamlSerializer do
context(".dump") do
it("serializes Ruby to YAML, removing pairs with nil values") do
expect(CustomYamlSerializer.dump(word_hash)).to eq(
expect(described_class.dump(word_hash)).to eq(
word_hash.reject { |_k, v| v.nil? }.to_yaml
)
end

View File

@ -1,84 +1,84 @@
require "rails_helper"
describe PaperTrail do
RSpec.describe PaperTrail do
context "when enabled" do
it "affects all threads" do
Thread.new { PaperTrail.enabled = false }.join
assert_equal false, PaperTrail.enabled?
Thread.new { described_class.enabled = false }.join
assert_equal false, described_class.enabled?
end
after do
PaperTrail.enabled = true
described_class.enabled = true
end
end
context "default" do
it "should have versioning off by default" do
expect(PaperTrail).not_to be_enabled
expect(described_class).not_to be_enabled
end
it "should turn versioning on in a `with_versioning` block" do
expect(PaperTrail).not_to be_enabled
expect(described_class).not_to be_enabled
with_versioning do
expect(PaperTrail).to be_enabled
expect(described_class).to be_enabled
end
expect(PaperTrail).not_to be_enabled
expect(described_class).not_to be_enabled
end
context "error within `with_versioning` block" do
it "should revert the value of `PaperTrail.enabled?` to it's previous state" do
expect(PaperTrail).not_to be_enabled
expect(described_class).not_to be_enabled
expect { with_versioning { raise } }.to raise_error(RuntimeError)
expect(PaperTrail).not_to be_enabled
expect(described_class).not_to be_enabled
end
end
end
context "`versioning: true`", versioning: true do
it "should have versioning on by default" do
expect(PaperTrail).to be_enabled
expect(described_class).to be_enabled
end
it "should keep versioning on after a with_versioning block" do
expect(PaperTrail).to be_enabled
expect(described_class).to be_enabled
with_versioning do
expect(PaperTrail).to be_enabled
expect(described_class).to be_enabled
end
expect(PaperTrail).to be_enabled
expect(described_class).to be_enabled
end
end
context "`with_versioning` block at class level" do
it { expect(PaperTrail).not_to be_enabled }
it { expect(described_class).not_to be_enabled }
with_versioning do
it "should have versioning on by default" do
expect(PaperTrail).to be_enabled
expect(described_class).to be_enabled
end
end
it "should not leak the `enabled?` state into successive tests" do
expect(PaperTrail).not_to be_enabled
expect(described_class).not_to be_enabled
end
end
describe ".version" do
it { expect(PaperTrail).to respond_to(:version) }
it { expect(PaperTrail.version).to eq(PaperTrail::VERSION::STRING) }
it { expect(described_class).to respond_to(:version) }
it { expect(described_class.version).to eq(described_class::VERSION::STRING) }
end
describe ".whodunnit" do
before(:all) { PaperTrail.whodunnit = "foobar" }
before(:all) { described_class.whodunnit = "foobar" }
it "should get set to `nil` by default" do
expect(PaperTrail.whodunnit).to be_nil
expect(described_class.whodunnit).to be_nil
end
end
describe ".controller_info" do
before(:all) { ::PaperTrail.controller_info = { foo: "bar" } }
before(:all) { described_class.controller_info = { foo: "bar" } }
it "should get set to an empty hash before each test" do
expect(PaperTrail.controller_info).to eq({})
expect(described_class.controller_info).to eq({})
end
end
end