0
votes

I just started some tests on my Rails application in which I use Devise for authentication. I just generated rspec and only added

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end

to my spec/support/devise.rb file. I also added Capybara to the test group in my gemfile, run the bundle command, etc. But as I do visit in my tests, I get a no method error. Here an example of my user_spec.rb:

require 'spec_helper'

describe "Club" do
  before(:each) do
    @club ||= FactoryGirl.create(:club)
    FactoryGirl.create(:membership)
    User.all.each{|x| x.delete}
  end
  describe "privacy" do
    it "shouldn't be shown any tournament if the user is private" do
      attributes = FactoryGirl.attributes_for(:user)
      user = User.create!({private: true}.merge(attributes))
      assert(user.private)
      visit "/user/#{user.id}/tournaments"

      page.should have_no_selector(".tournament-list")
    end
  end
end

As I run rspec there comes an error like this:

Failures:

  1) Club privacy shouldn't be shown any tournament if the user is private
     Failure/Error: visit "/user/#{user.id}/tournaments"
     NoMethodError:
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007ff0ea113108>
     # ./spec/user_spec.rb:14:in `block (3 levels) in <top (required)>'
2
Did you try that ? stackoverflow.com/a/10221773/919641pjam

2 Answers

1
votes

For capybara specs I use:

describe "Club", :type => :feature, :js => true do
  include Capybara::DSL

  it "..."
end

And instead User.all.each{|x| x.delete}, use DatabaseCleaner

1
votes

You can easily add the Capybara::DSL to RSpec config spec_helper.rb

RSpec.configure do |config|
  .....
  .......
  config.include(Capybara::DSL)

end