This is my code snippet to test the polymorphic relationship.
I wrote test as below.
require 'rails_helper'
RSpec.describe Proration, type: :model do
let(:invoice_item) { FactoryGirl.create(:proration_invoice_item) }
subject { :invoice_item }
it { should be_valid }
it { should respond_to(:total_amount) }
it { should respond_to(:invoice) }
it { should respond_to(:itemable) }
end
But this errors out
Failures:
1) Proration should be valid
Failure/Error: it { should be_valid }
NoMethodError:
undefined method `valid?' for :invoice_item:Symbol
# ./spec/models/proration_spec.rb:7:in `block (2 levels) in <top (required)>'
2) Proration Proration should respond to #total_amount
Failure/Error: end
expected :invoice_item to respond to :total_amount
# ./spec/models/proration_spec.rb:16:in `block (3 levels) in <top (required)>'
3) Proration Proration should respond to #invoice
Failure/Error: end
expected :invoice_item to respond to :invoice
# ./spec/models/proration_spec.rb:17:in `block (3 levels) in <top (required)>'
4) Proration Proration should respond to #itemable
Failure/Error: Unable to find matching line in /Users/toshikiinami/Desktop/billing/spec/models/proration_spec.rb
expected :invoice_item to respond to :itemable
# ./spec/models/proration_spec.rb:18:in `block (3 levels) in <top (required)>'
Any ideas to fix this?
(respond_to for model doesn't work.)
You defined an invoice_item using let, but as a subject you're using symbol. What you want instead is that object invoice_item, so
subject{ :invoice_item }
should be changed to
subject{ invoice_item }
Related
I have a module with a custom view helper. Actually it uses the modified code of link_to helper. Just append a query string to the generated link. I have existing tests which fails because the custom helper cannot be found. How can I include it so it is available for RSpec? I tried the following approaches:
1.Using include:
describe MyClass do
include MyHelper
2.Using configure
RSpec.configure do |config|
config.include MyHelper
end
3.Adding it in spec_helper.rb
config.include MyHelper
Here is the error:
1) Mailer#calendar_item_notification should send email for task
Failure/Error: expect {Mailer.calendar_item_notification('User', #user.id).deliver}.to change { ActionMailer::Base.deliveries.count }.by(1)
ActionView::Template::Error:
undefined method `<<' for #<Proc:0x00000013102d28>
# ./app/helpers/mailer_helper.rb:88:in `link_username'
# ./app/views/user_mailer/calendar_item_notification.html.erb:137:in `_app_views_user_mailer_calendar_item_notification_html_erb___206027131771876632_159436760'
# ./app/mailers/user_mailer.rb:136:in `calendar_item_notification'
# ./spec/mailers/user_mailer_spec.rb:19:in `block (4 levels) in <top (required)>'
# ./spec/mailers/user_mailer_spec.rb:19:in `block (3 levels) in <top (required)>'
# ./spec/support/misc.rb:13:in `block in suppress_output'
# ./spec/support/misc.rb:12:in `tap'
# ./spec/support/misc.rb:12:in `suppress_output'
# -e:1:in `<main>'
Thanks
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 have two methods in my Designer class (in my rails app):
def add_specialty(specialty)
specialty_list.add(specialty)
save
end
def add_qualification(qualification)
qualification_list.add(qualification)
save
end
Here are specs I have for them that are passing:
context 'adding specialties' do
it "can add a new specialty" do
expect { designer.add_specialty("interior design") }.to change {designer.specialty_list.count}.by(1)
expect(designer.specialty_list).to include("interior design")
end
end
context 'adding qualifications' do
it "can add a new qualification" do
expect { designer.add_qualification("architect") }.to change {designer.qualification_list.count}.by(1)
expect(designer.qualification_list).to include("architect")
end
end
Now I want to refactor to this implementation:
["specialty", "qualification"].each do |attr|
define_method("add_#{attr}") do |arg|
"#{attr}_list".add(arg)
save
end
end
This fails. I get failures:
1) Designer adding qualifications can add a new qualification
Failure/Error: expect { designer.add_qualification("architect") }.to change {designer.qualification_list.count}.by(1)
NoMethodError:
undefined method `add' for "qualification_list":String
# ./app/models/designer.rb:93:in `block (2 levels) in <class:Designer>'
# ./spec/models/designer_spec.rb:79:in `block (4 levels) in <top (required)>'
# ./spec/models/designer_spec.rb:79:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'
2) Designer adding specialties can add a new specialty
Failure/Error: expect { designer.add_specialty("interior design") }.to change {designer.specialty_list.count}.by(1)
NoMethodError:
undefined method `add' for "specialty_list":String
# ./app/models/designer.rb:93:in `block (2 levels) in <class:Designer>'
# ./spec/models/designer_spec.rb:72:in `block (4 levels) in <top (required)>'
# ./spec/models/designer_spec.rb:72:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'
What am I doing wrong in my define_method implementation?
"#{attr}_list" by itself is just the string "specialty_list" or "qualification_list", and strings don't have an add method. I think you want to the send the specialty_list method e.g.
%w{ specialty qualification }.each do |attr|
define_method("add_#{attr}") do |arg|
send("#{attr}_list").add(arg)
save
end
end
Ok: I got it working like this:
["specialty", "qualification"].each do |attr|
define_method("add_#{attr}") do |arg|
instance_eval("#{attr}_list").send(:add, arg)
save
end
end
Not sure why this worked though or if its the right way to do it. Would anyone care to contribute towards a better understanding?
I was changing some parts of code, and my tests started to give errors and warnings.
Then I removed those tests, because I couldn't fix them.
But then tests in my other file totally went awry.
The following is my factories.rb file:
FactoryGirl.define do
factory :user do
sequence(:name) { |n| "Person #{n}" }
sequence(:surname) { |n| "Persona #{n}" }
sequence(:email) { |n| "person_persona_#{n}#example.com.eu" }
password "foobar"
password_confirmation "foobar"
# factory :admin do
# admin true
# end
factory :admin do
role "admin"
end
factory :editor do
role "editor"
end
factory :author do
role "author"
end
end
factory :course do
sequence(:title) { |n| "Title #{n}" }
sequence(:objectives) { |n| "Objectives #{n}" }
user_id 1
subject_id 1
student_level_id 1
end
factory :subject do
title "French for Adults"
end
factory :student_level do
title "Advanced"
end
end
And this is my actual test file, models/course_spec.rb:
require 'spec_helper'
describe Course do
let (:user) { FactoryGirl.create(:user) }
let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
let (:student_level) { FactoryGirl.create(:student_level) }
before do
# #course = Course.new(user_id: user.id, subject_id: subject_.id, student_level_id: student_level.id,
# title: "French for Us", objectives: "Lorem ipsum")
#course = user.courses.build(title: "French", objectives: "lorem")
#course.subject = subject_
#course.student_level = student_level
end
subject { #course }
it { should respond_to(:user_id) }
it { should respond_to(:subject_id) }
it { should respond_to(:student_level_id) }
it { should respond_to(:title) }
it { should respond_to(:objectives) }
it { should respond_to(:user) }
its(:user) { should == user }
it { should be_valid }
describe "when user_id is not present" do
before { #course.user_id = nil }
it { should_not be_valid }
end
describe "when subject_id is not present" do
before { #course.subject_id = nil }
it { should_not be_valid }
end
describe "when student_level_id is not present" do
before { #course.student_level_id = nil }
it { should_not be_valid }
end
describe "when title is not present" do
before { #course.title = "" }
it { should_not be_valid }
end
describe "when title is too long" do
before { #course.title = "a" * 251 }
it { should_not be_valid }
end
describe "when title is already taken" do
before do
course_with_same_title = #course.dup
course_with_same_title.title = #course.title.upcase
course_with_same_title.save
end
it { should_not be_valid }
end
describe "when objectives are not present" do
before { #course.objectives = "" }
it { should_not be_valid }
end
describe "accessible attributes" do
it "should not allow access user_id" do
expect do
Course.new(user_id: user.id)
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
end
# it "should not allow access subject_id" do
# expect do
# Course.new(subject_id: subject_.id)
# end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
# end
# it "should not allow access student_level_id" do
# expect do
# Course.new(student_level_id: student_level.id)
# end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
# end
end
end
And these are test outputs:
:~/ror/oy$ bundle exec rspec
...............................................................FFFFFFFFFFFFFFFF.................................................
Failures:
1) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
2) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
3) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
4) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
5) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
6) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
7) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
8) Course when user_id is not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
9) Course user
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
10) Course when title is already taken
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
11) Course when objectives are not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
12) Course accessible attributes should not allow access user_id
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
13) Course when title is too long
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
14) Course when subject_id is not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
15) Course when student_level_id is not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
16) Course when title is not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
Finished in 7.82 seconds
128 examples, 16 failures
Failed examples:
rspec ./spec/models/course_spec.rb:36 # Course
rspec ./spec/models/course_spec.rb:37 # Course
rspec ./spec/models/course_spec.rb:34 # Course
rspec ./spec/models/course_spec.rb:35 # Course
rspec ./spec/models/course_spec.rb:33 # Course
rspec ./spec/models/course_spec.rb:41 # Course
rspec ./spec/models/course_spec.rb:38 # Course
rspec ./spec/models/course_spec.rb:45 # Course when user_id is not present
rspec ./spec/models/course_spec.rb:39 # Course user
rspec ./spec/models/course_spec.rb:76 # Course when title is already taken
rspec ./spec/models/course_spec.rb:82 # Course when objectives are not present
rspec ./spec/models/course_spec.rb:86 # Course accessible attributes should not allow access user_id
rspec ./spec/models/course_spec.rb:65 # Course when title is too long
rspec ./spec/models/course_spec.rb:50 # Course when subject_id is not present
rspec ./spec/models/course_spec.rb:55 # Course when student_level_id is not present
rspec ./spec/models/course_spec.rb:60 # Course when title is not present
Randomized with seed 44955
I suppose there is problem with factories.rb file. But I checked it with the same file on other branch, nothing changed actually.
What could be wrong here?
I ran
$ rake db:test:prepare
per this thread: Suddenly ALL RSpec tests failing?
And everything worked fine.
I suggest you check the following things
schema, migration: make sure your object has the correct attributes
model validation: this is highly the reason that cause your test fail. Last time I had this invalid_record error is because of a validation fault
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.