unit testing - RSpec it block with variable name -
i have function get_type returns string given int:
def get_type(integer) types = [...] return types[integer] end when testing rspec, tried doing following:
describe 'function' context 'on valid input' let(:input){ 2 } let(:type){ 'large' } let(:result){ get_type input } it{ expect(result).to eq(type) } end end however, gives message:
function on valid input should eq "large" without mention input, sounding function should return "large".
how should message changed like:
function on valid input should eq type or meaningful message? name it block:
it 'should have correct type' expect(result).to eq(type) end but there nicer way without typing out test twice?
i think unhelpful message should considered smell - you're headed down road every test expect(result).to eq(expected) wall of let. mind overuse of let - don't think gain over
describe 'function' context 'on valid input' it{ expect(get_type(2)).to eq('large') } end end which produce more helpful failure message. keep let when expressions more complex or when can give them better name (eg hash of attributes called valid_attributes)
Comments
Post a Comment