RailsによるアジャイルWebアプリケーション開発

第13章 イテレーションH2

統合テストはfeatureとして、省略して書いてみた。

require 'rails_helper'

feature "User Stories" do
  background do
    @book = create(:product)
  end

  scenario "buying a product", js: true do
    visit store_path
    click_button "カートに入れる"
    sleep 2
    click_button "チェックアウト"

    order = attributes_for(:order)
    fill_in "Name", with: order[:name]
    fill_in "Address", with: order[:address]
    fill_in "Email", with: order[:email]
    select "現金", from: "Pay type"
    save_screenshot sc_path("user_stories_1.png")

    click_button "注文する"
    expect(find("#notice")).to have_content "ご注文ありがとうございます"

    mail = ActionMailer::Base.deliveries.last
    expect(mail.to).to eq [order[:email]]
    save_screenshot sc_path("user_stories_2.png")
  end
end

f:id:yossk:20150124153731p:plain
f:id:yossk:20150124153741p:plain

また、deliverメソッドがdeprecateになってるので、deliver_nowにした。

DEPRECATION WARNING: `#deliver` is deprecated and will be removed in Rails 5. Use `#deliver_now` to deliver immediately or `#deliver_later` to deliver through Active Job.