-
-
Notifications
You must be signed in to change notification settings - Fork 1k
undefined method `visit' for #<RSpec::Core::ExampleGroup:.... #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
rc4 adds more support for Capybara 0.4 and 1.0. How/where are you requiring capybara? |
I have |
Try getting rid of that and tell me what happens. rspec-rails already does this, so it might be that doing it a second time is causing a problem due to module reloading, etc. |
I've commented out the require line, but nothing changed. |
What's in your Gemfile? |
Posted Gemfile here: https://gist.github.com/952141 |
I just ran this: https://gist.github.com/952630 and the spec with visit in it passed. Do you get the same result from that gist? |
Works here too. I tried to make On the other side, I experimented with rspec-rails git and found out that this commit exactly: 59793dc breaks things for me (the specs pass with the preceding one when rspec-rails is pulled from git). |
The test example works if I manually add How come it doesn't get included? |
So, I found it. The example that also breaks for your example app:
The cause of the bug is as follows. If we look at the :include_or_extend_modules array in rspec configuration, we see following:
(that's from my project). So Capybara::DSL gets included before RSpec::Rails::RequestExampleGroup. The former has In your test example, with double describe block, module inclusion occurs twice. The second time type is already set, Capybara::DSL gets included, everything works. The fix should be darn simple (haven't got more time right now, but I'll come up with it in the case you don't fix it first :) |
Otherwise Capybara's includes are not set correctly. Fixes rspec#360
Fix is available as pull request #362 |
I've got the same isssue (undefined method `visit' etc). I'm using capybara 1.0.0.beta1 I've got the rspec-rails and dependencies in my gemfile pointing to github. So I would have thought I'd have the latest, which includes the above commit? I have require 'rspec/rails' in my spec_helper.rb. It's in a new project I'm just getting started with. I'm also just getting started with rails, so I'm totally lost. Any help would be much appreciated. |
I ran into the same problem today with rspec-rails 2.6.1 and capybara 1.0.0 #spec_helper.rb
require 'rubygems'
require 'spork'
require "email_spec"
ENV["RAILS_ENV"] ||= 'test'
Spork.prefork do
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
end
Spork.each_run do
Dir[Rails.root.join("site/app/**/*.rb")].each {|f| require f}
require "#{Rails.root}/spec/factories.rb"
end |
Problem was due to the 'steak' gem. Once I removed it the Capybara methods worked once again. |
@jackkinsella - glad to hear it, though a lot of people like to use steak so I'd like to understand why that doesn't work. As an aside, I'd recommend the following changes to your spork config in spec_helper: #spec_helper.rb
require 'rubygems'
require 'spork'
ENV["RAILS_ENV"] ||= 'test'
Spork.prefork do
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'email_spec' # shouldn't really need this if it's in the :test group in the Gemfile
end
Spork.each_run do
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
end This assumes moving spec/factories.rb to spec/support. You don't need to require anything from app/** because Rails does that for you. |
Thanks Dave; I hadn't thought of putting the factories into the support dir. I'm aware that I don't need to require anything from app/, but I have a gem in site/app/ which I'm actively developing. I decided against using Steak for the same reason I've stopped using Cucumber: unwarranted additional abstraction. Rspec and Capybara do the same job with less lines of code and with fewer configuration headaches. |
Ah - missed that it was site/app. Cheers. |
I'm still seeing this with the latest rspec and rspec-rails. The I am using spork, so perhaps that has something to do with it? require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'capybara/rspec'
require 'rspec/rails'
require 'database_cleaner'
# use capybara-webkit
Capybara.javascript_driver = :webkit
# calls to DatabaseCleaner.clean will use truncation
# otherwise, we will still use transactional fixtures
DatabaseCleaner.strategy = :truncation
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.include ModelMacros
config.include ActionView::TestCase::Behavior, :example_group => {:file_path => %r{spec/presenters}}
# config.include FactoryGirl::Syntax::Methods
config.before(:suite) do
# Create the admin user
Factory(:user, :login => ENV['REMOTE_USER'], :roles_mask => 1)
end
end
end
Spork.each_run do
# verifies we start with a clean database each run
DatabaseCleaner.clean
# require factories
require 'factory_girl_rails'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
end
# This allows us to use transactional fixtures when
# using selenium/capybara-webkit by forcing them to use
# the same thread as capybara.
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
def current_connection_id
Thread.main.object_id
end
end |
Getting the same error with rspec-rails (2.8.1) and capybara (1.1.2). |
@derekprior, @ala I can't repro this on my system w/ Mac OS and ruby 1.9.3. What OS and ruby versions are you running? |
I'm running OS X 10.6.8, with Ruby 1.9.2-p290. I'll take a shot at distilling a simplified reproduction. |
Running on OS X too: rvm -v ruby -v |
Okay, @dchelimsky, I think I boiled it down to a base case (at least in my case). Please see this repository: The reproduction succeeds ( The repository I linked to will produce a failing spec on 1.9.2-p290 and 1.9.3-p0. I suspect the same is true of 1.8.7, but I didn't have time to correct the hash syntax and re-run the tests there. Seems like "leave it to rspec-rails to require capyabara" is the way to go. I think that line was in my spec_helper from days prior to whatever version of rspec-rails added the automatic require. |
Actually, it appears that test case isn't true to my actual project issue. In my actual project, neither removing or re-ordering the requires fixes anything. Calls to I'll keep looking... |
#
# *Working*
# spec/controller/pages_controller_spec.rb
#
require 'spec_helper'
describe PagesController do
render_views
describe "GET 'home'" do
it "should be successful" do
visit '/'
response.should be_successful
end
end
end #
# *Not Working*
# spec/requests/user_registration_spec.rb
#
require 'spec_helper'
describe "user registration" do
it "should serve the registration page" do
visit '/signup'
page.should have_content("Sign Up")
end
end |
@ala - what's not working? You're getting undefined method on |
@dchelimsky yes, getting the undefined visit method. |
@ala is your repo public? |
Also - @derekprior thanks for posting the app - that helped me see the bug, figure out the workaround, and will eventually lead to a fix. |
Unfortunately this workaround doesn't do it for me. I still get
The repo is public under: https://github.com/ikusei/Goldencobra_Newsletter edit: If i put |
I see this is marked as closed, but I'm having this same issue |
Did you see my edit? After doing that it worked for me. |
@jazzgumpy , Thanks that works for me as well using include Capybara::DSL within my outer describe |
@dchelimsky I started on a new app and ran into this, so this is a very small (if not minimal) failure case with RSpec 2.11: https://dl.dropbox.com/u/546793/joblog.zip Note that there is a workaround ( (And I will of course make sure to change the |
@bigtunacan @jazzgumpy A slightly nicer workaround is to put
in |
@henrik the directory is requests (plural), not request. Try that and it works as expected. |
@dchelimsky Thanks, that did work. Sorry for bothering you with such a silly mistake. Maybe @jazzgumpy and @bigtunacan made similar mistakes. Would be nice if it was harder to make a mistake, or easier to recover from it, but I can't think of how, other than maybe emphasizing it in the docs. Pull request for that: #585 |
I merged your pull request, so that should help. Thx. Also, the integration test generator puts it in the right place. |
I've run in this issue after update to capybara 2.0. First I implemented the henrik's workaround by mixing Capybara::DSL methods to Rspec but now I've found this in the Capybara 2.0 update notes:
See http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html I have my tests in the old path spec/requests of course ... Might be it could help someone. |
for others facing the issue, renaming request to |
2wojtha and @reejosamuel, thank you. I renamed my requests dir to features and that fixed it! |
thank you @wojtha. |
renaming requests to features worked here, too. Thx. |
ditto for me @george |
For reference, it's documented in Capybara.md and this blog post |
renamed requests to features. Problem fixed. Thank you. |
I'm using rails 4.0.0.beta1. Renamed the requests folder to features, but still needed to add |
i got the same problem and fixed with 2 way : thanks guys |
renaming "requests" to "features" fix it. rails 4 |
👍 renaming "requests" to "features" fixed it, on Rails 3. |
1、add "gem "rspec-rails", " |
Hmm I think it might be helpful to add the poing number 3 into the README.md file of capybara so that when people use they don't need to do search for the problem again. |
Renaming the |
+1 |
Since I got it wrong: rspec#360
I followed all the different work-around (or I think I did) in this post and still could not get it working. I still see the NoMethodError. My repo is a really basic practice website. Please help at |
You need to add a |
I'm having trouble with my Capybara integration specs and rspec-rails 2.6.0.rc4.
It's simple
visit '/'
which explodes.2.6.0.rc2 works great. What has been changed? Capybara version is 1.0.0.beta1
The text was updated successfully, but these errors were encountered: