[英]I keep getting this error “ NoMethodError:undefined method `visit' for #<RSpec::ExampleGroups::” in rspec and rails 4.1
I'm working on this http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I keep getting this error. 我正在对此http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/进行操作,并且不断收到此错误。
I'm using rails 4.1 我正在使用Rails 4.1
terminal 终奌站
Failures:
1) Tasks GET /tasks display some task
Failure/Error: visit tasks_path
NoMethodError:
undefined method `visit' for #<RSpec::ExampleGroups::Tasks::GETTasks:0x007fcfbd633758>
# /Users/estebangallego/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.8/lib/action_dispatch/testing/assertions/routing.rb:171:in `method_missing'
# /Users/estebangallego/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.8/lib/action_dispatch/testing/integration.rb:396:in `method_missing'
# ./spec/features/task_spec.rb:7:in `block (3 levels) in <top (required)>'
2) Tasks GET /tasks creates a new task
Failure/Error: visit "/"
NoMethodError:
undefined method `visit' for #<RSpec::ExampleGroups::Tasks::GETTasks:0x007fcfbe572ea8>
# /Users/estebangallego/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.8/lib/action_dispatch/testing/assertions/routing.rb:171:in `method_missing'
# /Users/estebangallego/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.8/lib/action_dispatch/testing/integration.rb:396:in `method_missing'
# ./spec/features/task_spec.rb:13:in `block (3 levels) in <top (required)>'
Finished in 0.01248 seconds (files took 1.69 seconds to load)
4 examples, 2 failures, 2 pending
Failed examples:
rspec ./spec/features/task_spec.rb:5 # Tasks GET /tasks display some task
rspec ./spec/features/task_spec.rb:12 # Tasks GET /tasks creates a new task
I tried "features/task_spect.rb" and "requests/tasks_spect.rb" 我尝试了“功能/ task_spect.rb”和“请求/ tasks_spect.rb”
require "rails_helper"
RSpec.describe "Tasks", type: :request do
describe "GET /tasks" do
it "display some task" do
@task = Task.create :task => "go to bed"
visit tasks_path
page.should have_content "go to bed"
end
it "creates a new task" do
visit "/"
fill_in "Task", :with => "go to work"
click_button "Create Task"
current_path.should == root_path
page.should have_content "go to work"
save_and_open_page
end
end
end
gems 宝石
group :development, :test do
gem 'rspec-rails'
gem 'capybara'
end
new rspec.rb 新的rspec.rb
require 'rails_helper'
RSpec.describe "Tasks", type: :request do
config.include Capybara::DSL
describe "GET /tasks" do
it "display some task" do
@task = Task.create :task => 'go to bed'
visit root_path
page.should have_content 'go to bed'
end
it "creates a new task" do
visit '/'
fill_in 'Task', :with => 'go to work'
click_button 'Create Task'
current_path.should == task_path
page.should have_content 'go to work'
save_and_open_page
end
end
end
I have fixed the error and post it in my github app 我已经修复了错误并将其发布在我的github应用中
https://github.com/rajcybage/tasks https://github.com/rajcybage/tasks
please see the commit 请看提交
https://github.com/rajcybage/tasks/commit/fa6fa54e60717f805e040f0eb767dc0e3ef4d434 https://github.com/rajcybage/tasks/commit/fa6fa54e60717f805e040f0eb767dc0e3ef4d434
run bundle exec rake spec:features
运行
bundle exec rake spec:features
rajarshi@rajarshi-X200CA:~/tasks$ bundle exec rake spec:features
/home/rajarshi/.rbenv/versions/2.1.4/bin/ruby -I/home/rajarshi/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.3/lib:/home/rajarshi/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-support-3.2.2/lib /home/rajarshi/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.3/exe/rspec --pattern ./spec/features/\*\*/\*_spec.rb
Randomized with seed 14426
..
Deprecation Warnings:
Requiring `rspec/autorun` when running RSpec via the `rspec` command is deprecated. Called from /home/rajarshi/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'.
Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/rajarshi/tasks/spec/features/task_spec.rb:18:in `block (3 levels) in <top (required)>'.
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
2 deprecation warnings total
Finished in 2.06 seconds (files took 6.03 seconds to load)
2 examples, 0 failures
Randomized with seed 14426
rajarshi@rajarshi-X200CA:~/tasks$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.