未定义的方法"获取"和"让"与Rspec 3 - rails 4

bvc*_*vcm 0 rspec ruby-on-rails capybara rspec3

我决定使用新的Rspec 3(+ capybara/factory_girl)开始一个新项目,并且在学习新语法时遇到了麻烦.现在我有

user_pages_spec.rb(功能)

scenario "Signing Up" do

        let(:submit) { "Sign up" }

        scenario "With valid information" do
            background do
                fill_in "Username", with: "bbvoncrumb"
                fill_in "Email", with: "bbvoncrumb@example.com"
                fill_in "Password", with: "foobar123"
                fill_in "Password confirmation", with: "foobar123"
            end

            scenario "should create a user" do
                expect { click_button submit }.to change(User, :count).by(1)
            end
        end
    end
Run Code Online (Sandbox Code Playgroud)

使用未定义的方法'let'失败.和:

static_pages_spec.rb(控制器)

describe StaticPagesController do

  describe "GET 'home'" do
    it "returns http success" do
      get :home
      expect(response).to be_success
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

使用"未定义的方法'获取'.(这只是默认的控制器规范)

pet*_*r_v 6

将现有项目从RSpec 2.x升级到3.0时遇到同样的问题.

它是通过明确的类型设置为我修复的.

你能试一试吗:

描述StaticPagesController,输入:: controller do

编辑:

我现在发现更多的结构原因和解决方案是在RSpec 3中,我需要添加:

config.infer_spec_type_from_file_location!

在spec_helper.rb的配置块中