plataformatec/devise — Issue #1576: Another rspec+devise issue.
Author: panSarin
Created: 2012-01-17 17:24:52+00:00
State: open

Hello. I saw many issues about that , but still i didn't found any sollution for my problem. Maybe it`s only some stupid mistake i made and can't find it. But i spent about 2 days to find a solution, and this is my last hope ;o

So :
1st sollution that i tried is my own helper that
[code]
visit login_page
fill :email => user.email
fill :password => user.password
click_button "Login"
[/code]

User don't need to be confirmed , my password and email are from user so there is no way that i made some typo, but i still get authentication_failure message (devise.failure.invalid)

So i tried second sollution - from wiki
my spec_helper:

[code]

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

# 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}
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)

RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.after(:all) do
GC.enable
GC.start
end

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
end

[/code]

controller_macros.rb is just copied from wiki and inserted in spec/support

and my spec/acceptance/admin/managing_users_spec.rb is :

[code]
require File.dirname(__FILE__) + '/../acceptance_helper'
describe UsersController do

login_admin
it "should have a current_user" do
subject.current_user.should_not be_nil
end
end
[/code]

when i run it i get: undefined local variable or method `login_admin' for # (NameError)

Where i make a mistake?
If u use second solution i can't write acceptance tests with "feature" and "scenario" ? And why i can't use 1st solution?

Srry if i doubled already existing issue, ( i found many similiar but , no about that problem)

Greetings and respect for all you doing Jose ;]