我有以下测试:
describe "POST 'create'" do
let(:url){ Rails.root.join('spec','files','example.git').to_s }
it "redirect" do
post 'create', repository: {url: url }
expect(response).to be_redirect
end
end
我的控制器代码:
def create
@repository = Repository.new repository_params
process_and_assign_respository_data
respond_to do |format|
if @repository.save
format.html { redirect_to @repository }
else
format.html { render action: 'new' }
end
end
end
private
def process_and_assign_respository_data
path = get_path
name = Time.now.to_i.to_s
Git.clone @repository.url, name, path: path
end
create action克隆存储库 测试在当地通过,但在Travis中打破并显示:
Failure/Error: post 'create', repository: { url: Rails.root.join('spec','files','example.git').to_s }
Git::GitExecuteError:
git clone "--" " &1:fatal: repository 'example.git' does not exist
我通过将url
更改为github存储库来修复它
有没有办法删除对github存储库的依赖,而不是在Travis中断?
答案 0 :(得分:0)
回购是否是有效的Github网址并不重要。您只需要假装数据进行测试,无论是夹具还是工厂,而我更喜欢FactoryGirl。
# Define it in factory file
factory :repo do
url: 'http://example.com/abc.git'
end
# Then test
describe "POST 'create'" do
let(:repo_attr) { FactoryGirl.attributes_for :repo }
it "redirect" do
post 'create', repository: repo_attr
expect(response).to be_redirect
end
end