-
Notifications
You must be signed in to change notification settings - Fork 3
/
fabricator_shorthand_spec.rb
49 lines (41 loc) · 1.26 KB
/
fabricator_shorthand_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
require "spec_helper"
describe RuboCop::Cop::Discourse::FabricatorShorthand, :config do
subject(:cop) { described_class.new(config) }
let(:config) { RuboCop::Config.new }
it "registers an offense when not using the fabricator shorthand" do
expect_offense(<<~RUBY)
RSpec.describe "Foo" do
fab!(:foo) { Fabricate(:foo) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:foo)`
end
RUBY
end
it "does not register an offense when the fabricator has attributes" do
expect_no_offenses(<<~RUBY)
RSpec.describe "Foo" do
fab!(:foo) { Fabricate(:foo, bar: 1) }
end
RUBY
end
it "does not register an offense when the identifier doesn't match" do
expect_no_offenses(<<~RUBY)
RSpec.describe "Foo" do
fab!(:bar) { Fabricate(:foo) }
end
RUBY
end
it "supports autocorrect" do
expect_offense(<<~RUBY)
RSpec.describe "Foo" do
fab!(:foo) { Fabricate(:foo) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:foo)`
end
RUBY
expect_correction(<<~RUBY)
RSpec.describe "Foo" do
fab!(:foo)
end
RUBY
end
end