RSpec弃用行为'让'

时间:2015-07-08 08:46:52

标签: ruby-on-rails rspec

我在使用Rspec-rails 2.14运行RSpec测试时收到这些警告。我想升级到RSpec 3以查看是否有任何性能改进,但我认为这些都会因为此警告而失败?我也在使用工厂女孩。

This is deprecated behavior that will not be supported in RSpec 3.

`let` and `subject` declarations are not intended to be called
in a `before(:all)` hook, as they exist to define state that
is reset between each example, while `before(:all)` exists to
define state that is shared across examples in an example group.
WARNING: let declaration `fa` accessed in a `before(:all)` hook at:
  D:/RailsApps/uwb/spec/models/fa_commercial_spec.rb:77:in `block (2 level
s) in <top (required)>'

这是一个例子,如何改变它以便它在RSpec 3中没问题?

require 'spec_helper'

describe 'FaCommercial' do
  let(:admin_user) {create(:user_admin_dev)}
  let(:template) {create :fa_commercial_template}
  let(:fa) {create :fa_commercial, fa_template: template}
  let(:stmt_template_bal_sheet) {create :fa_commercial_stmt_template_bal_sheet, fa_template: template}
  let(:stmt_template_cash_flow) {create :fa_commercial_stmt_template_cash_flow, fa_template: template}
  let(:stmt_template_income_stmt) {create :fa_commercial_stmt_template_income_stmt, fa_template: template}
  let(:stmt_template_ratios) {create :fa_commercial_stmt_template_ratios, fa_template: template}

  before(:all) do
    admin_user
    stmt_template_bal_sheet
    stmt_template_cash_flow
    stmt_template_income_stmt
    stmt_template_ratios
..........

1 个答案:

答案 0 :(得分:0)

错误不言自明。

`let` and `subject` declarations are not intended to be called
in a `before(:all)` hook

您可以查看RSpec文档以了解事物的工作原理,然后,您将能够重构场景以使其正常工作。