Ruby 1.9.3, Rails 3.1.10, RSpec 2.13.0, Capybara 2.2.1
I am writing tests for a Rails 3 app -- a GUI for customers (and admins) to configure various phone settings. I have written 6 or so spec files, with plenty others wrriten before (to which I used as templates). The following is a snapshot of what the spec files look like.
# spec/features/admin/administrators_spec.rb
require 'spec_helper'
include AdministratorHelper
include Helpers
feature "Exercise Administrators page"
include_context "shared admin context"
background do
visit administrators_path
end
scenario "show index page" do
title.should == "Administrators"
end
# ... other happy path tests
# SAD PATH TESTS #
scenario "validation: delete no administrators", js:true do
click_button "Delete"
page.driver.accept_js_confirms!
error_message("Error: You did not select any administrators for deletion.")
end
end
To my understanding, feature
/scenario
are exclusive to Capybara... and acceptance testing. Other collaborators said that our "acceptance tests" test everything -- whether the database saved entries, whether the view is rendered correctly, etc. Each spec is associated with a page in the GUI, not by model/controller.
He had me take a course on edX (CS169.1x), and they taught testing differently -- separate spec file per model and controller. They also used the describe
/context
/it
method of writing tests.
- Is there any advantage to writing tests with
describe
/it
overfeature
/scenario
? (Besides syntactic sugar) - By using Capybara's
feature
/scenario
, does it slow down the test suite? (Compared to using RSpec's keywords) - What exactly are the tests I am writing (as explained in the code block)? Acceptance, unit, a combination?
- Would writing tests like the above alone achieve higher coverage? (Our next goal is >80%)
Thank you for all the help and clarification.