Project

General

Profile

Test environment » History » Version 7

Version 6 (Tommy McNeely, 03/18/2015 05:03 PM) → Version 7/9 (Tommy McNeely, 11/18/2015 06:03 PM)

h1. Test environment

h2. Prerequisites

# Install PhantomJS - http://phantomjs.org/download.html
The directions below are to install the binary version of PhantomJS 1.9.8 into `/usr/local/bin`, which requires sudo/root access. If you want to install it locally, that should work as well.
<pre>
curl -LO https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
sudo tar xf phantomjs-1.9.8-linux-x86_64.tar.bz2 -C /usr/local
sudo ln -sf /usr/local/phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/local/bin/
</pre>
# PhantomJS also requires fontconfig and freetype
<pre>
yum -y install fontconfig freetype
</pre>

h2.
Installation

# Add a test database in your database.yml configuration file :
<pre>
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
</pre>
# Create your database with :
<pre> ~foreman$ RAILS_ENV=test rake db:migrate </pre>
# Run the all tests :
<pre>~foreman$ RAILS_ENV=test rake test</pre>
# Or a singe test :
<pre>~foreman/test$ RAILS_ENV=test ruby -I . functional/your_test.rb </pre>

h2. Troubleshooting

* If you have some errors like that :
<pre> /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- rr (MissingSourceFile) </pre>
juste install missing gem. In that case :
<pre>gem install rr</pre>

* If you get this kind of errors when running functional tests:
<pre>
test_should_not_remove_the_anonymous_role(UsersControllerTest):
ActionController::RoutingError: No route matches {:controller=>"users", :commit=>"Submit", :id=>980190963, :action=>"update", :user=>{:login=>"johnsmith"}}
test/functional/users_controller_test.rb:32:in `test_should_not_remove_the_anonymous_role'
</pre>
it means you need to set `:login: true` in the `config/settings.yaml` file.

* If you get errors related to `LocationsController` or `OrganizationsController` when running functional tests it means you need to set `:locations_enabled: true` and `:organizations_enabled: true`. Example errors:
<pre>
Api::V2::LocationsControllerTest#test_0001_should get index:
ActionController::RoutingError: No route matches {:controller=>"api/v2/locations"}
</pre>
<pre>
OrganizationsControllerTest#test_0001_should get index:
ActionController::RoutingError: No route matches {:controller=>"organizations"}
</pre>
<pre>
LocationTest#test_0001_index page:
NameError: undefined local variable or method `locations_path' for #<LocationTest:0x0000000b399030>
</pre>
<pre>
OrganizationTest#test_0001_index page:
NameError: undefined local variable or method `organizations_path' for #<OrganizationTest:0x0000000f6350d8>
</pre>