Why am I seeing output during 'rake test' other than '.' 'F' or 'E' (ruby 1.9.2p290, Rails 3.0.9)?
When I used to run 'rake test' I would see either '.' or 'F' or 'E' for each test. When all was well, the output was a line of '.'
Now, even though all my test are passing, I am seeing program output in the midst of t开发者_StackOverflow社区he line of '.'
I am not sure the best way to post the output, but here is an initial offering:
perrys-MacBook-Pro:iway perry_mac$ rake test:functionals --trace
** Invoke test:functionals (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:prepare
** Execute test:functionals
Loaded suite /Users/perry_mac/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
.........................."Welcome joe : "
."Welcome joe : "
."Welcome joe : "
."Welcome joe : "
.................."Welcome bob : "
...........
Finished in 0.998462 seconds.
58 tests, 81 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 15796
The line of code generating the output is: app/views/layouts/application.html.erb
<div id="nav">
<% if current_user %>
<% str= "Welcome " + current_user.username + " : "%>
<%= p str %>
<%= link_to "Edit Profile : ", edit_user_path(current_user.id)%>
<%= link_to "Logout", :logout%>
<% else %>
<%= link_to "Register", new_user_path%> |
<%= link_to "Login", :login %>
<% end %>
</div>
The "Welcome joe : " and "Welcome bob : " msgs are expected program output seen after a user successfully logs in. bob and joe are usernames created in a fixtures file. I can't figure out why the msgs are now seen during 'rake test' I see the same behavior when --trace is not used as well. Please comment on A) why I see some program output and not the rest and B) Why am I seeing any at all?
Grep for "puts" or other code that writes to stdout in your app or test code. Something is leaking data to stdout.
It looks like your view template is sending the content to stdout as well as the view:
<%= p str %>
The p function sends the string to stdout and then returns the string. The <%= ERB directive injects the value into the page being rendered, so you were both printing it out to stdout/console and rendering it in the page. This caused it to appear on the console when you were running tests.
精彩评论