2012-08-27 48 views
0

我寫一些規格覆蓋我的HTML輔助RSpec的測試失敗的特拉維斯-CI但本地計算機上通過成功

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回購特拉維斯失敗,並寫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 

回答

1

我忘了在我的spec文件上添加require 'spec_helper'

1

因爲http://travis-ci.org/#!/orodruin/orodruin/jobs/2248831/L73沒有使用捆綁高管。

上面的「bundle exec rake」行似乎沒有做任何事情。

您需要在bundle exec前面加上前綴。

我在代碼中看不到那行代碼,但它可能會在您的某個寶石或Travis服務中被硬編碼。

真正的問題是,當Travis運行規格時,找不到Sinatra寶石。這是因爲Travis正在使用RVM gemset,並且您可能正在使用「全局」gemset。

結果是ruby -s rspec ...未運行在gem bundle環境中,也未加載Sinatra。

+0

我在我的'Gemfile'中有Sinatra,當我在本地機器上運行時,我也使用'bundle exec rake'並完全通過。 – Hauleth

相關問題