2012-04-13 93 views
0

在测试模块我模块嵌套在一个模块中RSpec的 - 如何在模块

类似的东西:

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 

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

请为这个规范写一些伪代码(describe和module blocks的顺序,如何测试module是否扩展其他模块等)。

+0

还有就是当你测试一个模块没有其它附加的约束。指示/残桩忽略了通常的规则。我无法理解你期待的答案 – apneadiving 2012-04-13 09:58:24

+0

其实我是RSpec的新手。你可以写一些伪代码如何测试该模块? – 2012-04-13 10:17:03

回答

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变量