【问题标题】:RSpec - how to test module in the moduleRSpec - 如何在模块中测试模块
【发布时间】:2012-04-13 09:30:29
【问题描述】:

我将模块嵌套在一个模块中

类似的东西:

module Utilities
  extend ActiveSupport::Concern

  module InstanceMethods
    def fix_text(str, params = {})
      str = Iconv.conv('UTF8', 'LATIN1', str)
      str.gsub!(/\\u([0-9a-z]{4})/) { |s| [$1.to_i(16)].pack("U") }
      str.force_encoding("UTF-8")
      str = strip_html(str) unless params[:no_strip_html]
      MojiBake::Mapper.new.recover str
    end

    def strip_html(str)
      Hpricot(str, :xhtml => true).to_plain_text
    end
  end
end

我没有在互联网上找到如何在模块中测试模块的信息。

请为此规范编写一些伪代码(描述和模块块的顺序,如何测试模块是否扩展了其他模块等)。

【问题讨论】:

  • 测试模块时没有额外的约束。规范/存根使通常的规则变得愚蠢。我无法理解您期望的答案
  • 其实我是 RSpec 的新手。你能写一些伪代码来测试那个模块吗?

标签: ruby-on-rails ruby-on-rails-3 module rspec rspec2


【解决方案1】:

例子:

require 'spec_helper'

class Foo
  include Utilities
end

describe Utilities do
  it 'should pass' do
    foo = Foo.new
    foo.strip_text(arg).should == expected
  end
end

您需要更改arg 和expected 变量

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-05
    • 1970-01-01
    • 2012-06-13
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多