Skip to content

Instantly share code, notes, and snippets.

@hzm-s
Last active January 3, 2016 04:49
Show Gist options
  • Save hzm-s/8412105 to your computer and use it in GitHub Desktop.
Save hzm-s/8412105 to your computer and use it in GitHub Desktop.
異常系ValidationのE2Eテスト(RSpec,Rails)
context '入力が正しくない' do
[
[:name, "未入力", nil, "can't be blank"],
[:name, "101文字以上", 'a' * 101, "is too long"],
[:display, "101文字以上", 'a' * 101, "is too long"]
]
.each do |attr, state, value, msg|
context "#{attr.to_s.humanize}が#{state}" do
let(:input) { valid_input.merge(attr => value) }
it '保存されないこと' do
expect { subject }.not_to change { Model.count }
end
it 'エラーが表示されること' do
subject
expect(page).to have_content("#{attr.to_s.humanize} #{msg}")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment