1

我正在尝试围绕我刚刚编写的 Ruby Rails 应用程序设置 RSpec 测试。该应用程序是一个更大项目的附加组件,我对环境还不是很熟悉。我以前也从未使用过 RSpec,所以这很可能是一个基本问题。

首先,我编写了一些不应该失败的基本测试:

require 'spec_helper'
require '../../../lib/release_notes/release_notes_generator'

describe ReleaseNotesGenerator do
  before :each do
    @rng = ReleaseNotesGenerator.new()
  end

  it 'should print hello world' do
    puts "Hello world!"
  end

  describe "#new" do
    it "tests basic rspec syntax" do
      @rng.should be_an_instance_of ReleaseNotesGenerator
    end
  end
end

但是,当我运行这些测试时,我得到了这个错误:

An error occurred in an after(:all) hook.
  Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)
  occurred at /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:276:in `rescue in establish_connection'

Redis 如何影响 RSpec 测试?到目前为止,我的任何工作都没有涉及 Redis。我进行了一些搜索,但找不到任何其他提及此错误的内容。

谢谢你的帮助!

编辑:这是完整的堆栈跟踪(相当长)

[Zonebie] Setting timezone to "Almaty"

ReleaseNotesGenerator
  should print hello world (FAILED - 1)
  #new
    tests basic rspec syntax (FAILED - 2)

An error occurred in an after(:all) hook.
  Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)
  occurred at /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:276:in `rescue in establish_connection'


Failures:

  1) ReleaseNotesGenerator should print hello world
     Failure/Error: Unable to find matching line from backtrace
     Redis::CannotConnectError:
       Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:276:in `rescue in establish_connection'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:271:in `establish_connection'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:69:in `connect'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:290:in `ensure_connected'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:177:in `block in process'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:256:in `logging'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:176:in `process'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:84:in `call'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis.rb:69:in `block in select'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis.rb:36:in `block in synchronize'
     # /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis.rb:36:in `synchronize'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis.rb:67:in `select'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-namespace-1.2.1/lib/redis/namespace.rb:257:in `method_missing'
     # /Users/nadams/Workspace/orbit-server/spec/spec_helper.rb:47:in `block (2 levels) in <top (required)>'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:21:in `instance_eval'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:21:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:100:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:418:in `run_hook'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:320:in `block in run_before_all_hooks'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/memoized_helpers.rb:96:in `block in isolate_for_before_all'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/memoized_helpers.rb:92:in `instance_eval'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/memoized_helpers.rb:92:in `isolate_for_before_all'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:319:in `run_before_all_hooks'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:370:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `map'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block in run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in `report'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

  2) ReleaseNotesGenerator#new tests basic rspec syntax
     Failure/Error: Unable to find matching line from backtrace
     Redis::CannotConnectError:
       Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:276:in `rescue in establish_connection'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:271:in `establish_connection'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:69:in `connect'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:290:in `ensure_connected'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:177:in `block in process'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:256:in `logging'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:176:in `process'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis/client.rb:84:in `call'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis.rb:69:in `block in select'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis.rb:36:in `block in synchronize'
     # /Users/nadams/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis.rb:36:in `synchronize'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-3.0.4/lib/redis.rb:67:in `select'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/redis-namespace-1.2.1/lib/redis/namespace.rb:257:in `method_missing'
     # /Users/nadams/Workspace/orbit-server/spec/spec_helper.rb:47:in `block (2 levels) in <top (required)>'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:21:in `instance_eval'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:21:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:100:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:418:in `run_hook'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:320:in `block in run_before_all_hooks'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/memoized_helpers.rb:96:in `block in isolate_for_before_all'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/memoized_helpers.rb:92:in `instance_eval'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/memoized_helpers.rb:92:in `isolate_for_before_all'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:319:in `run_before_all_hooks'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:370:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `map'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block in run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in `report'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
     # /Users/nadams/.rvm/gems/ruby-2.0.0-p0@orbit/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

Finished in 0.12005 seconds
2 examples, 2 failures

Failed examples:

rspec ./release_notes_spec.rb:11 # ReleaseNotesGenerator should print hello world
rspec ./release_notes_spec.rb:16 # ReleaseNotesGenerator#new tests basic rspec syntax

Randomized with seed 11682
4

0 回答 0