Skip to content

This is an example app for using minitest and capybara in rails. It also contains a travis setup.

Notifications You must be signed in to change notification settings

info3-ss2013/rails_testing_example

Repository files navigation

Build Status

README

This is an example a simple integration test in rails using minitest and capybara. It has three parts:

Running tests

 rake

runs the default rake task which is test - runs all test cases. You can also run specific groups with

rake test:integration

and run single test files with

rake test TEST=test/integration/first_items_integration_test.rb

Minitest

Minitest is a testing framework for ruby. It is the default test framework for Rails 4 and substitutes Unit::Test which was the default in Rails 3.2

Here's a short intro to using minitest with Rails 3.2

Note that you won't need any of the setup steps in rails 4 as minitest is already the default there.

It also replaces rspec, which was often used as an alternative to unit::test in rails 3.2.

Capybara

Capybara is a library that enables you to automate website testing: Going to a page, clicking on links and buttons, checking if content is there.

You should have at least one integration test per story.

see the integration tests in

test/integration/

for examples. The rest of the testcases have been generated by the scaffold generator.

Model Tests

If you implement behaviour in the model, write a model unit test for it, I've included a very simple example in

test/models/item_test.rb

Opening the current page

If you get stuck with your tests, it is often helpful to have a look at the generated page. To do that, include the launchy gem in your Gemfile and call

save_and_open_page

from within your test case.

Finding out the class of something

Putting somethin like

assert_equal "xx", page.class

in one of your tests let's you find out the class of page, which is Capybara::Session.

About

This is an example app for using minitest and capybara in rails. It also contains a travis setup.

Resources

Stars

Watchers

Forks

Packages

No packages published