Testing the flash is brittle?

Hello all,

I seem to have an annoying habit of realizing that I’ve asked a
question with a blindingly obvious answer just after I’ve asked it
but here goes.

I’ve noticed that in my functional tests there’s the occasional
reliance on the contents of the flash. For example, I have an action
that confirms a users identity and may reject them because

A) The credentials were bad - flash contains “Sorry, I have no record
of you”
B) For the sake of argument, the controller deliberately stops 20% of
users logging in - flash contains “You’re not getting in because I
say so”

In both these cases the only thing that varies from the user side
(and therefore the functional test) is the flash. However, this
seems to be extremely brittle to me: if I were to change the message
then the tests fail. Is there a preferred way to cope with this
other than refactoring my tests not to use the flash?

The best solution I can come up with is to keep all interface text in
a external gettext file and compare the flash and the expected value
by keys.

I now fully expect to find an answer as soon as I press ‘send’.

Thanks,
Gavin

Hello Gavin,

2006/7/19, Gavin M. [email protected]:

A) The credentials were bad - flash contains “Sorry, I have no record
of you”
B) For the sake of argument, the controller deliberately stops 20% of
users logging in - flash contains “You’re not getting in because I
say so”

Use regular expressions, and search for the key words:

assert_match /no record.*of.*you/i, flash[:warning]
assert_match /because say so/i, flash[:warning]

That helps in the majority of cases.

Hope that helps !

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs