Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec view testing with capybara and rails3

I really like the way RSpec is able to separate controller and view tests but have some problems with getting capybara matchers to work in a view test. What i basically try to achieve is sth like this:

describe "some page" do
  it "should render with lots of stuff" do
    assign ..
    render
    rendered.should have_button ('Any button') #or any capybara matcher, really
  end
end

I've seen some posts on the net showing how to configure capybara and rails3 to work smoothly with cucumber or rspec controller tests, but this is not really what I want - that is, testing the views at the lowest level possible.

Also if there's another way to do this (not requiring lots of custom code, couse I know i could write some matchers that extract given selectors from rendered using nokogiri or whatever tool suitable) that'd be great too - using capybara is not a requirement.

like image 524
dahpgjgamgan Avatar asked Jan 16 '11 15:01

dahpgjgamgan


1 Answers

Capybara currently does not work with view specs (there are plans to make it work in the future). The simplest answer is to just add gem 'webrat' to the Gemfile and you're basically set. You might not have have_button but you'll have have_selector, have_tag and similar available.

Btw: as far as I know capybara and webrat can co-exist in one project.

like image 66
Paweł Gościcki Avatar answered Nov 15 '22 21:11

Paweł Gościcki