Skip to content

Instantly share code, notes, and snippets.

@idengager
Created November 22, 2013 09:46
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 idengager/7597445 to your computer and use it in GitHub Desktop.
Save idengager/7597445 to your computer and use it in GitHub Desktop.
Event#index tests
require 'spec_helper'
describe 'Event index' do
context 'when user is not signed-in' do
before do
stub_request(:get, "http://localhost:9292/events?token=").
to_return(status: 200, body: { message: [public_event, private_event, past_event, future_event] }.to_json, headers: {})
visit '/events'
end
subject { page }
it { should have_link(public_event[:name]) }
it { should_not have_link(private_event[:name]) }
it 'should only list events happening this month' do
expect(page).to have_link(public_event[:name])
expect(page).not_to have_link(future_event[:name])
end
context 'after clicking next month button' do
before { page.find(:xpath, "//a[@href='/events?date=#{(Date.today >> 1).to_s}']").click }
it 'should list events happening next month' do
expect(page).to have_link(future_event[:name])
end
end
context 'after clicking previous month button' do
before { page.find(:xpath, "//a[@href='/events?date=#{(Date.today << 1).to_s}']").click }
it 'should list events that happened previous month' do
expect(page).to have_link(past_event[:name])
end
end
end
context 'when user is signed-in' do
before do
stub_request(:get, "http://localhost:9292/events?token=").
to_return(status: 200, body: { message: [public_event, private_event] }.to_json, headers: {})
visit '/events'
end
subject { page }
it { should have_link(public_event[:name]) }
it { should have_link(private_event[:name]) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment