RSpec - 如何在模块中测试模块

时间:2012-04-13 09:30:29

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

我将模块嵌套在模块中

类似的东西:

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

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

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

1 个答案:

答案 0 :(得分:4)

示例:

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

您需要更改argexpected变量

相关问题