遇到“访问”问题在 Rails 教程中的集成测试中

发布于 2024-10-05 23:35:43 字数 1693 浏览 2 评论 0原文

我是 Rails 新手,正在阅读 rails 3 教程。我在运行集成测试时遇到问题。看来“访问”方法(Webrat?)总是会失败。这是我从 rspec 收到的错误消息:

Failure/Error: visit signup_path
Unknown Webrat mode: nil

Please ensure you have a Webrat configuration block that specifies a mode
in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).

This configure block supercedes the need to require "webrat/<framework>".

For example:

  Webrat.configure do |config|
    config.mode = :rails
  end
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'

我尝试将上面的 Webrat 配置块添加到 spec/spec_helpers.rb,并且收到此错误:

Failure/Error: visit signup_path
no such file to load -- action_controller/integration
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'

我已阅读有关此问题的其他主题,他们建议使用 'config.mode = :rack',如果我这样做,则会收到此错误:

Failure/Error: visit signup_path
undefined method `last_response' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_1::Nested_2:0xa4b8aac>
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'

我想可能需要注意的是,我在 win7x64 上开始了本教程,但我尝试在 ubuntu 上克隆存储库,但出现了相同的错误。如果有人想看的话,这是存储库:

git://github.com/ender4/sample_app2.git 请注意其中的 2^

我已经阅读了很多类似的主题,但大多数解决方案适用于旧版本的rails/rspec/webrat 或其他测试框架(如cucumber),所以我不知道它们是否/如何应用。

任何帮助将不胜感激。

I am new to rails and am running through the rails 3 tutorial. I have a problem running integration tests. It seems that the method 'visit' (Webrat?) will always fail. This is the kind of error message I get from rspec:

Failure/Error: visit signup_path
Unknown Webrat mode: nil

Please ensure you have a Webrat configuration block that specifies a mode
in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).

This configure block supercedes the need to require "webrat/<framework>".

For example:

  Webrat.configure do |config|
    config.mode = :rails
  end
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'

I tried adding the Webrat configure block above to spec/spec_helpers.rb, and I get this error:

Failure/Error: visit signup_path
no such file to load -- action_controller/integration
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'

I have read other topics about this problem and they suggested using 'config.mode = :rack', if I do so then I get this error:

Failure/Error: visit signup_path
undefined method `last_response' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_1::Nested_2:0xa4b8aac>
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'

I guess it might be important to note that I started the tutorial on win7x64, but I tried cloning the repository on ubuntu with the same errors. Here is the repository if anyone wants a look:

git://github.com/ender4/sample_app2.git
note the 2 there^

I have read a lot of similar topics but most solutions are for older versions of rails/rspec/webrat or for other testing frameworks (like cucumber) and so I do not know if/how they would apply.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

剑心龙吟 2024-10-12 23:35:43

如果您看到失败:

  1. 用户注册失败不应创建新用户
    失败/错误:访问signup_path
    名称错误:
    #RSpec::Core::ExampleGroup::Nested_1::Nested_3::Nested_1:0x0000000272d5b0 的未定义局部变量或方法“signup_path”

...确保将测试放置在正确的文件中:

它属于:
/spec/requests/users_spec.rb
不在:
/spec/model/user_spec.rb

通过实践来学习! :0>>
...更容易看到另一个人撞到墙上,然后避开那条路! :)

If you see failures:

  1. User signup failure should not make a new user
    Failure/Error: visit signup_path
    NameError:
    undefined local variable or method `signup_path' for #RSpec::Core::ExampleGroup::Nested_1::Nested_3::Nested_1:0x0000000272d5b0

... Make sure you are placing the test(s) in the correct file:

it belongs in:
/spec/requests/users_spec.rb
not in:
/spec/model/user_spec.rb

Learn by doing and all that! :0 <>
... much easier to watch the other guy slam into a wall and then avoid that path! :)

゛时过境迁 2024-10-12 23:35:43

将宝石更新为:

group :development do
  gem 'rspec-rails', '2.4.1'
end

group :test do
  gem 'rspec', '2.4.0'
  gem 'webrat', '0.7.1'
end

有效!

updated gems to :

group :development do
  gem 'rspec-rails', '2.4.1'
end

group :test do
  gem 'rspec', '2.4.0'
  gem 'webrat', '0.7.1'
end

works!

素染倾城色 2024-10-12 23:35:43

我想我找到了罪魁祸首,rspec 2.2.0。使用 rspec 2.1.0 似乎可以解决该问题。

I think I found the culprit, rspec 2.2.0. Using rspec 2.1.0 seems to fix the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文