1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Refactors strategy_calculator_spec.rb to conform to Let's Not style (#1351)

This commit is contained in:
Richie Thomas 2019-10-23 14:16:09 -07:00 committed by GitHub
parent a40b555cb0
commit ba3b937111
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,30 +1,24 @@
describe FactoryBot::StrategyCalculator do
let(:strategy) do
define_class("MyAwesomeClass")
it "returns the class passed when it is instantiated with a class" do
strategy = define_class("MyAwesomeClass")
calculator = FactoryBot::StrategyCalculator.new(strategy).strategy
expect(calculator).to eq strategy
end
context "when a class" do
subject { FactoryBot::StrategyCalculator.new(strategy).strategy }
it "finds the strategy by name when instantiated with a symbol" do
strategy = define_class("MyAwesomeClass")
allow(FactoryBot::Internal).to receive(:strategy_by_name).and_return(strategy)
FactoryBot::StrategyCalculator.new(:build).strategy
it "returns the class passed" do
expect(subject).to eq strategy
end
expect(FactoryBot::Internal).to have_received(:strategy_by_name).with(:build)
end
context "when a symbol" do
before do
allow(FactoryBot::Internal).to receive(:strategy_by_name).and_return(strategy)
end
it "returns the strategy found when instantiated with a symbol" do
strategy = define_class("MyAwesomeClass")
allow(FactoryBot::Internal).to receive(:strategy_by_name).and_return(strategy)
calculator = FactoryBot::StrategyCalculator.new(:build).strategy
subject { FactoryBot::StrategyCalculator.new(:build).strategy }
it "finds the strategy by name" do
subject
expect(FactoryBot::Internal).to have_received(:strategy_by_name).with(:build)
end
it "returns the strategy found" do
expect(subject).to eq strategy
end
expect(calculator).to eq strategy
end
end