Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Capybara get, show, post, put in controller tests?

I'm just not sure what the exact way to word it is..

This tells me 'No response yet. Request a page first.'

it "should list searches" do
  get 'index'
  page.should have_selector('tr#search-1')
end

Is it meant to be like this instead?

it "should list searches" do
  get 'index' do
    page.should have_selector('tr#search-1')
  end
end

That way doesn't seem to actually test anything though.

What's the correct way?

like image 281
David Tuite Avatar asked Dec 21 '22 14:12

David Tuite


1 Answers

According to this, Capybara doesn't support PUT and DELETE requests with the default driver. PUT and DELETE are usually faked with javascript to accomodate REST based architecture.

I haven't checked, but I believe that you can use PUT and DELETE with Capybara if you make it use one of it's JS compatible drivers such as Selenium.

like image 54
David Tuite Avatar answered Jan 02 '23 08:01

David Tuite