如何在rspec中打印let符号的值?

时间:2013-09-16 18:16:04

标签: rspec automation capybara

如果我的规格中有以下行

  include Rack::Test::Methods

  let(:competition_date) { Date.today+10.days }

如何在rspec中打印competition_date符号的值?

1 个答案:

答案 0 :(得分:2)

在RSpec中,let中定义的变量可在beforeit块中访问。所有内容都必须包含在describe块中,例如:

describe "let variables" do
  let(:competition_date) { Date.today+10.days }
  it "should be accessible within it blocks" do
    expect(competition_date).to be == Date.today+10.days
    puts competition_date
  end
end