【发布时间】:2014-03-09 06:15:36
【问题描述】:
我正在使用 rspec 来测试我的 Sinatra 应用程序。该应用程序非常简单,测试也是如此,但是当我从 CLI 运行 rspec 时,它只是启动了应用程序服务器。我从来没有发生过这种情况。
这是我的spec_helper.rb 的样子:
#spec/spec_helper.rb
require File.expand_path '../../app.rb', __FILE__
ENV['RACK_ENV'] = "test"
require 'rspec'
require 'rack/test'
set :environment, :test
set :run, false
set :raise_errors, true
set :logging, false
module RSpecMixin
def app
App.new
end
end
RSpec.configure do |config|
config.color_enabled = true
config.tty = true
config.formatter = :documentation
config.include Rack::Test::Methods
config.include RSpecMixin
end
而我的规格只是
require 'spec_helper'
describe "My Sinatra Application" do
it "should allow accessing the home page" do
expect(1).to eq(1)
end
end
我无法运行 rspec。
我尝试过的:
我已经尝试了Sinatra testing guide 中的建议。还有 rspec Sinatra test recipe。在this blog post 中,set :run, false 看起来很有希望,但没有骰子。然后我想,我就define a rake task。将rspec gem 放在test 组中,并将RACK_ENV 设置为测试。所有这些都只是启动应用服务器:
$ rake spec
[2014-03-08 22:06:38] INFO WEBrick 1.3.1
[2014-03-08 22:06:38] INFO ruby 2.0.0 (2013-02-24) [x86_64-darwin11.4.2]
== Sinatra/1.4.4 has taken the stage on 4567 for development with backup from WEBrick
[2014-03-08 22:06:38] INFO WEBrick::HTTPServer#start: pid=21538 port=4567
停下来?
【问题讨论】:
-
你的
app.rb是什么样的?