entire rails environment? Because our business logic is in our active record models And we need rails to run tests against classes that inherit from ActiveRecord::Base Because we're breaking SRP
let(:basket) { Basket.create! } let(:basket_items) { [BasketItem.create!(:discount => 10), BasketItem.create!(:discount => 20) ]} it "should return the total discount" do basket = Basket.create! basket.basket_items = basket_items basket.total_discount.should == 30 end end end
describe DiscountCalculator do context "#total_discount" do it "should return the total discount" do basket = FakeBasket.new basket_items = [stub(:discount => 10), stub(:discount => 20)] basket.stub(:basket_items) { basket_items } basket.total_discount.should eq 30 end end end
do let(:items) { [stub(:discount => 10), stub(:discount => 20)] } it "should return the total discount" do calculator = DiscountCalculator.new calculator.total_discount(items).should eq 30 end end end