sinon-chai-rails 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +6 -0
- data/Rakefile +2 -0
- data/lib/sinon-chai-rails.rb +7 -0
- data/lib/sinon/chai/rails/engine.rb +11 -0
- data/lib/sinon/chai/rails/version.rb +7 -0
- data/sinon-chai-rails.gemspec +17 -0
- data/vendor/assets/javascripts/sinon-chai.js +95 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/sinon/chai/rails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Cymen Vig"]
|
6
|
+
gem.email = ["cymenvig@gmail.com"]
|
7
|
+
gem.summary = %q{sinon-chai.js via asset pipeline}
|
8
|
+
gem.homepage = "http://github.com/cymen/sinon-chai-rails"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
|
+
gem.name = "sinon-chai-rails"
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.version = Sinon::Chai::Rails::VERSION
|
15
|
+
|
16
|
+
gem.add_dependency 'railties', '>= 3.1'
|
17
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
(function (sinonChai) {
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
// Module systems magic dance.
|
5
|
+
|
6
|
+
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
|
7
|
+
// NodeJS
|
8
|
+
module.exports = sinonChai;
|
9
|
+
} else if (typeof define === "function" && define.amd) {
|
10
|
+
// AMD
|
11
|
+
define(function () {
|
12
|
+
return sinonChai;
|
13
|
+
});
|
14
|
+
} else {
|
15
|
+
// Other environment (usually <script> tag): plug in to global chai instance directly.
|
16
|
+
chai.use(sinonChai);
|
17
|
+
}
|
18
|
+
}(function sinonChai(chai, utils) {
|
19
|
+
"use strict";
|
20
|
+
|
21
|
+
var slice = Array.prototype.slice;
|
22
|
+
|
23
|
+
function isSpy(putativeSpy) {
|
24
|
+
return typeof putativeSpy === "function" &&
|
25
|
+
typeof putativeSpy.getCall === "function" &&
|
26
|
+
typeof putativeSpy.calledWithExactly === "function";
|
27
|
+
}
|
28
|
+
|
29
|
+
function isCall(putativeCall) {
|
30
|
+
return putativeCall && isSpy(putativeCall.proxy);
|
31
|
+
}
|
32
|
+
|
33
|
+
function assertCanWorkWith(assertion) {
|
34
|
+
if (!isSpy(assertion._obj) && !isCall(assertion._obj)) {
|
35
|
+
throw new TypeError(utils.inspect(assertion._obj) + " is not a spy or a call to a spy!");
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
function getMessages(spy, action, nonNegatedSuffix, always, args) {
|
40
|
+
var verbPhrase = always ? "always have " : "have ";
|
41
|
+
nonNegatedSuffix = nonNegatedSuffix || "";
|
42
|
+
spy = spy.proxy || spy;
|
43
|
+
|
44
|
+
function printfArray(array) {
|
45
|
+
return spy.printf.apply(spy, array);
|
46
|
+
}
|
47
|
+
|
48
|
+
return {
|
49
|
+
affirmative: printfArray(["expected %n to " + verbPhrase + action + nonNegatedSuffix].concat(args)),
|
50
|
+
negative: printfArray(["expected %n to not " + verbPhrase + action].concat(args))
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
function sinonProperty(name, action, nonNegatedSuffix) {
|
55
|
+
utils.addProperty(chai.Assertion.prototype, name, function () {
|
56
|
+
assertCanWorkWith(this);
|
57
|
+
|
58
|
+
var messages = getMessages(this._obj, action, nonNegatedSuffix, false);
|
59
|
+
this.assert(this._obj[name], messages.affirmative, messages.negative);
|
60
|
+
});
|
61
|
+
}
|
62
|
+
|
63
|
+
function exceptionalSinonMethod(chaiName, sinonName, action, nonNegatedSuffix) {
|
64
|
+
utils.addMethod(chai.Assertion.prototype, chaiName, function () {
|
65
|
+
assertCanWorkWith(this);
|
66
|
+
|
67
|
+
var alwaysSinonMethod = "always" + sinonName[0].toUpperCase() + sinonName.substring(1);
|
68
|
+
var shouldBeAlways = utils.flag(this, "always") && typeof this._obj[alwaysSinonMethod] === "function";
|
69
|
+
var sinonMethod = shouldBeAlways ? alwaysSinonMethod : sinonName;
|
70
|
+
|
71
|
+
var messages = getMessages(this._obj, action, nonNegatedSuffix, shouldBeAlways, slice.call(arguments));
|
72
|
+
this.assert(this._obj[sinonMethod].apply(this._obj, arguments), messages.affirmative, messages.negative);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
function sinonMethod(name, action, nonNegatedSuffix) {
|
77
|
+
exceptionalSinonMethod(name, name, action, nonNegatedSuffix);
|
78
|
+
}
|
79
|
+
|
80
|
+
utils.addProperty(chai.Assertion.prototype, "always", function () {
|
81
|
+
utils.flag(this, "always", true);
|
82
|
+
});
|
83
|
+
|
84
|
+
sinonProperty("called", "been called", " at least once, but it was never called");
|
85
|
+
sinonProperty("calledOnce", "been called exactly once", ", but it was called %c%C");
|
86
|
+
sinonProperty("calledTwice", "been called exactly twice", ", but it was called %c%C");
|
87
|
+
sinonProperty("calledThrice", "been called exactly thrice", ", but it was called %c%C");
|
88
|
+
sinonMethod("calledBefore", "been called before %1");
|
89
|
+
sinonMethod("calledAfter", "been called after %1");
|
90
|
+
sinonMethod("calledOn", "been called with %1 as this", ", but it was called with %t instead");
|
91
|
+
sinonMethod("calledWith", "been called with arguments %*", "%C");
|
92
|
+
sinonMethod("calledWithExactly", "been called with exact arguments %*", "%C");
|
93
|
+
sinonMethod("returned", "returned %1");
|
94
|
+
exceptionalSinonMethod("thrown", "threw", "thrown %1");
|
95
|
+
}));
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinon-chai-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cymen Vig
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
description:
|
31
|
+
email:
|
32
|
+
- cymenvig@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/sinon-chai-rails.rb
|
42
|
+
- lib/sinon/chai/rails/engine.rb
|
43
|
+
- lib/sinon/chai/rails/version.rb
|
44
|
+
- sinon-chai-rails.gemspec
|
45
|
+
- vendor/assets/javascripts/sinon-chai.js
|
46
|
+
homepage: http://github.com/cymen/sinon-chai-rails
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
hash: 232721519219228683
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: 232721519219228683
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.24
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: sinon-chai.js via asset pipeline
|
76
|
+
test_files: []
|