---
title: "ruby ,   rspec中测试 module "
author: "sg552"
date: "2012-07-30T10:29:32Z"
tags: []
categories: ["编程语言"]
slug: "ruby-rspec-module"
draft: false
lastmod: "2012-07-30T10:29:52Z"
id: 1611857
url: "https://sg552.iteye.com/blog/1611857"
---

见：  <http://stackoverflow.com/questions/1542945/testing-modules-in-rspec/1546493#1546493>

What mike said. Here's a trivial example:

module code...

```ruby

module Say
  def hello
    "hello"
  end
end
```


spec fragment...


```ruby
class DummyClass
end

before(:each) do
  @dummy_class = DummyClass.new
  @dummy_class.extend(Say)
end

it "get hello string" do
  @dummy_class.hello.should == "hello"
end


```