1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/acceptance/stub_spec.rb
Avielle c716ce01b4 Replace 'girl' with 'bot' everywhere (#1051)
Also: add a deprecation warning to factory_girl, asking users to switch to
factory_bot

https://github.com/thoughtbot/factory_girl/issues/921
2017-10-20 15:20:28 -04:00

62 lines
1.2 KiB
Ruby

require 'spec_helper'
describe "a stubbed instance" do
include FactoryBot::Syntax::Methods
before do
define_model('User')
define_model('Post', user_id: :integer) do
belongs_to :user
end
FactoryBot.define do
factory :user
factory :post do
user
end
end
end
subject { build_stubbed(:post) }
it "acts as if it came from the database" do
should_not be_new_record
end
it "assigns associations and acts as if it is saved" do
expect(subject.user).to be_kind_of(User)
expect(subject.user).not_to be_new_record
end
end
describe "a stubbed instance overriding strategy" do
include FactoryBot::Syntax::Methods
before do
define_model('User')
define_model('Post', user_id: :integer) do
belongs_to :user
end
FactoryBot.define do
factory :user
factory :post do
association(:user, strategy: :build)
end
end
end
subject { build_stubbed(:post) }
it "acts as if it is saved in the database" do
should_not be_new_record
end
it "assigns associations and acts as if it is saved" do
expect(subject.user).to be_kind_of(User)
expect(subject.user).not_to be_new_record
end
end