我想做这样的事情:
feature "sign-up" do
  before {visit signup_path}
  let(:submit) {"Create my account"}
  feature "with invalid information" do
    scenario "should not create a user" do
      expect {click_button submit}.not_to change(User, :count)
    end
  end
  feature "with valid information" do
    scenario "should create a user" do
      fill_in "Name",         with: "test name"
      fill_in "Email",        with: "test@test.com"
      fill_in "Password",     with: "password"
      fill_in "Confirmation", with: "password"
      expect {click_button submit}.to change(User, :count).by(1)
    end
  end
end
但是当我运行 rspec 我得到
in `block in <top (required)>': undefined method `feature' for #<Class:0x000000039e0018> (NoMethodError)
如果我将其更改为如下所示,它可以工作:
  feature "with invalid information" do
    before {visit signup_path}
    let(:submit) {"Create my account"}
    scenario "should not create a user" do
      expect {click_button submit}.not_to change(User, :count)
    end
  end
  feature "with valid information" do
    before {visit signup_path}
    let(:submit) {"Create my account"}
    scenario "should create a user" do
      fill_in "Name",         with: "test name"
      fill_in "Email",        with: "test@test.com"
      fill_in "Password",     with: "nirnir"
      fill_in "Confirmation", with: "nirnir"
      expect {click_button submit}.to change(User, :count).by(1)
    end
  end
编辑:
另外,以下代码有效(描述嵌套内部功能) - 但它有任何错误吗?
feature "sign-up" do
  background {visit signup_path}
  given(:submit) {"Create my account"}
  scenario "with invalid information" do
    expect {click_button submit}.not_to change(User, :count)
  end
  describe "with valid information" do
    background do
      fill_in "Name",         with: "test name"
      fill_in "Email",        with: "test@test.com"
      fill_in "Password",     with: "password"
      fill_in "Confirmation", with: "password"
    end
    scenario { expect {click_button submit}.to change(User, :count).by(1) }
    scenario "after submission" do 
      click_button submit
      page.html.should have_content("Registration successful")
    end
  end
end