I have the following view which I can't spec out properly in a view spec:
file: "products/index.html.haml"
#products
= render @products
And this is my view spec:
require 'spec_helper'
describe "products/index.html.haml" do
let(:products) {[mock_model(Product)]}
before do
stub_template "products/product.html.haml" => ""
render
end
it "should render the products" do
rendered.should have_selector(#products) do
rendered.should render_template products
end
end
The problem here is that have_selector does not accept a block so there is no way to assert that the partial is rendered inside the #products div. Since Capybara matchers don't work within View specs you cannot use within either.
See also this issue: https://github.com/rspec/rspec-rails/issues/387