O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Stubject (Stubbing the Subject)

You may occasionally see a test case that uses allow or expect on the same object it’s testing. Sam Phippen refers to this antipattern as the stubject code smell, since you’re stubbing methods on the test subject.[102]

For example, consider the following code for a discussion forum that sends users a summary of what’s happened over the past day:

 class​ DailySummary
 def​ send_daily_summary(user_email, todays_messages)
  message_count = todays_messages.count
  thread_count = todays_messages.map { |m| m[​:thread_id​] }.uniq.count
  subject = ​'Your daily message summary'
  body = ​"You missed ​​#{​message_count​}​​ messages "​ \

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required