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 describe FactoryBot::StrategyCalculator do
let(:strategy) do it "returns the class passed when it is instantiated with a class" do
define_class("MyAwesomeClass") strategy = define_class("MyAwesomeClass")
calculator = FactoryBot::StrategyCalculator.new(strategy).strategy
expect(calculator).to eq strategy
end end
context "when a class" do it "finds the strategy by name when instantiated with a symbol" do
subject { FactoryBot::StrategyCalculator.new(strategy).strategy } 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(FactoryBot::Internal).to have_received(:strategy_by_name).with(:build)
expect(subject).to eq strategy
end
end end
context "when a symbol" do it "returns the strategy found when instantiated with a symbol" do
before do strategy = define_class("MyAwesomeClass")
allow(FactoryBot::Internal).to receive(:strategy_by_name).and_return(strategy) allow(FactoryBot::Internal).to receive(:strategy_by_name).and_return(strategy)
end calculator = FactoryBot::StrategyCalculator.new(:build).strategy
subject { FactoryBot::StrategyCalculator.new(:build).strategy } expect(calculator).to eq 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
end end
end end