Skip to content

Commit

Permalink
* initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai Târnovan committed Jun 1, 2012
1 parent 849447c commit 37b9149
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in sinon-rails.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2012 Mihai Tarnovan

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
jasmine-sinon-rails
===================

jasmine-sinon.js matchers via Rails 3.1+ asset pipeline
<<<<<<< HEAD
jasmine-sinon.js matchers via Rails 3.1+ asset pipeline
=======
jasmine-sinon matchers via Rails 3.1+ asset pipeline

See https://github.com/froots/jasmine-sinon

In Gemfile... you know the drill.
>>>>>>> * initial commit
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
16 changes: 16 additions & 0 deletions jasmine-sinon-rails.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$:.push File.expand_path("../lib", __FILE__)
require File.expand_path('../lib/jasmine-sinon-rails/version', __FILE__)

Gem::Specification.new do |gem|
gem.authors = ["Mihai Tarnovan"]
gem.email = ["mihai.tarnovan@cubus.ro"]
gem.summary = %q{jasmine-sinon.js matchers via Rails 3.1+ asset pipeline}
gem.homepage = "https://github.com/mtarnovan/jasmine-sinon-rails"

gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "jasmine-sinon-rails"
gem.require_paths = ["lib"]
gem.version = JasmineSinon::Rails::VERSION
end
7 changes: 7 additions & 0 deletions lib/jasmine-sinon-rails/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Sinon
module Rails
class Engine < ::Rails::Engine
# making class enables assets pipeline
end
end
end
5 changes: 5 additions & 0 deletions lib/jasmine-sinon-rails/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Sinon
module Rails
VERSION = "1.3.2.1"
end
end
7 changes: 7 additions & 0 deletions lib/sinon-rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "jasmine-sinon-rails/version"

module JasmineSinon
module Rails
require 'jasmine-sinon-rails/engine' if defined?(Rails)
end
end
43 changes: 43 additions & 0 deletions vendor/assets/javascripts/jasmine-sinon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(function(global) {

var spyMatchers = "called calledOnce calledTwice calledThrice calledBefore calledAfter calledOn alwaysCalledOn calledWith alwaysCalledWith calledWithExactly alwaysCalledWithExactly".split(" "),
i = spyMatchers.length,
spyMatcherHash = {},
unusualMatchers = {
"returned": "toHaveReturned",
"alwaysReturned": "toHaveAlwaysReturned",
"threw": "toHaveThrown",
"alwaysThrew": "toHaveAlwaysThrown"
},

getMatcherFunction = function(sinonName) {
return function() {
var sinonProperty = this.actual[sinonName];
return (typeof sinonProperty === 'function') ? sinonProperty.apply(this.actual, arguments) : sinonProperty;
};
};

while(i--) {
var sinonName = spyMatchers[i],
matcherName = "toHaveBeen" + sinonName.charAt(0).toUpperCase() + sinonName.slice(1);

spyMatcherHash[matcherName] = getMatcherFunction(sinonName);
};

for (var j in unusualMatchers) {
spyMatcherHash[unusualMatchers[j]] = getMatcherFunction(j);
}

global.sinonJasmine = {
getMatchers: function() {
return spyMatcherHash;
}
};

})(window);

beforeEach(function() {

this.addMatchers(sinonJasmine.getMatchers());

});

0 comments on commit 37b9149

Please sign in to comment.