From 3e00622d44f9500728f74eec65b270765740a7eb Mon Sep 17 00:00:00 2001 From: Daniel Miranda Date: Thu, 18 Jun 2015 19:40:06 -0300 Subject: [PATCH] Fixed branch filling JS test --- spec/javascripts/repository/branch_spec.js.coffee | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/spec/javascripts/repository/branch_spec.js.coffee b/spec/javascripts/repository/branch_spec.js.coffee index ffc65f8..fde26b6 100644 --- a/spec/javascripts/repository/branch_spec.js.coffee +++ b/spec/javascripts/repository/branch_spec.js.coffee @@ -79,42 +79,31 @@ describe "Repository.Branch", -> describe '#fetch', -> beforeEach -> - @subject.cancel_request = sinon.spy() + @subject.cancel_request = sinon.stub() context 'with valid address', -> beforeEach -> - @subject.fill_options = sinon.spy() -# @subject.names = {'https://github.com/mezuro/prezento.git': ['master', 'dev']} + sinon.stub(@subject, "fill_options") + + afterEach -> + @subject.fill_options.restore() context 'with new address', -> beforeEach -> @subject.names = {} - @address = 'https://github.com/mezuro/kalibro_processor.git' - @select = sinon.stub() - # Stub just the selector and not the whole jQuery object - find_stub = sinon.stub($, "find") - find_stub.withArgs("#repository_branch").returns(@select) - find_stub.withArgs("#repository_scm_type").returns({val: -> "SVN"}) - - @server = sinon.fakeServer.create() - @server.respondImmediately = true - - address_url_encoded = encodeURI(@address) - @server.respondWith('GET', '/repository_branches&url=' + address_url_encoded + '&scm_type=' + 'GIT', - [200, { "Content-Type": "application/json" }, JSON.stringify({ - "branches": ["stable", "dev", "master"] - })] - ) + @select = {empty: sinon.stub()} + $ = sinon.stub(window, "$") + $.withArgs("#repository_branch").returns(@select) + $.withArgs("#repository_scm_type").returns({val: -> "GIT"}) + $.get = sinon.stub().withArgs('/repository_branches', {'url': @address, 'scm_type': 'GIT'}).returns().yields({ + 'branches': ['stable', 'dev', 'master'] + }) afterEach -> - @server.restore() - $.find.restore() + $.restore() it 'should fetch the branches and fill the options', -> @subject.fetch(@address) - @server.respond() - console.log(@server.requests[0]) - debugger - assert.isTrue(@subject.fill_options.calledWith(['stable', 'dev', 'master'], @select)) + sinon.assert.calledWith(@subject.fill_options, ['stable', 'dev', 'master'], @select) -- libgit2 0.21.2