Reputation: 11887
Upon trying to run a specs files for integration testing, I see:
undefined method `visit' for #<Class:0xab9a140> (NoMethodError)
I've searched this website and found out several solutions to my problems, and these are the solutions I've tried already ( with no success ):
add include Capybara::DSL
to my spec file - this is funny. When I add this, I stop having the aforementioned error and start having another error message:
undefined method 'expect' for #<Class:0x9d2a088> (NoMethodError)
describe
with feature
in the spec tests. (no change)Outcome of trying to run the specs which contain the visit
method:
felipe@felipe-VirtualBox:~/rails/project-manager$ bundle exec rspec spec/features/
No DRb server is running. Running in local process instead ...
/home/felipe/rails/project-manager/spec/features/projects_spec.rb:15:in `block (2 levels) in <top (required)>': undefined method `visit' for #<Class:0xab9a140> (NoMethodError)
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `module_eval'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `subclass'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'
from /home/felipe/rails/project-manager/spec/features/projects_spec.rb:14:in `block in <top (required)>'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `module_eval'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `subclass'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/dsl.rb:18:in `describe'
from /home/felipe/rails/project-manager/spec/features/projects_spec.rb:3:in `<top (required)>'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:77:in `rescue in run'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:73:in `run'
from /home/felipe/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'
my Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
group :development,:test do
gem 'rspec-rails'
gem 'pg','0.15.1'
gem 'watchr'
gem 'selenium-webdriver'
gem 'capybara'
gem 'spork-rails'
gem 'guard-spork'
gem 'childprocess'
end
gem 'sass-rails', '~> 4.0.1'
gem 'uglifier', '>= 2.1.0'
gem 'coffee-rails', '~> 4.0.1'
gem 'jquery-rails','3.0.4'
gem 'turbolinks','1.1.1'
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
My spec_helper.rb file
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
# Disable the old-style object.should syntax.
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
end
Spork.each_run do
end
the actual test (yes, it's under spec/features
folder)
require 'spec_helper'
describe "Projects" do
describe "Projects index" do
it "should show the string 'Projetos'" do
visit '/projects'
expect(page).to have_content('Projetos')
end
end
describe 'Add and delete a project' do
visit '/projects/new'
expect(page).to have_content('Novo')
end
end
I'm looking for suggestions and pointers as to what might be my issue.
P.S.: I'm running rails (4.0.1)
, capybara (2.2.0)
, rspec-core (2.14.7)
rspec-rails (2.14.0)
Upvotes: 1
Views: 1287
Reputation: 11887
I've found the problem.... I was missing a it ... do ... end
block around the second call to visit
... Sorry for this and thank you to everyone who's helped me.
Upvotes: 2