RSpec controller testing - blank response.body

后端 未结 4 1423
长发绾君心
长发绾君心 2021-01-30 03:08

I am stuck with a problem when testing my controllers with RSpec - the response.body call always returns an empty string. In browser everything renders correctly, and cucumber f

4条回答
  •  面向向阳花
    2021-01-30 03:14

    As I worked with a similar problem (that led me to this question), it occurred to me that there are different ways to skin the same cat. In other words, rather than checking for the body text, you might be able to check the content of the flash.

    response.body.should =~ /Invalid email or password/
    

    might be an equivalent check to:

    flash[:alert].should == "Invalid email or password"
    

    To me the latter seems a bit more flexible as it will run either way, but it may not be appropriate in all cases.

    Cheers,

    John

提交回复
热议问题