Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I run multiple tests for one controller load or Capypara page load in RSpec?
    primarykey
    data
    text
    <p>I would like to test multiple aspects of a controller or page's behavior as separate tests, but speed up my tests but only running a controller or capybara page load once for multiple checks. As an example, with a controller test:</p> <pre><code> it "should include all videos in the list of all videos" do get :show, id: event.id response.should be_somehow end it "should set the main video to be the paid video" do get :show, id: event.id response.should be_somehow_else end </code></pre> <p>I'd like this to become:</p> <pre><code> before :all do get :show, id: event.id end it "should include all videos in the list of all videos" do response.should be_somehow end it "should set the main video to be the paid video" do response.should be_somehow_else end </code></pre> <p>The problem is that RSpec cleans out the response object (or, for capybara, the page object) after every test. So whether I'm checking <code>assigns</code> in controller tests, <code>response</code> objects, or <code>page</code> results in Capybara, nothing like this works:</p> <pre><code>before :all do get :show, id: event.id @response = response end example "it should do something" do @response.should be_somehow # test works end example "it should do something else" do @response.should be_somehow_else # test fails; @response has been flushed by Rails testing facilities end </code></pre> <p>So the solution for test speedup is to have multiple checks in a single test:</p> <pre><code>example "it should be totally correct in every way" do get :show, id: event.id response.should be_somehow # test works response.should be_somehow_else # test works end </code></pre> <p>But this grates my sensibilities on test naming.</p> <p>This is by far the most aggravating in Capybara, in which I might have a multi-step setup (login, permissioning) process, and have 15 things to check on a single page load: did all the correct things show? Did other, uncorrect things not show? Did javascript actions get bound to the right things? Did the right backbone template get rendered? These tests quickly become 20 continuous lines of <code>should</code> statements with Ruby comments inline so I can remember what I'm testing, and it's just a mess.</p> <p>Before everyone tells me not to maintain test state from test to test, that's not what I'm doing: I want to check independent variables associated with a single state.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload