2011-12-14 81 views

回答

1

我沒有用之前email_spec,但它看起來很酷。

你可以看到我是如何在規範文件來測試小馬,這可能是你的情況下工作:

https://github.com/benprew/pony/blob/master/spec/pony_spec.rb

此外,您還可以通過提供的消息:測試,它將使用包含在測試郵件附帶郵件:

有關檢查測試消息的示例,請參閱「在測試或特定庫中使用郵件」,地址爲https://github.com/mikel/mail

+0

這就是我所做的 - 從你的規範文件竊取代碼;) – zlog 2011-12-18 12:35:35

3

我結束了在看pony spec file,並竊取代碼它來寫我的規格=)

這是我有:

./spec/spec_helper.rb

def do_not_send_email 
    Pony.stub!(:deliver) # Hijack deliver method to not send email 
end 

RSpec.configure do |conf| 
    conf.include Rack::Test::Methods 
    conf.mock_with :rspec 

    # ... 

    conf.before(:each) do 
    do_not_send_email 
    end 
end 

./spec/integration/invite_user_spec.rb

require_relative '../spec_helper' 

feature "Invite user" do 
    scenario "should send an invitation email" do 
    visit "/" 
    click_link "start-btn" 

    within_fieldset("Invite new user") do 
     fill_in 'new_user_email', :with => '[email protected]' 

     Pony.should_receive(:mail) { |params| 
     params[:to].should == "[email protected]" 
     params[:subject].should include("You are invited to blah") 

     params[:body].should include("You've been invited to blah") 
     params[:body].should include("/#{@account_id}/new-user/register") 
     } 
     click_button 'new_user' 
    end 

    page.should have_content("Invitation email has been sent") 
    end 
end 
相關問題