6

My code in view is

<h3 id="account_owner">This is Jhon's account</h3>

The line to test this code is

assert_select "h3#account_owner", "This is Jhon's account"

Test fails and says

"This is Jhon's account" was expected but was This is Jhon&# x27;s account'

I put a space between "&# x27;" because it also converts into ' on output of this question. Any guess? Or how should I test this line?

Malik Shahzad
  • 6,703
  • 3
  • 37
  • 49

2 Answers2

3

I didn't found a valid answer, but to test that line i do something like assert_select "h3#account_owner", "This is Jhon's account".gsub("\'", '&# x27;')

Again, I put a space between "&# x27;" because it also converts into ' on output of this answer. I am still looking for better way to test this.

Malik Shahzad
  • 6,703
  • 3
  • 37
  • 49
0
  expect(rendered).to have_css(".columns", :text=>"This is John's account")

Use have_css instead of assert_select.

vanboom
  • 1,274
  • 12
  • 20
  • 2
    Please, avoid code only answers and explain your solution. – Micho Dec 14 '16 at 09:47
  • 1
    While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – kayess Dec 14 '16 at 11:15