Skip to content

Instantly share code, notes, and snippets.

@refiute
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refiute/9787603 to your computer and use it in GitHub Desktop.
Save refiute/9787603 to your computer and use it in GitHub Desktop.
AOJの補助サイトをTDDやってみながら作った時のテスト
require 'spec_helper'
describe 'Diff' do
before { visit diff_index_path }
specify 'ユーザーがどちらも存在する時' do
within('form') do
fill_in 'user1', with: 'refiute'
fill_in 'user2', with: 'kagasan'
click_button 'Submit'
end
expect(current_path).to eq(diff_path(user1:'refiute', user2:'kagasan'))
end
specify 'ユーザー1が存在しない時' do
within('form') do
fill_in 'user1', with: 'wrong_refiute'
fill_in 'user2', with: 'kagasan'
click_button 'Submit'
end
expect(current_path).to eq(diff_index_path)
end
specify 'ユーザー2が存在しない時' do
within('form') do
fill_in 'user1', with: 'refiute'
fill_in 'user2', with: 'wrong_kagasan'
click_button 'Submit'
end
expect(current_path).to eq(diff_index_path)
end
specify 'ユーザーがどちらも存在しない時' do
within('form') do
fill_in 'user1', with: 'wrong_refiute'
fill_in 'user2', with: 'wrong_kagasan'
click_button 'Submit'
end
expect(current_path).to eq(diff_index_path)
end
end
require 'spec_helper'
describe 'Subject' do
before { visit subject_index_path }
specify 'ユーザーが存在する時' do
within('form') do
fill_in 'username', with: 'bardiche'
click_button 'Submit'
end
expect(current_path).to eq(subject_path(user: 'bardiche'))
end
specify 'ユーザーが存在しない時' do
within('form') do
fill_in 'username', with: 'wrong_refiute'
click_button 'Submit'
end
expect(current_path).to eq(subject_index_path)
end
end
require 'spec_helper'
describe 'TopPage' do
before { visit root_path }
specify '挨拶文が表示される' do
expect(page).to have_css('h1', text: 'Welcome to AOJ-Support')
end
specify 'Diffページへのリンクがある' do
expect(find_link("Diff")).to be_present
find_link("Diff").click
expect(current_path).to eq(diff_index_path)
end
specify 'Subjectページへのリンクがある' do
expect(find_link("Subject")).to be_present
find_link("Subject").click
expect(current_path).to eq(subject_index_path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment