rails3 rspec问题 [英] rails3 rspec issue
问题描述
我正在尝试使用rails3。我正在使用 railstutorial
网站来探索有关rails3的更多信息;本教程非常好(我对rails2的经验很少)。
I am trying out rails3. I am using railstutorial site to explore more about rails3; the tutorial is very good to begin with (I have minimal experience with rails2).
rspec存在一个问题,该问题目前阻止了我的进度。我看到该教程推荐使用rspec2.0.0.beta.18 gem;我改为使用
I have an issue with rspec which is currently blocking my progress. I saw that the tutorial recommended using rspec2.0.0.beta.18 gem; I instead installed rspec2.0.0.beta.20 gem using
bundle install
但是我发现此版本的rspec
有问题,我的rspec for integration_test看起来像:
However I find issues with this version of rspec My rspec for integration_test looks like:
describe "LayoutLinks" do
it "should have a About page at '/about'" do
get '/about'
response.should have_selector('h1', :content => "About Us")
end
end
失败看起来像:
Failures:
1) LayoutLinks should have a About page at '/about'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /home/arun/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
(注意:那些看过<一个href = http://railstutorial.org/chapters/filling-in-the-layout#top rel = nofollow noreferrer> 第5章 不会出现以下问题
(NOTE: Those who have looked at Chapter 5 will not have issues understanding the context.)
如果我在Gemfile中将rspec版本更改为2.0.0.beta.18并运行rspec,则会出现以下错误
If I change rspec version to 2.0.0.beta.18 in the Gemfile and run rspec I get the following error
arun@ubuntu-world:~/Project/Rails/rails3/sample_app$ rspec spec/
/home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/runtime.rb:27:in `block in setup': You have already activated rspec-core 2.0.0.beta.20, but your Gemfile requires rspec-core 2.0.0.beta.18. Consider using bundle exec. (Gem::LoadError)
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `block in each'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/runtime.rb:17:in `setup'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler.rb:100:in `setup'
from /home/arun/Project/Rails/rails3/sample_app/config/boot.rb:8:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /home/arun/Project/Rails/rails3/sample_app/config/application.rb:1:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /home/arun/Project/Rails/rails3/sample_app/config/environment.rb:2:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /home/arun/Project/Rails/rails3/sample_app/spec/spec_helper.rb:3:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /home/arun/Project/Rails/rails3/sample_app/spec/requests/layout_links_spec.rb:1:in `<top (required)>'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `load'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `block in load_spec_files'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `map'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `load_spec_files'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/command_line.rb:18:in `run'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:46:in `run_in_process'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:37:in `run'
from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:10:in `block in autorun'
推荐答案
我遇到了同样的问题。在第5章结尾中,通过 / spec / requests / layout_links_spec.rb 均因相同的错误而失败(控制器测试正常运行):
I'm having the same problem. At the end of Chapter 5, tests from /spec/requests/layout_links_spec.rb are all failing with the same error (the controller tests work just fine):
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# C:/Ruby192/lib/ruby/1.9.1/forwardable.rb:185
在 /spec/requests/layout_links_spec.rb 文件上进行了一些故障排除后,似乎使用了响应
是引发问题的原因。例如,如果文件的读取内容如下,则没有错误:
After doing a little troubleshooting on the /spec/requests/layout_links_spec.rb file, it appears that using response
within this context is what triggers the problem. For example, there is no error if the file reads as follows:
require 'spec_helper'
describe "LayoutLinks" do
it "should run tests properly from this file" do
get '/'
end
end
但是从本教程复制的文件为:
But the file as copied from the tutorial reads:
require 'spec_helper'
describe "LayoutLinks" do
it "should have a Home page at '/'" do
get '/'
response.should have_selector('title', :content => "Home")
end
it "should have a Contact page at '/contact'" do
get '/contact'
response.should have_selector('title', :content => "Contact")
end
it "should have an About page at '/about'" do
get '/about'
response.should have_selector('title', :content => "About")
end
it "should have a Help page at '/help'" do
get '/help'
response.should have_selector('title', :content => "Help")
end
end
响应
被称为
这是在Windows 7上(我尝试设置Ruby,Git,Vim和
This is on Windows 7 (I've attempted to setup Ruby, Git, Vim, and other development tools at the system level rather than within Cygwin).
Rspeicher-按照RailsTutorial.org的步骤操作, /config/routes.rb 文件看起来像这样:
Rspeicher - following RailsTutorial.org's steps, the /config/routes.rb file looks something like this:
SampleApp::Application.routes.draw do
get "users/new"
match '/signup', :to => 'users#new'
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
root :to => 'pages#home'
end
就像Arun所说的那样,这一切都按预期浏览器,因此问题似乎出在rspec或ruby中。我想如果在Cygwin下安装ruby,这不是问题。我希望不必恢复到纯Cygwin环境,尤其是因为我的webroot和项目文件已经在Cygwin的虚拟unix文件夹结构之外进行了管理。
like Arun says, this all works as intended in the browser, so the issue seems to be somewhere within rspec or ruby. I suppose this isn't a problem if ruby is installed under Cygwin. I was hoping to not have to revert to a pure Cygwin environment, especially since my webroot and project files are already managed outside of Cygwin's virtual unix folder structure.
这篇关于rails3 rspec问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!