By Neha Suwal on Mar, 18, 2016 in rails, testing, rspec, capybara
Rails makes it easier to write your tests. Rspec- rails extends Rails' built-in testing framework to support rspec for requests, controllers, models, views, helpers, mailers and routing.
To install rspec-rails in your rails project, you need to add “ gem rspec-rails ” in your development and test group. Then run bundle install. The “ rails generate rspec:install ” , this command adds spec folder with spec_helper.rb and rails_helper.rb which is used for configurations. For running the specs, “ bundle exec rspec ” is used. By default all _spec.rb files in the spec folder is run.
Rspec testing can be of various types such as controller, model, view, feature, routing, request.
Amongst these all feature testing are high-level tests that walk through your entire application ensuring that each of the components works together. For using feature test we use Capybara, which allow you to write tests that can interact with the web page.
For installing capybara in the project, add ‘gem capybara ’ in your test group. Then run bundle install. Then require capybara/ rails in your spec_helper.rb. To run the test via capybara, selenium-webdriver is required. So you need to add selenium-webdriver in the gem file and run bundle install.
Writing feature test via capybara is a fun element in rails for testing.
Don't miss the next one!