2011-11-02 1 views
1

어떤 이유로이 테스트는 실패하고 테스트가 전자 메일을 보내야 할 때와 관련이 있습니다. 그것은 배열에 이메일을 저장하지 않습니다 그리고 나는 폼 차이에 대한 ajax/js를 사용하지 않고 테스트가 잘 통과하고 이메일이 배열로 전달되는 유일한 차이점과 거의 동일한 또 다른 테스트를 가지고 있습니다.RSpec 통합 테스트가 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 

지원/mailer_macros

module MailerMacros 
    def last_email 
    ActionMailer::Base.deliveries.last 
    end 

    def reset_email 
    ActionMailer::Base.deliveries = [] 
    end 
end 

답변