I'm using Rails 3.2, Rspec 2 and capybara 2.
I am truncating a string of body text in my webpage and would like to test this in my feature spec.
Can someone advise how to do this because I can't seem to call truncate in my test because it keeps saying it's an undefined method and I don't really want to have a long string of truncated text in my test suite; just applying the truncate function is good enough.
I've tried using helper.truncate()
, view.truncate()
but to no avail.
I've used the Faker gem in other parts of my tests if there's a way to generate a lorem ipsum string and truncate it to compare against somehow.
View code:
<dd><%= truncate(project.details, :length => 100) %></dd>`
Test code
it { should have_selector('dd', @project.details) }
This test test worked fine when I was showing the full details text but because I've decided to only show the first 100 characters in this view I'm not sure how to test for this without having to set the details as a fixed string and then check for a truncated version of it somehow.
Thanks
Col