简体   繁体   中英

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.

I'm using 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"

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

    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

https://github.com/rajcybage/tasks

please see the commit

https://github.com/rajcybage/tasks/commit/fa6fa54e60717f805e040f0eb767dc0e3ef4d434

run 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$ 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM