Note that there are some explanatory texts on larger screens.

plurals
  1. PORspec/capybara requests failing to see page content
    primarykey
    data
    text
    <p><b>Final Edit:</b> Thanks to @PeterAlfvin's suggestion that I focus on the application layout and the header, I was able to fix it. I haven't been able to figure out exactly what the problem was, but something in the header was causing capybara to not 'see' the rest of the page. I removed <code>&lt;%= render 'layouts/header' %&gt;</code>, re-built the header inside <code>application.html.erb</code>, and once it was working, pulled it out into a partial and replaced the render statement. I fiddled with both the old and new header files to try to figure out the problem, but no success with that yet. That makes my tests seem a bit brittle, but if the problem arises again, at least I'll know where to look. </p> <p><b>Edit: If you feel inclined to downvote, please go ahead, but let me know what I have overlooked or failed to research, because your comment might help me figure this out.</b></p> <p>I've searched for HOURS trying to fix this, but I can't figure out what's going on. I'm sure I'm missing something simple that will be obvious to anyone who hasn't been staring at it for the last day. That's my hope, anyway. </p> <p>All of my Rspec/capybara request specs are failing, but when I view the pages in my browser, all the elements that the specs fail to find are plainly there. As far as I can tell, Capybara isn't seeing the entire page- save_and_open_page returns a nearly-blank page. The failure I see with the spec below is universal- the specs can see the page title, but not anything in the page body. I'm fairly confident that all my routes are good, because all the title tests pass when they should. </p> <p><b>spec/requests/static_pages_spec.rb</b></p> <pre><code>require 'spec_helper' describe "StaticPages" do subject { page } describe "About page" do before { visit about_path } it { save_and_open_page; should have_selector('title', text: 'Company Name | About') } it { should have_selector('h1', text: 'About stuff') } it { should have_content('About paragraph') } end #more specs... end </code></pre> <p><b>results:</b></p> <pre><code>5) StaticPages About page Failure/Error: it { should have_selector('h1', text: 'About stuff') } expected css "h1" with text "About stuff" to return something # ./spec/requests/static_pages_spec.rb:28:in `block (3 levels) in &lt;top (required)&gt;' 6) StaticPages About page Failure/Error: it { should have_content('About paragraph') } expected there to be content "About paragraph" in "Company Name | About\n\t\n\t\t" # ./spec/requests/static_pages_spec.rb:29:in `block (3 levels) in &lt;top (required)&gt;' </code></pre> <p><b>Here's the "view source" output of the page opened in my browser by save_and_open_page:</b></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;Company Name | About&lt;/title&gt; &lt;link href="/assets/application.css" media="all" rel="stylesheet" type="text/css"&gt; &lt;script src="/assets/application.js" type="text/javascript"&gt;&lt;/script&gt;&lt;!--[if lt IE 9]&gt; &lt;script src="http://html5shim.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt; &lt;![endif]--&gt; &lt;/head&gt; &lt;body&gt; &lt;header class="navbar navbar-fixed-top navbar-inverse"&gt;&lt;div class="navbar-inner"&gt; &lt;/div&gt;&lt;/header&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>So, based on the source, and the response message for spec #6, it looks like it isn't searching any content besides the page title, which would be supported by the fact that my title tests always pass, but nothing else does. I have tests that look for form elements, buttons, etc, and I've tried identifying them different ways (label, id, name), but capybara can't find any of them. Again, when I view these pages in my browser, everything is plainly visible, and labelled correctly. </p> <p><b>When I visit the About page in my browser, this is the page source for the body, in contrast to the body content shown above:</b></p> <pre><code>&lt;body&gt; &lt;header class="navbar navbar-fixed-top navbar-inverse"&gt; &lt;div class="navbar-inner"&gt; &lt;a class="brand" href='/'&gt;Company Name&lt;/a&gt; &lt;ul class="nav pull-left"&gt; &lt;li&gt;&lt;a href="/products"&gt;Products&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/about"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/contact"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul class="nav pull-right"&gt; &lt;li&gt;&lt;a href="/users/sign_in"&gt;Sign in&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/header&gt; &lt;div class="container-fluid"&gt; &lt;div class="row-fluid"&gt; &lt;div class="span10 offset2"&gt;&lt;/div&gt; &lt;h1&gt;About stuff&lt;/h1&gt; &lt;p&gt;About paragraph&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p><b>Gemfile:</b></p> <pre><code>source 'https://rubygems.org' gem 'rails', '3.2.13' gem 'bootstrap-sass', '2.1' gem 'faker', '1.1.2' gem 'will_paginate', '3.0.4' gem 'bootstrap-will_paginate', '0.0.9' gem 'jquery-rails' gem 'devise' gem 'foreigner' gem 'paper_trail' group :development, :test do gem 'sqlite3', '1.3.7' gem 'rspec-rails', '2.11.0' gem 'letter_opener' gem 'factory_girl_rails', '4.1.0' end # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '3.2.5' gem 'coffee-rails', '3.2.2' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms =&gt; :ruby gem 'uglifier', '1.2.3' end group :test do gem 'capybara', '1.1.2' # gem 'rb-inotify', '0.8.8' # gem 'libnotify, '0.5.9' gem 'shoulda-matchers' gem 'accept_values_for' end group :production do gem 'pg', '0.12.2' end </code></pre> <p>Any help towards sorting this out will be greatly appreciated. Please let me know if I should include any additional info. </p> <p><b>Edit to add erb files</b></p> <p><b>app/views/layouts/application.html.erb</b></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;%= full_title(yield(:title)) %&gt;&lt;/title&gt; &lt;%= stylesheet_link_tag "application", :media =&gt; "all" %&gt; &lt;%= javascript_include_tag "application" %&gt; &lt;%= csrf_meta_tags %&gt; &lt;!--[if lt IE 9]&gt; &lt;script src="http://html5shim.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt; &lt;![endif]--&gt; &lt;/head&gt; &lt;body&gt; &lt;%= render 'layouts/header' %&gt; &lt;div class="container-fluid"&gt; &lt;div class="row-fluid"&gt; &lt;div class="span10 offset2"&gt; &lt;% flash.each do |key, value| %&gt; &lt;div class="alert alert-&lt;%= key %&gt;"&gt;&lt;%= value%&gt;&lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; &lt;%= yield %&gt; &lt;%= render 'layouts/footer' %&gt; &lt;%= debug(params) if Rails.env.development? %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><b>app/views/layouts/_header.html.erb</b></p> <pre><code>&lt;header class="navbar navbar-fixed-top navbar-inverse"&gt; &lt;div class="navbar-inner"&gt; &lt;a class="brand" href='/'&gt;Company Name&lt;/a&gt; &lt;ul class="nav pull-left"&gt; &lt;li&gt;&lt;%= link_to "Products", products_path %&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to "About", about_path %&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to "Contact", contact_path %&gt;&lt;/li&gt; &lt;/ul&gt; &lt;% if user_signed_in? %&gt; &lt;ul class="nav pull-right"&gt; &lt;li&gt;&lt;strong&gt;&lt;%= current_user.email %&gt;&lt;/strong&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to 'Account', account_path %&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to "Sign out", destroy_user_session_path, method: :delete %&gt;&lt;/li&gt; &lt;/ul&gt; &lt;% else %&gt; &lt;ul class="nav pull-right"&gt; &lt;li&gt;&lt;%= link_to "Sign in", new_user_session_path %&gt;&lt;/li&gt; &lt;/ul&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/header&gt; </code></pre> <p><b>app/views/layouts/_footer.html.erb</b></p> <pre><code>&lt;footer class="footer"&gt; &lt;small&gt;Company Name Price Management&lt;/small&gt; &lt;/footer&gt; </code></pre> <p><b>app/views/static_pages/about.html.erb</b></p> <pre><code>&lt;% provide(:title, 'About') %&gt; &lt;h1&gt;About stuff&lt;/h1&gt; &lt;p&gt;About paragraph&lt;/p&gt; </code></pre>
    singulars
    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.
 

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