По какой-то причине этот тест не пройден, и это связано с тем, что тест должен отправить по электронной почте.Он не хранит электронную почту в массиве, и у меня есть еще один почти идентичный тест, с той лишь разницей, что он не использует ajax / js для отправки формы, этот тест проходит нормально, и письма попадают в массив.
Есть идеи?
Контроллер:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
UserMailer.join_confirmation(@user).deliver
format.js { render :js => "window.location = '#{temp_success_path}'" }
else
format.html { render :new }
format.js { render :form_errors }
end
end
end
end
user_spec
require 'spec_helper'
describe "Users" do
describe "signup" do
describe "failure" do
it "should not make a new user" do
lambda do
visit root_url
fill_in "user[first_name]", :with => ""
fill_in "user[last_name]", :with => ""
fill_in "user[email]", :with => ""
fill_in "user[password]", :with => ""
fill_in "user[username]", :with => ""
click_button "join_submit"
response.should render_template 'users/new'
response.should have_selector :div, :id => "error_explanation"
last_email.should be_nil
end.should_not change User, :count
end
end
describe "success" do
it "should make a new user" do
lambda do
user = Factory :user
visit root_url
fill_in "user[first_name]", :with => user.first_name
fill_in "user[last_name]", :with => user.last_name
fill_in "user[email]", :with => user.email
fill_in "user[password]", :with => user.password
fill_in "user[username]", :with => user.username
click_button "join_submit"
last_email.to.should include user.email
response.should render_template :js => "window.location = '#{temp_success_path}'"
end.should change User, :count
end
end
end
end
Ошибка:
Failures:
1) Users signup success should make a new user
Failure/Error: last_email.to.should include user.email
NoMethodError:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.to
# ./spec/requests/users_spec.rb:40:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:31:in `block (4 levels) in <top (required)>'
Finished in 148.66 seconds
2 examples, 1 failure
Failed examples:
rspec ./spec/requests/users_spec.rb:29 # Users signup success should make a new user
support / mailer_macros
module MailerMacros
def last_email
ActionMailer::Base.deliveries.last
end
def reset_email
ActionMailer::Base.deliveries = []
end
end