Advertisement
istrasci

RSpec test naming/output

Jul 20th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.98 KB | None | 0 0
  1. class StringTester
  2.   def self.is_hello?(s)
  3.     s == 'hello'
  4.   end
  5. end
  6.  
  7. RSpec.describe StringTester do
  8.   # Tests are fairly readable in English...
  9.   describe '::is_hello?' do
  10.     it { expect(StringTester.is_hello?('hello')).to be_truthy }
  11.     it { expect(StringTester.is_hello?('something else')).to be_falsey }
  12.   end
  13. end
  14.  
  15. # ...but the output is ambiguous without going back to look at the tests.
  16. # Output:
  17. # StringTester
  18. #   ::is_hello?
  19. #     should be truthy
  20. #     should be falsey
  21.  
  22.  
  23. RSpec.describe StringTester do
  24.   # Tests are redundant when read in English...
  25.   describe '::is_hello?' do
  26.     it 'is true for "hello"' do
  27.       expect(StringTester.is_hello?('hello')).to be_truthy
  28.     end
  29.     it 'is false for "something else"' do
  30.       expect(StringTester.is_hello?('something else')).to be_falsey
  31.     end
  32.   end
  33. end
  34.  
  35. # ...but the output is very straightfoward.
  36. # Output:
  37. # StringTester
  38. #   ::is_hello?
  39. #     is true for "hello"
  40. #     is false for "something else"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement