Travis-CI上的RSpec测试失败,但在本地机器上成功通过

时间:2012-08-27 11:05:41

标签: ruby rspec sinatra travis-ci

我正在编写一些规范以涵盖我的HTML帮助程序

describe Sinatra::Helpers::HTML do
  describe 'tag' do
    it 'should retun selfclosed tag' do
      Helpers.tag(:br, {}, true).should == '<br />'
    end

    it 'should have valid attributes' do
      Helpers.tag(:div, :class => 'test').should include("class='test'")
    end

    it 'should contain value returned from block' do
      tag = Helpers.tag(:div) { 'Block value' }
      tag.should include('Block value')
    end
  end

  describe 'stylesheet_tag' do
    it 'should return link tag' do
      Helpers.stylesheet_tag('test').should include('link')
    end

    it 'should contain path to asset' do

    end
  end
end

当我在本地机器上运行时,一切都很好,一切都过去了。但在推送到GitHub之后,Travis失败并写道Object::Sinatra未初始化(link)并且我不明白为什么。

spec_helper.rb看起来:

ENV['RACK_ENV'] = "test"

require 'simplecov'
SimpleCov.start
require File.join(File.dirname(__FILE__), '..', 'boot')

require 'rspec'
require 'capybara/rspec'
require 'rack/test'
require 'factory_girl'

FactoryGirl.find_definitions

Capybara.app = Orodruin.rack

RSpec.configure do |config|
  config.include Rack::Test::Methods

  config.after(:each) do
    MongoMapper.database.collections.each do |collection|
      collection.remove unless collection.name.match(/^system\./)
    end
  end
end

class Helpers
  extend(*Sinatra::Base.included_modules.map(&:to_s).grep(/Helpers/).map(&:constantize))
end

2 个答案:

答案 0 :(得分:1)

因为http://travis-ci.org/#!/orodruin/orodruin/jobs/2248831/L73没有使用bundle exec。

上面的“捆绑exec rake”行似乎没有做任何事情。

您需要使用bundle exec为该行添加前缀。

我在您的代码中没有看到该行,但可以在您的某个宝石或Travis服务中进行硬编码。

真正的问题是,当Travis运行规格时,没有找到sinatra宝石。这是因为travis使用的是RVM gemset,你可能正在使用“全局”gemset。

结果是ruby -s rspec ...未在gem包环境中运行,并且未加载Sinatra。

答案 1 :(得分:1)

我忘了在我的specfile上添加require 'spec_helper'

相关问题