Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you actually see the html output during a functional test in rails

Tags:

One of my assert_selects is driving me up the wall. Its failing and of course its telling me what it expected but Id like to see what was actually there on that page when it rendered to track down this bug.

Ive already tried using my browser and the app is behaving as it should but thats using development data.

Is there a command i can use to print the html to console or my test log?

like image 584
robodisco Avatar asked Dec 05 '09 06:12

robodisco


People also ask

How do you run a Minitest in rails?

To run a Minitest test, the only setup you really need is to require the autorun file at the beginning of a test file: require 'minitest/autorun' . This is good if you'd like to keep the code small. A better way to get started with Minitest is to have Bundler create a template project for you.

What are the instance variables available in functional testing?

You also have access to three instance variables in your functional tests: @controller – The controller processing the request. @request – The request. @response – The response.

How do I run a test case in rails?

Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.

What type of test is not typical in a rails application?

Integration. Don't try to test all the combinations in integration tests. That's what unit tests are for. Just test happy-paths or most common cases.


2 Answers

Just do

puts @response.body 

right before the problematic assertion and you should see the thing.

like image 177
Milan Novota Avatar answered Oct 12 '22 23:10

Milan Novota


Webrat does this very thing with the command save_and_open_page.

like image 33
zetetic Avatar answered Oct 13 '22 00:10

zetetic