1

在我的套房中,我有很多it块:

let(:user) { create(:user) }
let(:plan) { Plan.first }
let(:subscription) { build(:subscription, user: user ) }


it "something" do
  subscription.create_stripe_customer
  subscription.update_card valid_card_data
  subscription.change_plan_to plan
  login_as user
end

我怎么能把它弄干,这样我就不必在许多文件中复制所有这些行?

4

2 回答 2

1

您还可以创建一个方法,如

def prepare_subscription
    subscription.create_stripe_customer
    subscription.update_card valid_card_data
    subscription.change_plan_to plan
end

在你的 it 块中,像这样:

it "something" do
  prepare_subscription
  login_as user
end
于 2013-08-27T12:20:23.130 回答
0

You ain't checking value for that spec so it always green.

If you need prepare some data before test then you could put that code into helper and call it when needed in (for example) before block.

If you need check spec passing again and again then you could use shared examples.

于 2013-08-27T04:53:03.707 回答