I know integration tests are preferred but I need this to be ran in a controller test, I'm testing a gem injecting html code in the view, especially with xhr so this can't be run in a feature spec (if it can, please explain me how :) )
So with rspec controller tests you can assert a selector is present (with capybara) :
response.body.should have_selector('#foobar')
has_selector?
will call the all
method from capybara to find the selector.
What I want to do is get the last child of body and then assert that its id is something in particular.
AFAIK it's not possible to do this with have_selector.
What I would do is :
all('body:first-child').first.id.should == '#foobar'
However, with Capybara DSL, all is defined like this (more or less):
def all(*args)
page.all(*args)
end
And the page will be empty unless I use visit
but it's for integrations specs.
How can I use capybara all
method inside an rspec controller test ?