使用rspec-page-regression时expect方法出现参数数量错误(给定1,预期0)
解决rspec-page-regression中
match_expectation参数数量不符的问题 这个错误的根源是你对match_expectation的用法理解有误——它并不是一个RSpec匹配器,而是一个独立的断言方法,不需要包裹在expect(page).to语句里。
当你写expect(page).to match_expectation时,RSpec会自动把page作为参数传递给match_expectation方法,但这个方法本身设计为不需要参数(它默认会使用当前的page对象进行对比),所以就触发了wrong number of arguments的错误。
修复后的代码
只需要直接调用match_expectation即可,不需要expect包裹:
describe "my page", :type => :feature, :js => true do before(:each) do visit EnvConfig.get :app_url end it { match_expectation } end
如果想要让测试用例的描述更清晰,也可以写成带块的形式:
describe "my page", :type => :feature, :js => true do before(:each) do visit EnvConfig.get :app_url end it "matches the page regression baseline" do match_expectation end end
额外提示
如果需要区分不同场景的基准截图(比如同一页面的不同状态),你可以给match_expectation传递一个自定义名称参数:
match_expectation("my_page_logged_in_state")
这样gem会自动寻找对应名称的基准截图文件进行对比。
内容的提问来源于stack exchange,提问作者Dmytro Sotnikov
相关产品推荐
相关产品推荐

