Rspec:“它”和“指定”之间有什么区别?

时间:2013-03-07 20:47:33

标签: ruby-on-rails ruby-on-rails-3 rspec

假设我有这段代码:

require 'spec_helper'

  describe "authorization" do

    describe "for non-signed-in users" do
      let(:user) { FactoryGirl.create(:user) }

      describe "in the Users controller" do

      describe "submitting to the update action" do
        before { put user_path(user) }
        specify { response.should redirect_to(signin_path) }
      end
    end
  end
end

而不是:

  

指定{response.should redirect_to(signin_path)}

为什么我不能使用:

  

它的{response.should redirect_to(signin_path)}

1 个答案:

答案 0 :(得分:2)

AS ZippieJulianoapneadiving已声明:

指定 it

的别名

上下文 describe

的别名

您可以使用表单(:method){expectation}来调用主题上的方法:

let(:bar) { Bar.new }
subject { bar }

its(:foo) { should == 0 }

测试这个

class Bar
  def foo
    0
  end
end