I'm having an issue while testing user authentication with rspec and devise.
here is my code:
require 'rails_helper'
describe UsersController, :type => :controller do
let(:user) { User.create!(email: '1#test.com', password: '123456') }
describe 'GET #show' do
context 'User is logged in' do
before
sign_in user
get :show
end
it "loads correct user details" do
expect(assigns(:user)).to eq user
end
end
context 'No user is logged in' do
it 'redirects to login' do
get :show, id: user.id
expect(response).to redirect_to(root_path)
end
end
end
end
When i run rspec on the terminal i get this error:
/Users/joao1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load': /Users/joao1/Desktop/nameofapp/spec/controllers/users_controller_spec.rb:29: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `block in load_spec_files'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `each'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `load_spec_files'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:100:in `setup'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:86:in `run'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
from /Users/joao1/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `load'
from /Users/joao1/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `<main>'
from /Users/joao1/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/joao1/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
How can i solve this and effectively test my user authentication?
The error message is a result of a typo in your program and it not matching up do end blocks. Looking more carefully I see you are missing a do statement from the before block. Change it to:
before do
sign_in user
get :show
end
Related
I'm working with Rails 5.1.13
When I run an individual test, it pass:
rails test test/api/controllers/positions_controller_test.rb
But when I run all the test in a folder, it fail:
rails test test/api/controllers/
With this error message: test_should_get_index is already defined in
Running via Spring preloader in process 14518
/home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/testing/declarative.rb:14:in `test': test_should_get_index is already defined in Api::V1::PositionsControllerTest (RuntimeError)
from /home/mato/cuadernogordo/test/api/controllers/teachers_controller_test.rb:11:in `<class:PositionsControllerTest>'
from /home/mato/cuadernogordo/test/api/controllers/teachers_controller_test.rb:3:in `<top (required)>'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `block in require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/test_unit/runner.rb:50:in `block in load_tests'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/test_unit/runner.rb:50:in `each'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/test_unit/runner.rb:50:in `load_tests'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/test_unit/runner.rb:39:in `run'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/commands/test/test_command.rb:38:in `perform'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/command/base.rb:63:in `perform'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/command.rb:44:in `invoke'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/railties-5.1.3/lib/rails/commands.rb:16:in `<top (required)>'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `block in require'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
from /home/mato/cuadernogordo/bin/rails:9:in `<top (required)>'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:286:in `load'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:286:in `block in load'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency'
from /home/mato/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:286:in `load'
from /home/mato/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/mato/.rvm/rubi
All and each one test in that folder pass when I run they individually.
All my test of controllers have, more or less, the same form, like the following:
require 'test_helper'
class Api::V1::PositionsControllerTest < ActionDispatch::IntegrationTest
setup do
#school = schools(:school_one)
#teacher = teachers(:teacher_one)
#course = courses(:course_one)
#position = positions(:position_one)
end
test "should get index" do
get api_v1_positions_url
assert_response :success
end
test "should create position" do
assert_difference('Position.count') do
post "/api/v1/positions", params: { position: { course_id: #course.id, shift: "tarde", status: "activo", teacher_id: #teacher.id, position_type: "titular" }}
end
assert_response 201
assert_response :success
end
test "should show position" do
get api_v1_position_url(#position)
assert_response :success
end
test "should update position" do
patch api_v1_position_url(#position), params: { position: { shift: "tarde", status: #position.status, teacher_id: #position.teacher_id, position_type: "suplente" } }
assert_response :success
end
test "should destroy position" do
assert_difference('Position.count', -1) do
delete api_v1_position_url(#position)
end
assert_response :success
end
end
To learn API by using Rails I'm reading this tutorial.
In a part of RSpec test there is a method like this:
spec/support/authentication_helper.rb
module AuthenticationHelper
def sign_in(user)
header('Authorization', "Token token=\"#{user.authentication_token}\", email=\"#{user.email}\"")
end
def create_and_sign_in_user
user = FactoryGirl.create(:user)
sign_in(user)
user
end
alias_method :create_and_sign_in_another_user, :create_and_sign_in_user
end
RSpec.configure do |config|
config.include AuthenticationHelper, type: :api
end
And the test failed by undefined method `header'.
Where is this header method defined?
This is the whole source code of this tutorial.
https://github.com/vasilakisfil/rails_tutorial_api/
spec/apis/users_spec.rb
require 'rails_helper'
describe Api::V1::UsersController, type: :api do
context :show do
before do
create_and_sign_in_user
#user = FactoryGirl.create(:user)
get api_v1_user_path(#user.id), format: :json
end
it 'returns the correct status' do
expect(last_response.status).to eql(200)
end
it 'returns the data in the body' do
body = HashWithIndifferentAccess.new(MultiJson.load(last_response.body))
expect(body[:user][:name]).to eql(#user.name)
expect(body[:user][:updated_at]).to eql(#user.updated_at.iso8601)
end
end
end
StackTrace
1) Api::V1::UsersController show returns the correct status
Failure/Error: create_and_sign_in_user
NameError:
undefined local variable or method `request' for #<RSpec::ExampleGroups::ApiV1UsersController::Show:0x007fcbfec91d60>
# ./spec/support/authentication_helper.rb:4:in `sign_in'
# ./spec/support/authentication_helper.rb:9:in `create_and_sign_in_user'
# ./spec/apis/user_spec.rb:6:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:39:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:38:in `block (2 levels) in <top (required)>'
# -e:1:in `<main>'
2) Api::V1::UsersController show returns the data in the body
Failure/Error: create_and_sign_in_user
NameError:
undefined local variable or method `request' for #<RSpec::ExampleGroups::ApiV1UsersController::Show:0x007fcbfb7cfa28>
# ./spec/support/authentication_helper.rb:4:in `sign_in'
# ./spec/support/authentication_helper.rb:9:in `create_and_sign_in_user'
# ./spec/apis/user_spec.rb:6:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:39:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:38:in `block (2 levels) in <top (required)>'
# -e:1:in `<main>'
I had to add api_helper.rb to use the methods.
module ApiHelper
include Rack::Test::Methods
def app
Rails.application
end
end
RSpec.configure do |config|
config.include ApiHelper, type: :api #apply to all spec for apis folder
config.include Rails.application.routes.url_helpers, type: :api
end
Here is source code in Github.
https://github.com/vasilakisfil/rails_tutorial_api/blob/008af67e88897a5bcde714ce13d39a26ec70fba7/spec/support/api_helper.rb
In spec/support/auth_helpers.rb, you can try something like this
module AuthHelpers
def authenticate_with_user(user)
request.headers['Authorization'] = "Token token=#{user.token}, email=#{user.email}"
end
def clear_authentication_token
request.headers['Authorization'] = nil
end
end
In Rspec's spec/rails_helper.rb
Rspec.configure do |config|
config.include AuthHelpers, file_path: /spec\/apis/
end
An example test in spec/apis/users_controller_spec.rb:
require 'rails_helper'
describe Api::V1::UsersController, type: :controller do
let(:user) { create(:user) }
context 'signed in' do
before do
authenticate_with_user user
end
it 'does something' # tests here
end
end
Hope it helps!
Edit: Note the type: :controller is important
I was working on the part 9.3.3 about pagination from the ruby on rails tutorial of Michael Hartl, an Im stuck: running the rspec tests i got an error message that there is something wrong with the gem FactoryGirl. Do you suppose what could be a problem?
/Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/definition_proxy.rb:43:in `add_attribute': Both value and block given (FactoryGirl::AttributeDefinitionError)
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/definition_proxy.rb:102:in `method_missing'
from /Users/smi/projects/sample_app/spec/factories.rb:3:in `block (2 levels) in <top (required)>'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `instance_eval'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `factory'
from /Users/smi/projects/sample_app/spec/factories.rb:2:in `block in <top (required)>'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `run'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:7:in `define'
from /Users/smi/projects/sample_app/spec/factories.rb:1:in `<top (required)>'
from /Users/smi/.rvm/ge......................
users_pages_spec.rb:
describe "pagination" do
before(:all) { 30.times { FactoryGirl.create(:user) } }
after(:all) { User.delete_all }
it { should have_selector('div.pagination') }
it "should list each user" do
User.paginate(page: 1).each do |user|
expect(page).to have_selector('li', text: user.name)
end
end
end
factories.rb:
FactoryGirl.define do
factory :user do
sequense(:name) { |n| "Person #{n}" }
sequense(:email) { |n| "person_#{n}#example.com" }
password "foobar"
password_confirmation "foobar"
end
end
I have found an answer! the method "sequence" in factories.rb was written with a mistake. Now all tests are green.
Uninitialized constant Production::POverview (NameError)
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/syntax/default.rb:49:in `run'
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/syntax/default.rb:7:in `define'
from /Users/simon_zhu/Documents/original_version_carmel/carmel/spec/factories/poverview.rb:1:in `<top (required)>'
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/find_definitions.rb:20:in `block (2 levels) in find_definitions'
from /Users/simon_zhu/.rvm/gems/ruby-2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/find_definitions.rb:19:in `each'
I have the following code:
poverview.rb (factory)
FactoryGirl.define do
factory :poverview, class: Production::POverview do
name "test"
status ["p", "d", "m"]
end
end
p_overview_controller_spec.rb (spec)
require 'spec_helper'
describe Production::POverviewController do
login_user
# GET Request to pod_info
describe 'GET pod_info' do
before(:each) do
#pods = Factory(:poverview)
get 'show', :format => :json, :name => #pods.name
get 'show', :format => :json, :status => #pods.status
end
it "should return the correct company when correct id is passed" do
body = JSON.parse(response.body)
for(pod in body[0])
if(pod['name'].eql? #pod.name)
#pod.status.should.include? pod['status']
end
end
end
end
This is my first time writing an integration test for Factory Girl and I have this uninitialized constant error.
Any Ideas how to solve this?
Also your test setup looks very odd. It definitely looks like you are confusing integration and controller test.
Here is a post to get you started. I recommend doing some more research on testing in rails.
https://semaphoreapp.com/blog/2014/02/11/rails-testing-antipatterns-controllers.html
In Rails 3.2.13, subdomain is provided by default. As such, I want to test my application such that when a merchant signs up, he goes by default to root_url with subdomain 'merchant' i.e. https://merchant.lvh.me:3000. However, I am having trouble testing the same in RSpec. My test looks like this:
describe "Sign in" do
before { visit signup_path }
let(:submit) { "Sign up" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Email", with: "user#gmail.com"
fill_in "Password", with: "securepassword"
end
describe "as a merchant" do
before { choose("Merchant") }
it "should create a merchant user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after creating the merchant user" do
before do
click_button submit
request = ActionController::TestRequest.new(:host => "lvh.me:3000")
end
let(:merchant) { User.find_by_email('user#gmail.com') }
expect (request.subdomain).to eq('merchant')
it { should have_selector 'div.alert.alert-success', text: "Welcome to App!" }
it { should have_link "Sign out", href: signout_path }
it { should_not have_link "Sign in", href: signin_path }
it { should have_content merchant.email }
it { should have_selector "title", text: full_title(merchant.email) }
end
end
describe "as a user" do
before do
choose("User")
request = ActionController::TestRequest.new(:host => "lvh.me:3000")
end
it "should create a normal user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after creating the normal user" do
before { click_button submit }
let(:user) { User.find_by_email('user#gmail.com') }
expect (request.subdomain).to eq('user')
it { should have_selector 'div.alert.alert-success', text: "Welcome to App!" }
it { should have_link "Sign out", href: signout_path }
it { should_not have_link "Sign in", href: signin_path }
it { should have_content user.email }
it { should have_selector "title", text: full_title(user.email) }
end
end
end
end
Error is:
19:58:54 - INFO - Guard::RSpec is running, with RSpec 2!
19:58:54 - INFO - Running all specs
Running tests with args ["--drb", "-f", "progress", "-r", "/usr/local/lib/ruby/gems/1.9.1/gems/guard-rspec-1.2.1/lib/guard/rspec/formatters/notification_rspec.rb", "-f", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--failure-exit-code", "2", "spec"]...
Exception encountered: #<NameError: undefined local variable or method `request' for #<Class:0x007fe0d8058848>>
backtrace:
/home/app/spec/requests/user_pages_spec.rb:46:in `block (5 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/app/spec/requests/user_pages_spec.rb:39:in `block (4 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/app/spec/requests/user_pages_spec.rb:32:in `block (3 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/app/spec/requests/user_pages_spec.rb:26:in `block (2 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/app/spec/requests/user_pages_spec.rb:16:in `block in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/dsl.rb:18:in `describe'
/home/app/spec/requests/user_pages_spec.rb:3:in `<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `block in load'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/test_framework/rspec.rb:11:in `run_tests'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:13:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:21:in `block in initialize'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:18:in `fork'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:18:in `initialize'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `new'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/server.rb:48:in `run'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'
Done.
I tried to print request object to see if anything is there, but its blank. How to access request object in RSpec integration test or is integration test the right place to test for this kind of behavior? Please suggest.
Edit: More Information My data model consists of only single user table where all by default are normal users. However, some are merchants also. Now, when someone signs-in as a user (distinguished using radio button in sign-in form), he should be redirected to user.lvh.me and if he signs-in as a merchant, he should be redirected to merchant.lvh.me. This is what I am trying to test in my integration tests.
You can mock a request using
ActionController::TestRequest.new()
for example
request = ActionController::TestRequest.new(:host => test_domain)
I'm not really clear what behaviour you are trying to test here.
It seems that you have a sign up form where merchants can sign up. Once they have signed up they should get their own subdomain ( merchant1.lvh.me, merchant2.lvh.me). Is that right?
If that is right, then it looks like you are trying to test that the sub-domain for the sign up request should be set. I don't think thats how it works - the client is in control of the domain that the request is made to not the server. I suspect what you want to do is perform a redirect after successful signup to the appropriate subdomian. Thus you want to test that the response is redirecting to the subdomain.