Pages

Friday, October 14, 2011

I just read a bit more on RSpec's expectation matchers : should, should_not

should - It's being used like a connector. For example, if a GET request was made to the index of a resource's controller,

  fact: the resulting page would have the string, 'I love rails'
  spec:

  1. the spec would therefore expect to have the string, 'I love rails' in it
  2. we would write the spec as follows:
       request.should contain('I love rails')




should_not - it's the 'negative' version of should. This means we need not use 'not' :)


For example, if a GET request was made to the index of a resource's controller,

  fact: the resulting page will NOT have the string, 'I love rails'
  spec:

  1. the spec would therefore expect to have the string, 'I love rails' in it
  2. we would write the spec as follows to say, "we do not expect the resulting request object to have the string, 'I love rails' in its contents":
       request.should_not contain('I love rails')




Here's also another article which speaks of this well.

Gordon Yeong :)