Ruby Travis CI上的RSpec测试失败,但在本地计算机上成功通过

Ruby Travis CI上的RSpec测试失败,但在本地计算机上成功通过,ruby,rspec,sinatra,travis-ci,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, :cl

我正在写一些规范来涵盖我的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
因为没有使用bundle exec

上面的“bundle exec rake”行似乎什么也没做

您需要在该行前面加上bundle exec

我在你的代码中没有看到这一行,但它可以在你的一个gems或Travis服务中硬编码

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


结果是,
ruby-srspec…
没有在gem bundle环境中运行,也没有加载Sinatra。

我忘了在specfile上添加
require'spec\u helper'

我的
Gemfile
中有Sinatra,当我在本地机器上运行时,我还使用
bundle exec rake
并完全通过。
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