ruby - How to merge matchers in rspec? -
this specs:
"should convert doc successfully" @response = sharpoffice::office.process(file.expand_path("spec/fixture/test.doc")) @response[:status].should == 'ok' file.exist?(@response[:pdf_path]).should be_true file.exist?(@response[:swf_path]).should be_true file.exist?(@response[:cover_path]).should be_true end "should convert ppt successfully" @response = sharpoffice::office.process(file.expand_path("spec/fixture/test.ppt")) @response[:status].should == 'ok' file.exist?(@response[:pdf_path]).should be_true file.exist?(@response[:swf_path]).should be_true file.exist?(@response[:cover_path]).should be_true end "should convert xls successfully" @response = sharpoffice::office.process(file.expand_path("spec/fixture/test.xls")) @response[:status].should == 'ok' file.exist?(@response[:pdf_path]).should be_true file.exist?(@response[:swf_path]).should be_true file.exist?(@response[:cover_path]).should be_true end
how merge repetition ? thanks
you declare custom matcher in new conversion_helpers.rb
file:
rspec::matchers.define :be_converted_successfully match |conversion_response| conversion_response[:status] == 'ok' && file.exist?(conversion_response[:pdf_path]) && file.exist?(conversion_response[:swf_path]) && file.exist?(conversion_response[:cover_path]) end end
then in spec, require 'conversion_helpers'
, can do:
it "should convert doc successfully" sharpoffice::office.process(file.expand_path("spec/fixture/test.doc")).should be_converted_successfully end "should convert ppt successfully" sharpoffice::office.process(file.expand_path("spec/fixture/test.ppt")).should be_converted_successfully end "should convert xls successfully" sharpoffice::office.process(file.expand_path("spec/fixture/test.xls")).should be_converted_successfully end
although, in actual testing quite annoying trying track down bug. that's different issue.
Comments
Post a Comment