- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对测试驱动开发有点陌生,我想学习如何覆盖尽可能多的代码,这样当我在 Rails 中制作更复杂的应用程序时,我将能够防止引入错误。
我在 application_helper.rb
中有一些代码,它们将 flash 消息设置为 Twitter Bootstrap 类,我想为我编写的代码编写一个测试,这样如果有任何变化,我会提前知道这变成了一个小问题。
#application_helper.rb
module ApplicationHelper
def flash_class(type)
case type
when :alert
"alert-error"
when :notice
"alert-info"
else
""
end
end
end
我的 application.html.erb
View 具有以下代码,使用上面的辅助方法显示 flash 消息。
#application.html.erb
<% flash.each do |type, message| %>
<div class="alert <%= flash_class type %>">
<button type="button" class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
我将编写什么类型的测试来测试 application_helper.rb
中的代码是否有效,我将如何编写该测试?我也在使用 shoulda-context gem 用于测试编写,但我不关心测试是否以标准 Rails test_with_lots_of_underscores
样式编写。
我正在使用 Cloud9使用 Ruby 1.9.3(补丁级别 327)和 Rails 3.2.13 编写应用程序。我正在开发的应用程序的代码是 in this Github repository
最佳答案
这样的事情怎么样:
class ApplicationHelperTest < Test::Unit::TestCase
context "flash_class" do
should "map :alert symbol to 'alert-error' string" do
assert_equal 'alert-error', flash_class(:alert)
end
should "map :notice symbol to 'alert-info' string" do
assert_equal 'alert-info', flash_class(:notice)
end
should "map anything else to empty string" do
assert_equal '', flash_class(:blah)
end
end
end
关于ruby-on-rails - 在 Rails 的 application_helper.rb 代码中测试 flash 消息方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16083317/
下面是activeresource.rb的全部内容: require 'active_resource' 谁能解释一下这其中的逻辑? 为什么不简单地让 activeresource.rb 包含 act
Neo4j.rb 中是否有针对 Rails 6 的开发?在一个新的 Rails 6(rc1) 项目中,如果我创建几个脚手架然后运行“rake neo4j:migrate:all”,我会收到一个错误,当
对此很陌生,所以我一直在尝试解决这个问题,但无法找到答案。 gem update --system 安装 rb-appscript 时出现以下错误。 gem install rb-appscript
我正在为涉及选中/取消选中框的场景编写步骤定义。在步骤定义中,我尝试使用 web_steps.rb 中的现有步骤。但是我收到错误:未定义的步骤:“我检查'评级'”。我必须做些什么才能让我的 myfea
为什么 Controller 命名为“users_controller.rb”而模型不命名为“user_model.rb”? 为什么有“application_controller.rb”但在view
我对 Ruby on Rails 完全陌生,正在运行以下命令$rails生成设备用户 我期望生成文件 _devise_create_users.rb 。但是它会生成文件 _add_devise_to_
我的 Rails 应用程序(在 Heroku 上运行)有一个暂存和生产环境。目前,我必须在每个文件中分别定义 staging.rb 和 production.rb 中的很多内容,例如: # Cod
我是 Rails 新手,并且对 ASP.net 有很好的了解。在 ASP.net Web 应用程序中,我有一个 web.config 来完成所有设置,但在 Rails 中,有几个配置文件,我现在想知道
预先感谢您的帮助。 我正在尝试在 env.rb 中创建变量 File_path =("#{File.dirname(__FILE__)}/../../features/TestData/Testdat
按照这里的例子: http://rspec.info 但是它失败了: kernel_require.rb:45:in `require': cannot load such file -- bowli
我在使用 Ruby 时遇到了一个我无法解释的奇怪问题。我有以下脚本,它抓取剪贴板中当前的任何代码,通过语法高亮器运行它,然后将新版本放回剪贴板: #!/usr/bin/ruby1.9.1 requir
假设我想通过表单将此代码嵌入到单独的 ruby.rb 文件中: print "Hello, Please enter a value:" var = gets.to_i if var == 1
我正在从“MongoDB in Action”一书中学习 Mongodb 和 ruby 我已经安装好 Mongodb 并设法在其上执行了许多命令。 我可能没有正确安装 ruby。 我正在使用 Ub
更多新手问题。 我知道,如果我在我的应用程序帮助程序中定义了一个方法,那么整个应用程序代码都可以使用它。 在我的应用程序助手中,我有: def primary_user_is_admin if c
尝试将此代码块授予 capistrano 的版本 3 但无济于事。一切都变了。任何人都可以帮助我在正确的轨道上进行转换吗? 旧版本 2 deploy.rb: #require 'new_relic/r
我正在第二次学习 Rails 教程。当我输入这个 rails generate integration_test static_pages 我得到 spec/rails_helper.rb 和 spe
请问这个env.rb错误是什么意思? root# rake db:migrate WARNING: Cucumber-rails required outside of env.rb. The re
我已经看到这个问题出现在许多不同的情况下,并希望获得在 StackOverflow 上修复/调试它的最佳实践。 今天早上我想到了一个现实世界的例子: expected announcement.rb
这是我在 StackOverflow 上的第一个问题,请耐心等待...... 当我在Listing 8.6中使用authentication_pages_spec.rb时我的测试通过了。然后我在'sp
有谁知道在 JRuby 中是如何处理 tempfile.rb 的。它在 Ruby 中,但不在 JRuby 中。 有人有任何想法吗? 干杯 埃夫 最佳答案 您仍然可以“要求'tempfile'”并且它会
我是一名优秀的程序员,十分优秀!