Skip to content

Commit

Permalink
Move JS tests from Selenium/Firefox to PhantomJS
Browse files Browse the repository at this point in the history
  • Loading branch information
cdouglass committed Jun 1, 2016
1 parent f0442c6 commit 4e6dbf2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ end
group :development, :test do
gem 'rspec-rails', '~> 3.4.2'
gem 'factory_girl_rails', '~> 4.6.0'
gem 'selenium-webdriver', '~> 2.52'
gem 'capybara', '~> 2.6.2'
gem 'capybara-webkit', '~> 1.8.0'
gem 'phantomjs', '~> 2.1.1'
gem 'poltergeist', '~> 1.9.0'
gem 'database_cleaner', '~> 1.5.1'
gem 'fakeweb', '~> 1.3.0'
gem 'shoulda-matchers', '~> 3.1'
Expand Down
32 changes: 16 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
capybara-webkit (1.8.0)
capybara (>= 2.3.0, < 2.7.0)
json
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
cliver (0.3.2)
coderay (1.1.1)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -104,7 +100,6 @@ GEM
fakeweb (1.3.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.10)
figaro (0.7.0)
bundler (~> 1.0)
rails (>= 3, < 5)
Expand Down Expand Up @@ -200,6 +195,12 @@ GEM
orm_adapter (0.5.0)
os (0.9.6)
pg (0.18.4)
phantomjs (2.1.1.0)
poltergeist (1.9.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
premailer (1.8.6)
css_parser (>= 1.3.6)
htmlentities (>= 4.0.0)
Expand Down Expand Up @@ -274,19 +275,13 @@ GEM
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubyzip (1.2.0)
sass (3.4.21)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (2.52.0)
childprocess (~> 0.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0)
shortener (0.5.5)
rails (>= 3.0.7)
shoulda-matchers (3.1.1)
Expand Down Expand Up @@ -330,7 +325,9 @@ GEM
activemodel (>= 4.2)
debug_inspector
railties (>= 4.2)
websocket (1.2.2)
websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
will_paginate (3.1.0)
xpath (2.0.0)
nokogiri (~> 1.3)
Expand All @@ -342,7 +339,6 @@ DEPENDENCIES
better_errors (~> 2.1.1)
binding_of_caller (~> 0.7.2)
capybara (~> 2.6.2)
capybara-webkit (~> 1.8.0)
coffee-rails (~> 4.1.1)
database_cleaner (~> 1.5.1)
derailed
Expand All @@ -360,6 +356,8 @@ DEPENDENCIES
nokogiri (~> 1.6.7.2)
omniauth-github (~> 1.1.2)
pg (~> 0.18.4)
phantomjs (~> 2.1.1)
poltergeist (~> 1.9.0)
premailer-rails (~> 1.9)
pry-byebug (~> 3.3)
puma (~> 2.16.0)
Expand All @@ -370,7 +368,6 @@ DEPENDENCIES
redcarpet (~> 3.3.4)
rspec-rails (~> 3.4.2)
sass-rails (~> 5.0.4)
selenium-webdriver (~> 2.52)
shortener (~> 0.5.5)
shoulda-matchers (~> 3.1)
simple_form (~> 3.2.1)
Expand All @@ -380,5 +377,8 @@ DEPENDENCIES
web-console (~> 3.0)
will_paginate (~> 3.1.0)

RUBY VERSION
ruby 2.3.0p0

BUNDLED WITH
1.11.2
1.12.5
33 changes: 13 additions & 20 deletions doc/linux_setup.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
## Setup ruby
In case you don't have the version of ruby that the TheOdinProject uses, install it with rvm:
## Set up Ruby
In case you don't have the version of Ruby that the TheOdinProject uses, install it with rvm:
```
$ rvm install ruby-2.3
$ rvm use ruby-2.3
```

#### Bundler
If you needed to install the ruby version specified previously, then you're going to need to install bundler all over again, run the following commands for that:
If you needed to install the Ruby version specified previously, then you're going to need to install bundler all over again. Run the following commands for that:
```
$ sudo apt-get install bundler
$ gem install bundler
$ gem install bundle
```

## Setup postgres
## Set up Postgres
Skip this is you have already installed and setup a user for postgresql.
First, we add the repository and then install postgresql and it's dependencies:
First, we add the repository and then install postgresql and its dependencies:
```
$ sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
$ wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql-common
$ sudo apt-get install postgresql-9.3 libpq-dev
```
Next we need to create our role, run the following:
Next we need to create our role. Run the following:
```
$ sudo -u postgres createuser yourusername -s
$ sudo -i -u postgres psql
Expand All @@ -34,37 +34,30 @@ postgres=# \password yourusername
# Type \q to quit
```

## Gems
Okay, first we need to install some dependencies that the gem `capybara-webkit` has and then install the actual gem(we also install the postgres gem here):
## Installing Gems and Migrating the Database
Now we need to pull down TOP's repository. To do this, go ahead and `fork` [TOP](https://github.com/TheOdinProject/theodinproject.git) repository. In your terminal run:
```
$ sudo apt-get install qt4-dev-tools libqt4-dev libqt4-core libqt4-gui
$ gem install pg -v '0.17.1'
$ gem install capybara-webkit -v '1.1.1'
```

Now we need to pull down TOP's repository. To do this, go ahead an `fork` [TOP](https://github.com/TheOdinProject/theodinproject.git) repository. On your terminal run:
```
git clone https://github.com/YOUR_USERNAME_HERE/theodinproject.git
$ git clone https://github.com/YOUR_USERNAME_HERE/theodinproject.git
# Once git finishes cloning, cd into the project directory with
cd theodinproject
$ cd theodinproject
```
With all that taken care of, run `bundle` and everything should be green.
```
$ bundle install
```

Once bundle finishes, go to `config/database.yml` and write your username and password(only if you added a password) of postgresql for the development and the test database(leave the production alone), next we create and migrate the database:
Once bundle finishes, go to `config/database.yml` and write your username and password (only if you added a password) of postgresql for the development and the test database (leave the production alone). Next we create and migrate the database:
```
$ rake db:create
$ rake db:migrate
```

Finally set up the test database
Set up the test database:
```
$ rake db:test:prepare
```

Get the server up and running with:
Finally, get the server up and running with
```
$ rails s
```
Expand Down
1 change: 1 addition & 0 deletions spec/features/courses_lessons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@
end
it "should not hide the lesson completed check (JS test)", :js => true do
find("a.lc-unchecked").click
wait_for_ajax
expect(page).to_not have_css(".lc-completion-indicator.hidden")
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/features/search_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper'
require 'capybara-webkit'
require 'fakeweb'

feature "Search" do
Expand Down Expand Up @@ -30,7 +29,7 @@
visit curriculum_path
# Make the window big enough so the navbar doesn't collapse
# and hide the search field!
page.driver.browser.manage.window.resize_to(1200,600)
page.driver.resize(1200,600)
end

it "should have a searchbox (JS TEST)", :js => true do
Expand Down
1 change: 0 additions & 1 deletion spec/features/static_pages_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'spec_helper'
require 'database_cleaner'
require 'capybara-webkit'

describe "StaticPages" do

Expand Down
13 changes: 6 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
require 'phantomjs'
require 'capybara/poltergeist'
DEFAULT_HOST = "localhost"

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
Timeout.timeout(Capybara.default_max_wait_time) do
loop do
active = page.evaluate_script('jQuery.active')
break if active == 0
Expand All @@ -23,15 +25,12 @@ def wait_for_ajax

RSpec.configure do |config|
config.include Capybara::DSL
Capybara.javascript_driver = :webkit
Capybara.javascript_driver = :poltergeist
Capybara.always_include_port = true
Capybara.default_host = "http://#{DEFAULT_HOST}"
#fixes issues with capybara not detecting db changes made during tests
config.use_transactional_fixtures = false

# Capybara.default_driver = :selenium
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox)
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path)
end

config.before :each do
Expand Down
4 changes: 2 additions & 2 deletions spec/support/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

config.before(:each) do |example|
if example.metadata[:js]
Capybara.current_driver = :selenium
Capybara.current_driver = :poltergeist
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
Expand All @@ -25,4 +25,4 @@
Capybara.use_default_driver if example.metadata[:js]
DatabaseCleaner.clean
end
end
end

0 comments on commit 4e6dbf2

Please sign in to comment.