I am new to Ruby / Rails / RSpec and hopefully this is a dumb / simple question. I am currently working on writing RSpec tests for our current project. I am currently writing a test to display the last time / date a page was entered.
What I want to do is just check if the date / time is present in the correct format. I use regular expression to check formatting. I create a regular expression and then try to use the string must be selector so (please excuse the ugly regular expression) -
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
When I try to run the test, I get the following error:
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)>'
So it looks like I can't pass in the regex, but I'm not sure what to do next? Thanks in advance for your help!
Will source share