这个rspec助手测试我在做什么错? [英] What am I doing wrong with this rspec helper test?

查看:95
本文介绍了这个rspec助手测试我在做什么错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的只是说明视图的单行助手方法应如何表现,但是我不确定如果正在使用哪种模拟对象(如果有)应该创建滑轨.

All I'm trying to do is spec how a one line helper method for a view should behave, but I'm not sure what kind of mock object, (if any) I should be creating if I'm working in Rails.

这是events_helper.rb的代码:

Here's the code for events_helper.rb:

module EventsHelper

  def filter_check_button_path
    params[:filter].blank? ? '/images/buttons/bt_search_for_events.gif' : '/images/buttons/bt_refine_this_search.gif'
  end
end

这是我在specs_helper_spec.rb中的规范代码:

And here's my spec code, in events_helper_spec.rb:

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe EventsHelper do

  #Delete this example and add some real ones or delete this file
  it "should be included in the object returned by #helper" do
    included_modules = (class << helper; self; end).send :included_modules
    included_modules.should include(EventsHelper)
  end

  it "should return the 'refine image search' button if a search has been run" do

  # mock up params hash
    params = {}
    params[:filter] = true

   # create an instance of the class that should include EventsHelper by default, as the first test has verified (I think)
    @event = Event.new

  # call method to check output
    @event.filter_check_button_path.should be('/images/buttons/bt_search_for_events.gif')
  end

end

当我在这里浏览文档时- http://rspec.info/rails /writing/views.html ,我对模板"对象的来源感到迷惑.

When I've looked through the docs here - http://rspec.info/rails/writing/views.html, I'm mystified as to where the 'template' object comes from.

我也尝试过看这里,我认为这会指向正确的方向,但是可惜没有骰子. http://jakescruggs.blogspot.com/2007/03/模拟ingingstubbing-partials-and-helper.html

I've also tried looking here, which I thought would point me in the right direction, but alas, no dice. http://jakescruggs.blogspot.com/2007/03/mockingstubbing-partials-and-helper.html

我在做什么错了?

谢谢

克里斯

推荐答案

在该规范中,您没有做任何事情,只是设置了一个存根,以便它可以通过,但未进行任何测试.

You are not doing anything in that spec, just setting a stub, so it will pass, but hasn't tested anything.

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe EventsHelper do
 it "should return the 'refine image search' button if a search has been run" do
  # mock up params hash
  params = {:filter => true}

  helper.stub!(:params).and_return(params)
  helper.filter_check_button_path.should eql('/images/buttons/bt_search_for_events.gif')
 end
end

这篇关于这个rspec助手测试我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆