Guest User

Untitled

a guest
Dec 14th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. it('case describing conditionalParamter=NOT NULL'):
  2. expect(conditionalParamter, 'to be a', 'string') // Guard assertion which can FAIL test. Is it OK? Can I simply **SKIP** assertion WITHOUT test failing
  3. expect(myStub.args, 'to satisfy', [[ nonConditionalParamter, ExpressionWhichUsesNonNullConditionalParamterValue ]])
  4.  
  5. it('case describing conditionalParamter= NULL')
  6. expect(conditionalParamter, 'to be falsy') // Guard assertion. The same issue
  7. expect(myStub.args, 'to satisfy', [[ nonConditionalParamter, ExpressionForNullConditionalParamterValue ]])
  8.  
  9. class Foo
  10. def bar(required_param, conditional_param = nil)
  11. return 'abc' if conditional_param.nil?
  12. '123'
  13. end
  14. end
  15.  
  16. describe Foo do
  17. subject(:foo) { described_class.new }
  18.  
  19. describe '#bar' do
  20. subject(:bar) { foo.bar(required_param, conditional_param) }
  21.  
  22. let(:required_param) { 'required_param' }
  23.  
  24. context 'when conditional_param is nil (not present)' do
  25. let(:conditional_param) { nil }
  26.  
  27. it 'returns abc' do
  28. expect(bar).to eq('abc')
  29. end
  30. end
  31.  
  32. context 'when conditional_param is not nil' do
  33. let(:conditional_param) { true }
  34.  
  35. it 'returns 123' do
  36. expect(bar).to eq('123')
  37. end
  38. end
  39. end
  40. end
Add Comment
Please, Sign In to add comment