test/unit/github_test.rb in vigetlabs-provisional-2.1.6 vs test/unit/github_test.rb in vigetlabs-provisional-2.1.7

- old
+ new

@@ -12,25 +12,40 @@ stub.expects(:config).with('github.token').returns('token') stub.expects(:add_remote) stub.expects(:push) end - URI.expects(:parse).with('https://github.com/api/v2/yaml/repos/create') - Net::HTTP.expects(:post_form).with(nil, { 'login' => 'user', 'token' => 'token', 'name' => 'name' }) + stub_github do |stub| + stub.expects(:request).returns(true) + end @scm.checkin end - def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception + def test_checkin_should_fail_if_any_step_raises_any_exception stub_git_checkin do |stub| stub.expects(:config).with('github.user').returns('user') stub.expects(:config).with('github.token').returns('token') end - URI.expects(:parse).with('https://github.com/api/v2/yaml/repos/create') - Net::HTTP.expects(:post_form).with(nil, { 'login' => 'user', 'token' => 'token', 'name' => 'name' }).raises(Net::HTTPUnauthorized) + stub_github do |stub| + stub.expects(:request).raises(Net::HTTPUnauthorized) + end assert_raise RuntimeError do @scm.checkin end + end + + private + + def stub_github + http = stub + + connection = stub(:use_ssl= => true, :verify_mode= => true) + connection.expects(:start).yields(http) + + Net::HTTP.expects(:new).with('github.com', 443).returns(connection) + + yield http end end