Created
July 18, 2012 10:42
-
-
Save mkempe/3135487 to your computer and use it in GitHub Desktop.
Testing rspec views with capybara
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
module RSpec | |
module Support | |
module Views | |
module CapybaraExtensions | |
def rendered | |
Capybara.string(@rendered) | |
end | |
def within(selector) | |
yield rendered.find(selector) | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'spec_helper' | |
describe 'page/foo.html.haml' do | |
include RSpec::Support::Views::CapybaraExtensions | |
before do | |
render | |
end | |
it 'has a header' do | |
rendered.find('h1').should have_content('Foo') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.tamingthemindmonkey.com/2011/11/07/capybara-matchers-and-scoping-in-view-specs
http://rubyforge.org/pipermail/rspec-users/2011-October/020664.html