title: Why does my RSpec assertion work on one view spec and not another?
body: <p>I have a Rails app with an "Events" model, and in the 'spec/features' directory I have a 'list_events_spec.rb' file and a 'show_event_spec.rb' file.  The following 3 assertions crashed my RSpec tests when placed in the 'list_events' spec, but the tests passed when I placed the assertions in the 'show_event' spec.  The header, footer and aside are all partials which are rendered in the application.html.erb file.  </p>
  
  <p>The only thing I can figure is that Rails treats these 2 files differently based on their filenames, but I would expect the assertions to work regardless of the spec_file they're placed in, since they're rendered in the application.html.erb file.</p>
  
  <p>Here are the assertions (filenames are "_header.html.erb", "_footer.html.erb", and "_sidebar.html.erb"):</p>
  
  <pre><code>it "has a header" do
    expect(page).to have_selector("header")
  end
  
  it "has a footer" do
    expect(page).to have_selector("footer")
  end
  
  it "has a sidebar" do
    expect(page).to have_selector("aside")
  end
  </code></pre>
  
  <p>And here is the application.html.erb file:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;EventsTdd&lt;/title&gt;
      &lt;%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" =&gt; true %&gt;
      &lt;%= javascript_include_tag "application", "data-turbolinks-track" =&gt; true %&gt;
      &lt;%= csrf_meta_tags %&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;%= render 'header' %&gt;
      &lt;%= render 'sidebar' %&gt;
      &lt;%= yield %&gt;
  
    &lt;/body&gt;
    &lt;%= render 'footer' %&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is the RSpec error message:</p>
  
  <pre><code>Failures:
  
    1) viewing the list of events has a sidebar
       Failure/Error: expect(page).to have_selector("aside")
       Capybara::ExpectationNotMet:
         expected to find css "aside" but there were no matches
       # ./spec/features/list_events_spec.rb:53:in `block (2 levels) in &lt;top (required)&gt;'
  
    2) viewing the list of events has a footer
       Failure/Error: expect(page).to have_selector("footer")
       Capybara::ExpectationNotMet:
         expected to find css "footer" but there were no matches
       # ./spec/features/list_events_spec.rb:49:in `block (2 levels) in &lt;top (required)&gt;'
  
    3) viewing the list of events has a header
       Failure/Error: expect(page).to have_selector("header")
       Capybara::ExpectationNotMet:
         expected to find css "header" but there were no matches
       # ./spec/features/list_events_spec.rb:45:in `block (2 levels) in &lt;top (required)&gt;'
  
  Finished in 0.8435 seconds
  33 examples, 3 failures
  
  Failed examples:
  
  rspec ./spec/features/list_events_spec.rb:52 # viewing the list of events has a sidebar
  rspec ./spec/features/list_events_spec.rb:48 # viewing the list of events has a footer
  rspec ./spec/features/list_events_spec.rb:44 # viewing the list of events has a header
  
  Randomized with seed 16198
  </code></pre>