`

Rspec 和 flexmock

阅读更多
http://wiki.github.com/dchelimsky/rspec/configgem-for-rails
http://swachian.iteye.com/blog/163202
http://rspec.info/documentation/
http://hideto.iteye.com/blog/126583
http://github.com/jimweirich/flexmock/tree/master
http://flexmock.rubyforge.org/
  require 'flexmock/test_unit'
  require 'spec'

Spec::Runner.configure do |config|
    config.mock_with :flexmock
  end

  describe "Using FlexMock with RSpec" do
    it "should be able to create a mock" do
      m = flexmock(:foo => :bar)
      m.foo.should === :bar
    end
  end


require 'machine'

describe Machine do
  before :each do
    @machine = Machine.new
  end
  
  it "should initially have a state of :initial" do
    @machine.state.should == :initial
  end
  
end


describe Account do
  context "transfering money" do
    it "deposits transfer amount to the other account" do
      source = Account.new(50, :USD)
      target = mock('target account')
      target.should_receive(:deposit).with(Money.new(5, :USD))
      source.transfer(5, :USD).to(target)
    end

    it "reduces its balance by the transfer amount" do
      source = Account.new(50, :USD)
      target = stub('target account')
      source.transfer(5, :USD).to(target)
      source.balance.should == Money.new(45, :USD)
    end
  end
end

$ spec spec/account_spec.rb --format nested
Account
  transfering money
    deposits transfer amount to the other account
    reduces its balance by the transfer amount


Scenario: stub in before
  Given the following spec:
    """
    describe "a stub in before" do
      before(:each) do
        @messenger = mock('messenger').as_null_object
      end

      it "a" do
        @messenger.should_receive(:foo).with('first')
        @messenger.foo('second')
        @messenger.foo('third')
      end
    end
    """
  When I run it with the spec command --format nested
  Then the stdout should match "expected :foo with (\"first\") but received it with ([\"second\"], [\"third\"])"


分享到:
评论

相关推荐

    BDD开发之rspec和cucumber

    ### BDD开发之rspec和cucumber #### 行为驱动开发(BDD)概览 行为驱动开发(Behavior-Driven Development, BDD)是一种软件开发方法论,它结合了敏捷开发的思想和技术,如测试驱动开发(TDD)和领域驱动设计(DDD)...

    the rspec book.pdf

    这本书不仅涵盖了Rspec的基本用法,还深入探讨了高级特性和最佳实践,旨在帮助开发者实现更高效、更有信心的软件开发。 Rspec的核心理念是通过描述代码应有的行为来驱动其设计,而不是单纯地验证其功能。这种方式...

    rspec 入门者学习

    RSpec 的设计目的是让测试更加自然和易读,使得开发人员能够更好地理解和编写测试用例。 #### 二、RSpec 与 BDD **行为驱动开发 (BDD)** 是一种软件开发方法论,它鼓励团队成员(包括开发者、QA 和非技术人员)...

    Ruby-RSpec和Minitest匹配器来预防N1查询问题

    Ruby提供了两种强大的测试工具,RSpec和Minitest,它们通过匹配器功能可以帮助我们预防这种问题的发生。 RSpec是Ruby中广泛使用的BDD(行为驱动开发)框架,它允许开发者以自然语言的方式编写测试。匹配器是RSpec的...

    rspec测试.pdf

    RSpec作为Ruby社区中最流行的测试框架之一,不仅因其强大的功能和灵活性而受到欢迎,更重要的是,它推动了一种更为健康和有效的软件开发文化——通过清晰的行为描述来驱动开发,确保软件的质量和可维护性。...

    RSpec 3.1中文版

    RSpec 3.1版本是RSpec框架的更新版,提供了更多的功能和更好的用户体验。Rails是一个用Ruby语言编写的开源web应用框架,它采用MVC(模型-视图-控制器)架构模式,使得开发人员能够更容易地构建和维护web应用。使用...

    RSpec.Essentials

    ### RSpec Essentials: Key Insights and Learning Points **RSpec Essentials** is an essential guide for developers looking to enhance their skills in testing Ruby applications using the RSpec framework...

    Pragmatic.The RSpec Book.2010.pdf

    4. **强大的社区支持**:RSpec 拥有活跃的社区和丰富的文档资源,这为开发者提供了极大的帮助和支持。 #### 二、RSpec的安装与基本使用 **安装:** 1. **Gem 安装**:通过 Ruby 的包管理工具 Gem 来安装 RSpec,...

    rspec測試工具書

    最后,RSpec的使用通常与持续集成(Continuous Integration)和敏捷开发实践相结合,这可以提升软件开发的效率和软件质量的可靠性。通过RSpec,团队可以更快地获得反馈,及时发现和修复问题,从而在项目中实现更快的...

    使用RSpec 测试Rails 程序.pdf

    3. **RSpec配置**:编辑`spec_helper.rb`来配置RSpec的行为和偏好,例如指定默认的测试环境、启用或禁用特定特性等。 4. **生成器**:使用`rails generate rspec:install`命令来初始化RSpec,并创建必要的目录结构和...

    jruby-1.5.5+OperaWatir+RSpec

    标题 "jruby-1.5.5+OperaWatir+RSpec" 暗示了这是一个关于使用 JRuby 1.5.5 版本、OperaWatir 和 RSpec 进行自动化测试的项目或者资源集合。现在,我们将深入探讨这三个关键组件以及它们在 IT 领域中的应用。 JRuby...

    rspec_api_documentation, 从RSpec自动生成API文档.zip

    rspec_api_documentation, 从RSpec自动生成API文档 RSpec Doc为你的Rails API生成漂亮的。查看一个示例文件。更改请查看维基以了解最新的更改。安装将rspec_api_documentation添加到你的文件gem 'rspec_a

    The.RSpec.Book

    - **社区资源**:RSpec 拥有一个活跃的社区,提供了大量的文档、教程和示例代码,可以帮助开发者更快地掌握RSpec的使用方法。 - **官方文档**:RSpec 官方文档是学习RSpec的最佳起点,其中包含了详细的安装指南、...

    rspec-api-blueprint-formatter, 从RSpec测试自动生成API文档 !.zip

    rspec-api-blueprint-formatter, 从RSpec测试自动生成API文档 ! RSpec APIBlueprint格式化程序从RSpec测试自动生成API文档 !像这样it 'retrievs the patients medications' do retrieve_medications

    rspec-collection_matchers, 集合基数匹配器,从rspec期望中提取.zip

    rspec-collection_matchers, 集合基数匹配器,从rspec期望中提取 RSpec::CollectionMatchers RSpec::CollectionMatchers 让你在一个例子中表达一个对象集合的预期结果。expect(account.shopping_cart).to have_

    RSpec运行和格式化工具rspec-core.zip

    rspec-core 是 RSpec 运行和格式化工具。rspec-core 提供一个框架,用来书写你的代码应该怎样表现的可执行案例;以及一个 rspec 命令工具来限制哪些案例可以运行,调整输出格式。 标签:rspec

    The Rspec Book -- BDD methodology

    RSpec和Cucumber可以很好地协同工作,RSpec负责单元测试和集成测试,而Cucumber则处理验收测试。 2. **RSpec**与**Cucumber**的结合使用可以覆盖从底层代码到用户界面的完整测试范围,确保了软件质量的同时也促进...

    rspec_junit_formatter, RSpec结果格式化为你的CI可以读取的JUnit.zip

    rspec_junit_formatter, RSpec结果格式化为你的CI可以读取的JUnit RSpec JUnit格式化程序 RSpec 2 & 3结果, Jenkins可以读取。 可能还有其他的CI服务。灵感来自于的工作,在的RSpec格式化程序在对 Reporter的失望...

Global site tag (gtag.js) - Google Analytics