2016-03-27 51 views
0

我是新來的功能測試和水豚,我現在有一個真正簡單的功能測試,我不能讓它通過,但我相信這是因爲我的'做錯了寫測試。我會發布我的測試,讓我知道是否有任何東西跳出來,是一個明確的開發錯誤。我認爲這是我用這張支票做的事情?功能測試失敗時,試圖使用「檢查」

require "rails_helper" 

RSpec.feature "Send a message" do 
    scenario "Staff can send a message" do 
    visit "/" 

group = Group.create!(name: "Group A") 
user = User.create!(email: "[email protected]", password: "password") 
fill_in "Email", with: "[email protected]" 
fill_in "Password", with: "password" 
click_button "Sign in" 

fill_in "Enter a Message:", with: "Test Message" 
check("message_group_#{group.id}") 
click_button "Send Message" 


expect(page).to have_content("Messages on their way!") 
end 

這是我得到的錯誤消息。

Send a message Staff can send a message 
Failure/Error: expect(page).to have_content("Messages on their way!") 
    expected to find text "Messages on their way!" in "Tulip Time Text Numbers Sent Messages Scheduled Messages Statistics [email protected] Logout SMS Notifications Use this form to send SMS notifications to Visitors, Staff or Volunteers. Enter a Message: Groups: Group A Scheduled Text Message:" 

Message.rb

def create 
@message = Message.create(message_params) 
if @message.save 
    run_at_time = @message.send_at.present? ? @message.send_at : Time.zone.now 
    people = Person.in_groups(message_params[:group_ids]) 
    if people.any? 
    people.each do |person| 
     person.delay(run_at: run_at_time).send_message(@message.body) 
    end 
    flash[:success] = "Messages on their way!" 
    end 
    redirect_to root_path 
else 
    render "new" 
end 
end 

enter image description here

+2

是什麼讓你覺得檢查是問題?如果檢查失敗,Capybara會在該行發現錯誤,您應該檢查測試日誌並檢查提交的參數 –

+0

是的,這不是檢查,但我仍然不明白爲什麼它沒有我建議的內容。它通過所有驗證,並通過一切手段代碼應該通過,但它只是不會? – Bitwise

+0

發佈您的控制器代碼和響應HTML –

回答

1

要創建作爲測試數據的組是空的,所以被設定不閃光消息。您可能不想親手創建對象,而是需要使用工廠庫(FactoryGirl,Machinist等)中的一個來幫助構建對象,而無需每次都提供所有值,並且還可以構建所需的關聯。

相關問題