【问题标题】:Installing RSpec in Rubygem在 Rubygem 中安装 RSpec
【发布时间】:2014-01-18 04:37:39
【问题描述】:

我决定创建我的第一个 gem,现在我正在尝试安装 RSpec。

我已将spec.add_development_dependency "rspec", "~> 2.14" 添加到我的 .gemspec 文件中,并创建了如下所示的 spec/spec_helper.rb

require 'rubygems'
require 'bundler/setup'
Bundler.require(:default, :development)

require 'my_gem' 


RSpec.configure do |config|
  config.color_enabled = true
  config.formatter     = 'documentation'

  config.order = 'random'
end

捆绑后,我终于添加了spec/foobar_spec.rb,如下所示

require 'spec_helper'

describe 'foobar' do
  expect(1).to eq(2)
end

但是当我运行 rspec spec/foobar_spec.rb 我得到了

# (NoMethodError) 的未定义方法 `expect'

我错过了什么吗?

谢谢

【问题讨论】:

    标签: rubygems rspec2


    【解决方案1】:

    根据the Rspec docs,期望必须在it 块内定义:

    describe 'foobar' do
       it { expect(1).to eq(2) }
    end
    

    【讨论】:

    • 感谢您的回复。不知道为什么我忽略了它。
    • 如果这个答案解决了你的问题,你会考虑接受它是正确的吗?
    • 我还要再等 2 分钟 ;)
    猜你喜欢
    • 2014-04-12
    • 2015-02-24
    • 2018-04-20
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多