diff --git a/Gemfile b/Gemfile index f8d9308..92f0eb9 100644 --- a/Gemfile +++ b/Gemfile @@ -113,6 +113,9 @@ group :development, :test do gem 'i18n_generators' gem 'sprockets', '~>2.12.3' # spckets 3.0.3 breaks konacha + + # Mocks and stubs for javascript tests + gem 'sinon-rails' end # Acceptance tests diff --git a/Gemfile.lock b/Gemfile.lock index 3acc70b..5adaa0a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -283,6 +283,8 @@ GEM json (~> 1.8) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) + sinon-rails (1.10.3) + railties (>= 3.1) spring (1.3.6) sprockets (2.12.3) hike (~> 1.2) @@ -367,6 +369,7 @@ DEPENDENCIES sdoc (~> 0.4.0) shoulda-matchers (~> 2.8.0) simplecov + sinon-rails spring sprockets (~> 2.12.3) sqlite3 diff --git a/spec/javascripts/repository/branch_spec.js.coffee b/spec/javascripts/repository/branch_spec.js.coffee index 3826139..2849e1e 100644 --- a/spec/javascripts/repository/branch_spec.js.coffee +++ b/spec/javascripts/repository/branch_spec.js.coffee @@ -1,10 +1,30 @@ #= require application +#= require 'sinon' -describe "Repository.Branch", -> - beforeEach -> - @repository_branch = new Repository.Branch() +describe "Branch#constructor", -> + it "should construct a branch", -> + subject = new Repository.Branch() + subject.names.should.deep.equal({}) + assert.isNull(subject.request) - describe "Branch#constructor", -> - it "should construct a branch", -> - @repository_branch.names.should.deep.equal({}) - assert.isNull(@repository_branch.request) +describe "toggle", -> + @subject = new Repository.Branch() + beforeEach -> + @combo_box = sinon.stub() + $ = sinon.stub(window, "$") + $.withArgs("#branches").returns(@combo_box) + context "scm_type = SVN", -> + @combo_box.hide = sinon.spy() + it "should hide the branches combo box", -> + $.withArgs("#repository_scm_type").returns({val: -> "SVN"}) + @subject.toggle() + assert.isTrue(@combo_box.hide.calledOnce) + context "scm_type != SVN", -> + @combo_box.show = sinon.spy() + $.withArgs("#repository_address").returns({val: -> "https://github.com/mezuro/prezento.git"}) + sinon.stub(@subject, "fetch").withArgs("https://github.com/mezuro/prezento.git") + @subject.stub = sinon.spy() + it "should show the branches combo box", -> + $.withArgs("#repository_scm_type").returns({val: -> "GIT"}) + @subject.toggle() + assert.isTrue(@combo_box.show.calledOnce) -- libgit2 0.21.2