mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Refactor aliases_spec.rb to more closely adhere to the Let's Not school of RSpec (#1338)
Refactor aliases_spec.rb to more closely adhere to the Let's Not school of RSpec
This commit is contained in:
parent
2e48817bad
commit
e98a4aae15
1 changed files with 16 additions and 17 deletions
|
@ -1,29 +1,28 @@
|
||||||
describe FactoryBot, "aliases" do
|
describe FactoryBot, "aliases" do
|
||||||
context "aliases for an attribute" do
|
it "for an attribute should include the original attribute and a version suffixed with '_id'" do
|
||||||
subject { FactoryBot.aliases_for(:test) }
|
aliases = FactoryBot.aliases_for(:test)
|
||||||
it { should include(:test) }
|
|
||||||
it { should include(:test_id) }
|
expect(aliases).to include(:test, :test_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "aliases for a foreign key" do
|
it "for a foreign key should include both the suffixed and un-suffixed variants" do
|
||||||
subject { FactoryBot.aliases_for(:test_id) }
|
aliases = FactoryBot.aliases_for(:test_id)
|
||||||
it { should include(:test) }
|
|
||||||
it { should include(:test_id) }
|
expect(aliases).to include(:test, :test_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "aliases for an attribute starting with an underscore" do
|
it "for an attribute which starts with an underscore should not include a non-underscored version" do
|
||||||
subject { FactoryBot.aliases_for(:_id) }
|
aliases = FactoryBot.aliases_for(:_id)
|
||||||
it { should_not include(:id) }
|
|
||||||
|
expect(aliases).not_to include(:id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe FactoryBot, "after defining an alias" do
|
describe FactoryBot, "after defining an alias" do
|
||||||
before do
|
it "the list of aliases should include a variant with no suffix at all, and one with an '_id' suffix" do
|
||||||
FactoryBot.aliases << [/(.*)_suffix/, '\1']
|
FactoryBot.aliases << [/(.*)_suffix/, '\1']
|
||||||
|
aliases = FactoryBot.aliases_for(:test_suffix)
|
||||||
|
|
||||||
|
expect(aliases).to include(:test, :test_suffix_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { FactoryBot.aliases_for(:test_suffix) }
|
|
||||||
|
|
||||||
it { should include(:test) }
|
|
||||||
it { should include(:test_suffix_id) }
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue