diff --git a/spec/features/calendar/google_calendar_widget_spec.rb b/spec/features/calendar/google_calendar_widget_spec.rb index c9082fb..5bc0c17 100644 --- a/spec/features/calendar/google_calendar_widget_spec.rb +++ b/spec/features/calendar/google_calendar_widget_spec.rb @@ -1,11 +1,18 @@ -require 'spec_helper' +require "spec_helper" + +feature "Google Calendar widget", js: :true do + let(:timezone_name) { Time.zone.name } + let(:events_data_file) { Rails.root.join("spec/fixtures/google_calendar.json") } + let(:events_list_data) { JSON.parse(File.read(events_data_file)) } -feature 'Google Calendar widget', js: :true do before do + allow(GoogleCalendar::Request).to receive(:events_list) + .and_return(GoogleCalendar::EventList.new(events_list_data, timezone_name)) + visit root_path end - scenario 'the most recent upcoming event should appear correctly' do + scenario "the most recent upcoming event should appear correctly" do time = Time.zone.local(2014, 4, 1, 12, 0, 0) Timecop.travel(time) do @@ -15,8 +22,8 @@ feature 'Google Calendar widget', js: :true do end end - feature 'Timezones offsets' do - scenario 'when a user is logged out, CEST is default' do + feature "Timezones offsets" do + scenario "when a user is logged out, CEST is default" do time = Time.zone.local(2014, 4, 1, 12, 0, 0) Timecop.travel(time) do @@ -26,7 +33,7 @@ feature 'Google Calendar widget', js: :true do end end - scenario 'when time has passed under 2 hours after the start date' do + scenario "when time has passed under 2 hours after the start date" do time = Time.zone.local(2014, 4, 4, 23, 59, 0) Timecop.travel(time) do @@ -36,7 +43,7 @@ feature 'Google Calendar widget', js: :true do end end - scenario 'when time has passed over 2 hours after the start date' do + scenario "when time has passed over 2 hours after the start date" do time = Time.zone.local(2014, 4, 5, 0, 1, 0) Timecop.travel(time) do @@ -47,17 +54,24 @@ feature 'Google Calendar widget', js: :true do end end - scenario 'when a user is logged in, their local timezone is used' do - time = Time.zone.local(2014, 4, 1, 12, 0, 0) - user = create(:user) + context "when a user is logged in" do + let(:timezone_name) { "Eastern Time (US & Canada)" } - sign_in_as(user) - change_timezone_for(user, timezone_us_east) + before do + user = create(:user) - Timecop.travel(time) do - visit root_path + sign_in_as(user) + change_timezone_for(user, timezone_name) + end - expect(first_event).to have_content(timezone_adjusted) + scenario "their local timezone is used" do + time = Time.zone.local(2014, 4, 1, 12, 0, 0) + + Timecop.travel(time) do + visit root_path + + expect(first_event).to have_content(timezone_adjusted) + end end end end @@ -75,8 +89,4 @@ feature 'Google Calendar widget', js: :true do "15:30 EST" end end - - def timezone_us_east - "Eastern Time (US & Canada)" - end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 85567d0..9a147eb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,26 +1,29 @@ -ENV["RAILS_ENV"] ||= 'test' +ENV["RAILS_ENV"] ||= "test" + +require "codeclimate-test-reporter" +require "simplecov" -require 'codeclimate-test-reporter' -require 'simplecov' CodeClimate::TestReporter.start -SimpleCov.start 'rails' +SimpleCov.start "rails" require File.expand_path("../../config/environment", __FILE__) -require 'rspec/rails' -require 'capybara/rspec' -require 'capybara/poltergeist' +require "rspec/rails" +require "capybara/rspec" +require "capybara/poltergeist" + +Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } -Capybara.default_wait_time = 5 Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, timeout: 30, - phantomjs_logger: File.open('/dev/null') + phantomjs_logger: File.open("/dev/null") ) end -Capybara.javascript_driver = :poltergeist - -Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } +Capybara.configure do |config| + config.default_wait_time = 5 + config.javascript_driver = :poltergeist +end RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods @@ -30,17 +33,9 @@ RSpec.configure do |config| config.include Features::SessionHelpers, type: :feature config.fixture_path = "#{::Rails.root}/spec/fixtures" - config.order = 'random' + config.order = :random config.use_transactional_fixtures = false config.color = true config.formatter = :documentation config.infer_spec_type_from_file_location! - - config.before(:each) do - events_list_json = JSON.parse(File.read(Rails.root.join('spec/fixtures/google_calendar.json'))) - - GoogleCalendar::Request.stub(:events_list) do - GoogleCalendar::EventList.new(events_list_json, Time.zone.name) - end - end end