我是Ruby/Rails/RSpec的新手,希望这是一个愚蠢/简单的问题.我正在为我们当前的项目编写RSpec测试.我目前正在做的是编写一个测试,用于在页面上显示上次登录时间/日期.
我想做的只是测试日期/时间是否以我们想要的格式出现.我正在使用正则表达式来检查格式.我正在创建正则表达式,然后尝试使用should have_selector这样的行(请原谅丑陋的正则表达式) -
it "should display last login date and time" do
date_time_regex = /Last Login: [0-9][0-9]-[0-9][0-9]-[0-9][0-9], [0-9][0-9]:[0-9[0-9]]/
visit root_path
response.should have_selector("date_time", :content => date_time_regex)
end
Run Code Online (Sandbox Code Playgroud)
当我尝试运行测试时,我得到以下错误 -
1) LayoutLinks when signed in should display last login date and time
Failure/Error: response.should have_selector("date_time", :content => date_time_regex)
NoMethodError:
undefined method `include?' for #<Regexp:0xef2a40>
# ./layout_links_spec.rb:60:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
所以看起来我无法传递正则表达式,但我不确定下一步该做什么?在此先感谢您的帮助!
有没有人有使用Cucumber和代码覆盖率工具SimpleCov的经验?我添加了以下行env.rb文件,因此Cucumber将触发SimpleCov-
require 'simplecov'
SimpleCov.start 'rails'
SimpleCov.coverage_dir 'coverage/cucumber'
Run Code Online (Sandbox Code Playgroud)
它做了它应该做的事情除了输出文件列出0文件测试,0相关行,0行覆盖等等.任何想法我怎么能使代码覆盖出来正确?