[英]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 '.' 当我以前运行'rake test'时,我会看到'''。 or 'F' or 'E' for each test. 或每次测试的'F'或'E'。 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 the 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 生成输出的代码行是: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. “Welcome joe:”和“Welcome bob:”msgs是用户成功登录后可以看到的程序输出.bob和joe是在fixture文件中创建的用户名。 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. 我无法弄清楚为什么现在可以在'rake test'中看到msgs。当我没有使用--trace时,我看到相同的行为。 Please comment on A) why I see some program output and not the rest and B) Why am I seeing any at all? 请评论A)为什么我看到一些节目输出而不是其余节目B)为什么我看到任何节目?
Grep for "puts" or other code that writes to stdout in your app or test code. grep用于“puts”或其他代码,用于在应用程序或测试代码中写入stdout 。 Something is leaking data to stdout. 有些东西正在向stdout泄露数据。
It looks like your view template is sending the content to stdout as well as the view: 看起来您的视图模板正在将内容发送到stdout以及视图:
<%= p str %>
The p function sends the string to stdout and then returns the string. p函数将字符串发送到stdout,然后返回字符串。 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. <%= ERB指令将值注入正在呈现的页面中,因此您将它打印到stdout / console并在页面中呈现它。 This caused it to appear on the console when you were running tests. 这导致它在运行测试时出现在控制台上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.