新手问题 rails tutorial 中第 7 章 sign up 测试出现问题

yldcb · 2014年10月07日 · 最后由 yldcb 回复于 2014年10月07日 · 2707 次阅读

代码是直接从 github 下过来解压然后 bundle install 发现 rails s 后能正常运行 但是测试就是各种出现错误 bundle exec rspec spec/requests/user_pages_spec.rb -e "signup page" 执行这句的时候出现:

bundle exec rspec spec/requests/user_pages_spec.rb -e "signup page" No DRb server is running. Running in local process instead ... /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in load': /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:20: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' (SyntaxError) fill_in "Email", ^ /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:20: syntax error, unexpected ',', expecting keyword_end /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:22: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' fill_in "Confirmation", with: "foobar" ^ /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:22: syntax error, unexpected ',', expecting keyword_end fill_in "Confirmation", with: "foobar" ^ /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:23: syntax error, unexpected ':', expecting keyword_end with: "Example User" ^ /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:24: syntax error, unexpected ':', expecting keyword_end with: "[email protected]" ^ /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:25: syntax error, unexpected ':', expecting keyword_end with: "foobar" ^ from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:inblock in load_spec_files' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in each' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:inload_spec_files' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/command_line.rb:22:in run' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:77:inrescue in run' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:73:in run' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:17:inblock in autorun'

google 了很久没发现答案。。求解惑

spec/requests/user_pages_spec.rb:20: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' (SyntaxError) fill_in "Email",

有语法错误

%>_<%都是复制粘贴的。。。我再看看跟 pdf 里是不是有差。。。

我从 git 上把完成的版本的 user_pages.spec.rb 覆盖后再执行出现:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0/gems/nokogiri-1.5.6/lib/nokogiri.rb:27:in require': cannot load such file -- nokogiri/nokogiri (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0/gems/nokogiri-1.5.6/lib/nokogiri.rb:27:in' from /Users/qianyuhui/.bundler/ruby/2.0.0/capybara-d73c24d3e3fb/lib/capybara.rb:2:in require' from /Users/qianyuhui/.bundler/ruby/2.0.0/capybara-d73c24d3e3fb/lib/capybara.rb:2:in' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.7.2/lib/bundler/runtime.rb:76:in require' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.7.2/lib/bundler/runtime.rb:76:inblock (2 levels) in require' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.7.2/lib/bundler/runtime.rb:72:in each' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.7.2/lib/bundler/runtime.rb:72:inblock in require' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.7.2/lib/bundler/runtime.rb:61:in each' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.7.2/lib/bundler/runtime.rb:61:inrequire' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.7.2/lib/bundler.rb:133:in require' from /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/config/application.rb:11:in' from /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/config/environment.rb:2:in require' from /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/config/environment.rb:2:in' from /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/spec_helper.rb:6:in require' from /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/spec_helper.rb:6:inblock in ' from /Library/Ruby/Gems/2.0.0/gems/spork-1.0.0rc3/lib/spork.rb:24:in prefork' from /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/spec_helper.rb:4:in' from /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:1:in require' from /Users/qianyuhui/Desktop/ruby/rails/sample_app_rails_4-modeling-users/spec/requests/user_pages_spec.rb:1:in' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in load' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:inblock in load_spec_files' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in each' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:inload_spec_files' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/command_line.rb:22:in run' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:77:inrescue in run' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:73:in run' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:17:inblock in autorun'

nokogiri-1.5.6/lib/nokogiri.rb

这个问题我之前也出现过。。。请问是什么原因?

下载附书源码,在这份源码中执行测试看看有没有错误。

不要直接用源码中的文件覆盖你自己编写的代码。

我是直接下载 git 上源码,现在执行了 bundle install --path vendor/bundle 查到的有关资料是这样的:

这样项目依赖的 gem 既不是安装在系统目录,也不是用户目录,而是当前目录的 vendor/bundle 文件夹内。这样安装的 gem 每个项目独立,要清除项目的时候只要把整个项目目录删除就好了。(注意设置 git 忽略这个目录)

部署环境同理,也是安装到 vendor/bundle 目录:

bundle install --deployment 所以,一般情况把 Bundler 装到系统目录就够了,应用依赖装到应用目录中。关于 Bundler 的用法这里不再展开,可以查看官方网站:http://bundler.io/

需要 登录 后方可回复, 如果你还没有账号请 注册新账号