Ruby on rails 3 未找到Rails测试-未定义的局部变量或方法;回应";

Ruby on rails 3 未找到Rails测试-未定义的局部变量或方法;回应";,ruby-on-rails-3,syntax,rspec2,railstutorial.org,Ruby On Rails 3,Syntax,Rspec2,Railstutorial.org,我正试图追随迈克尔·哈特尔,但我遇到了一个在别处找不到解释的错误。在下,我在尝试为试图更新配置文件页面的未登录用户运行测试时出错 describe "submitting to the update action" do before { put user_path(user) } specify { response.should redirect_to(signin_path) } end 我得到的错误是“未定义的局部变量或#(namererror)的方法‘response’”。这

我正试图追随迈克尔·哈特尔,但我遇到了一个在别处找不到解释的错误。在下,我在尝试为试图更新配置文件页面的未登录用户运行测试时出错

describe "submitting to the update action" do
  before { put user_path(user) }
  specify { response.should redirect_to(signin_path) }
end
我得到的错误是“未定义的局部变量或#(namererror)的方法‘response’”。这是对“bundle exec rspec spec/”的响应。当我注释掉有问题的行时,所有测试都实例化并通过。我试着用“response.body”和“page”来代替“response”,但这两个词似乎都没用

我不确定问题出在哪里,因为在我继续学习教程的过程中,类似的模块正在顺利通过

以下是完整的错误文本:

C:\Ruby193\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\Ruby193\bin\rake spec
Testing started at 7:39 PM ...
C:/Ruby193/bin/ruby.exe -S rspec ./spec/models/user_spec.rb ./spec/requests/authentication_pages_spec.rb ./spec/requests/static_pages_spec.rb ./spec/requests/user_pages_spec.rb
Rack::File headers parameter replaces cache_control after Rack 1.5.
C:/Users/Jeff/Documents/rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:60:in `block (5 levels) in <top (required)>': undefined local variable or method `response' for #<Class:0x4894908> (NameError)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `module_eval'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `subclass'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:in `describe'
    from C:/Users/Jeff/Documents/rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:58:in `block (4 levels) in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `module_eval'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `subclass'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:in `describe'
    from C:/Users/Jeff/Documents/rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:51:in `block (3 levels) in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `module_eval'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `subclass'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:in `describe'
    from C:/Users/Jeff/Documents/rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:48:in `block (2 levels) in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `module_eval'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `subclass'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:in `describe'
    from C:/Users/Jeff/Documents/rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:46:in `block in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `module_eval'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `subclass'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:in `describe'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/dsl.rb:18:in `describe'
    from C:/Users/Jeff/Documents/rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:3:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `block in load_spec_files'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load_spec_files'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:in `run'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:80:in `run'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:17:in `block in autorun'
rake aborted!
C:/Ruby193/bin/ruby.exe -S rspec ./spec/models/user_spec.rb ./spec/requests/authentication_pages_spec.rb ./spec/requests/static_pages_spec.rb ./spec/requests/user_pages_spec.rb failed
-e:1:in `load'
-e:1:in `<main>'
Tasks: TOP => spec
(See full trace by running task with --trace)

Process finished with exit code 1
Empty test suite.

你正在运行哪种版本的水豚

$ bundle exec gem list | grep capybara
如果您运行的是版本
>=2.0
,则应再次查看您的GEM文件,并明确标记该版本与教程相同(
1.1.2

Gemfile

group :test do
  gem 'capybara', '1.1.2'
end
如果您非常想使用最新版本,则必须进行一些更改,如以下问题与解答所述:

更新 好吧,你会踢自己,但是在克隆你的回购协议并得到同样的错误后,你的问题很明显(语法突出显示是你的朋友):

关于你有:

specify ( response.should redirect_to(signin_path) )
应该是:

specify { response.should redirect_to(signin_path) }

修复后,您的测试将通过。

坚持使用此处指定的gem版本:我复制了源gem文件,但仍然出现此错误。这并不能回答您的问题,但是我只是因为一个不同的原因收到了相同的错误消息,所以我为其他有相同问题的人发布了这个消息:我忘记了包含行
subject{page}
。哦!根据教程中的Gemfile,仍然是1.1.2版吗?您是否有一个Github repo,其中包含您正在使用的代码版本?考虑到您说“显然
have_selector('title'),…)
不再是有效语法”,我认为您在第一次运行
bundle install
并获得Capybara版本2时没有指定Capybara版本。如果是这种情况,并且您稍后又更改回1.1.2版,您是否再次运行了
捆绑安装
?我仔细检查了一遍,重新运行了
捆绑安装
,仍然显示错误。
specify { response.should redirect_to(signin_path) }