2 つの重複部分がある機能テストがあります。
require 'spec_helper'
describe "Messages manage" do
let (:user) { create :user }
let (:other_user) { create :use }
before(:each) do
login_as user
end
describe "[message create]" do
it "messages created by self, should appear on the page", js: true do
message_text = "Hello my friend"
visit user_messages_path(user, {with:other_user.id} )
fill_in :message_body, with: message_text
click_button t("users.messages.index.send")
sleep 1 # waiting for js
page.should have_content(message_text)
find_field(:message_body).value.should == ""
page.should have_selector('#message_body', visible: false)
end
it "message errors should be displayed", js: true do
message_text = "123"
visit user_messages_path(user, {with:other_user.id} )
fill_in :message_body, with: message_text
click_button t("users.messages.index.send")
sleep 1 # waiting for js
page.should_not have_content("Message: #{message_text}")
find_field(:message_body).value.should == message_text
page.should have_selector('.message.error', visible: true)
end
end
end
この状況で、shared_examples などを使用する最善の方法は何ですか? 次のDRYへ。