Mir*_*rko 44 rspec ruby-on-rails helper rspec2
在我的ApplicationController中,我有一个定义为辅助方法的方法:
helper_method :some_method_here
我正在使用Rails3和RSpec2
Kon*_*che 22
您可以在规范中subject或@controller在规范中调用辅助方法.
我一直在寻找这个问题的解决方案,匿名控制器不是我想要的.假设你有一个控制器生活在app/controllers/application_controller.rb一个简单的方法,它没有绑定到REST路径:
class ApplicationController < ActionController:Base
  def your_helper_method
    return 'a_helpful_string'
  end
end
然后你可以spec/controllers/application_controller_spec.rb按如下方式编写测试:
require 'spec_helper'
describe ApplicationController do
  describe "#your_helper_method" do
    it "returns a helpful string" do
      expect(subject.your_helper_method).to eq("a_helpful_string")
    end
  end
end
虽然@controller并且subject可以在这里互换使用,但我现在将subject其作为RSpec惯用的方式.
| 归档时间: | 
 | 
| 查看次数: | 28557 次 | 
| 最近记录: |