ruby-on-rails - 如何测试使用捕获的辅助方法?

标签 ruby-on-rails testing rspec helper

我有一个助手可以执行以下操作:

def send_to_block(value, &block)
   capture(value, &block)
end

编写测试时:

value_received = nil
send_to_block('test') do |value|
   value_received = value
end
value_received.should == 'test'

我遇到以下异常:

NameError: uninitialized constant Kernel::DISABLED

有什么想法吗?

最佳答案

您需要使用辅助对象,如下所述:https://www.relishapp.com/rspec/rspec-rails/v/2-11/docs/helper-specs/helper-spec

沿着这些思路的东西应该是你所追求的:

require "spec_helper"

describe MyHelper do
  describe "#send_to_block" do
    it "should do something" do
      helper.send_to_block('test').should == 'I have no idea what this should be'
    end
  end
end

关于ruby-on-rails - 如何测试使用捕获的辅助方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11587229/

相关文章:

ruby-on-rails - 如何使用 postgres 和 ActiveRecord 检索所有重复的电子邮件

unit-testing - 将测试数据填充到 cassandra 单元的最快方法?

java - 如何测试Spring Boot优雅关闭?

php - 在 codeception 中设置用户代理

ruby-on-rails - 无法使用 redcarpet 换行

ruby-on-rails - 如何在 Rails 3.1 中使用 group() 将 COUNT 列添加到工作查询中

ruby-on-rails - 在 Rspec 中创建的记录在新线程中不可用?

ruby-on-rails - 为 ruby​​onrails 编写测试

ruby-on-rails - Michael Hartl 教程第 11 章中的 "undefined method ` find_by '"

ruby-on-rails - Rails JSON 到 Swift 2 JSON