Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Selenium-Chrome rspec test integration #283

Open
wants to merge 10 commits into
base: development
Choose a base branch
from
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ group :development, :test do
gem 'factory_girl_rails'
gem 'capybara'
gem 'launchy'
gem 'selenium-webdriver'
gem 'database_cleaner'
gem 'coveralls', require: false
gem 'fuubar'
end
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ GEM
crass (0.2.1)
daemons (1.1.9)
dalli (2.7.2)
database_cleaner (1.3.0)
delayed_job (4.0.2)
activesupport (>= 3.0, < 4.2)
delayed_job_active_record (4.0.1)
Expand Down Expand Up @@ -358,6 +359,11 @@ GEM
tilt (~> 1.3)
scrollToFixed_rails (1.0.5)
railties (>= 3.1)
selenium-webdriver (2.35.1)
childprocess (>= 0.2.5)
multi_json (~> 1.0)
rubyzip (< 1.0.0)
websocket (~> 1.0.4)
simplecov (0.9.1)
docile (~> 1.1.0)
multi_json (~> 1.0)
Expand Down Expand Up @@ -404,6 +410,7 @@ GEM
uuidtools (2.1.5)
warden (1.2.3)
rack (>= 1.0)
websocket (1.0.7)
win32-process (0.7.4)
ffi (>= 1.0.0)
win32console (1.3.2-x86-mingw32)
Expand Down Expand Up @@ -442,6 +449,7 @@ DEPENDENCIES
coveralls
daemons
dalli
database_cleaner
delayed_job_active_record
devise (= 3.0)
exception_notification
Expand Down Expand Up @@ -480,6 +488,7 @@ DEPENDENCIES
sanitize
sass-rails (~> 3.2.3)
scrollToFixed_rails (~> 1.0.0)
selenium-webdriver
simple_form!
slugged (~> 2.0)
spork-rails
Expand Down
14 changes: 6 additions & 8 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
config.use_transactional_fixtures = false

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
Expand All @@ -35,8 +28,13 @@
config.include Warden::Test::Helpers

config.include Capybara::DSL

Capybara.default_wait_time = 3

Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

config.before(:each) {
Warden.test_mode!
}
Expand Down
47 changes: 47 additions & 0 deletions spec/requests/announcement_pages_copy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'rails_helper'

RSpec.describe "AnnouncementPages", :type => :request do

let(:admin) {FactoryGirl.create(:admin)}
let(:course) { FactoryGirl.create(:course) }
before do
sign_in admin
create_course course
end

describe "Announcement Creation", :js => true do
before do
visit course_announcements_path(course)
end

describe "Test 1" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title must have an actual meaning

it "shows the new button" do
expect(page).to have_link('New', href: new_course_announcement_path(course))
end
end

describe "create action" do
before do
click_link 'New'
end

it "displays the content" do
expect(page).to have_field("announcement_title")
expect(page).to have_selector("iframe.wysihtml5-sandbox")
end

describe "with valid information" do
let(:announcement) {FactoryGirl.build(:announcement)}
before do
fill_in 'announcement_title', with: announcement.title
page.execute_script("$('#announcement_description').attr('value','abcd');")
end

it "should create an announcement", :js => true do
expect(page).to have_selector("textarea[value='abcd']", visible: false)
expect { click_button 'Create'}.to change(Announcement, :count).by(1)
end
end
end
end
end
36 changes: 36 additions & 0 deletions spec/support/database_cleaner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
RSpec.configure do |config|

config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
load Rails.root + "db/seeds.rb"
# puts "before suite"
end

config.before(:each) do
DatabaseCleaner.strategy = :transaction
# puts "Before Normal"
end

config.before(:each, :js => true) do
Capybara.current_driver = :selenium_chrome
DatabaseCleaner.strategy = :truncation
# puts "Before JS"
end

config.before(:each) do
DatabaseCleaner.start
# puts "Before all"
end

config.after(:each, :js => true) do
load Rails.root + "db/seeds.rb"
Capybara.use_default_driver
# puts "After JS"
end

config.after(:each) do
DatabaseCleaner.clean
# puts "After all"
end

end