jasmine-spec-extras 0.0.1 → 0.0.2
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/README.md +10 -35
- data/jasmine-spec-extras.gemspec +1 -1
- data/lib/jasmine-spec-extras.rb +8 -0
- data/vendor/assets/javascripts/jasmine-sinon.js +44 -0
- metadata +4 -2
data/README.md
CHANGED
@@ -1,56 +1,31 @@
|
|
1
1
|
Use vendored Jasmine helpers! No more copying around all those fun helpers to all your projects!
|
2
|
-
Works with Rails gems like jquery-rails too!
|
3
2
|
|
4
|
-
Works in jasmine-headless-webkit versions
|
3
|
+
Works in jasmine-headless-webkit versions that support Sprockets.
|
5
4
|
|
6
5
|
## What it comes with...
|
7
6
|
|
8
7
|
It comes with the libraries I need:
|
9
8
|
|
10
9
|
* [jasmine-jquery](https://github.com/velesin/jasmine-jquery) 1.3.1
|
10
|
+
* [jasmine-sinon](https://github.com/froots/jasmine-sinon) 0.1.0
|
11
11
|
* [Sinon.js](http://sinonjs.org/) 1.2.0
|
12
12
|
|
13
13
|
## How to use it
|
14
14
|
|
15
|
-
|
15
|
+
It's Sprockets vendored gem goodness, so at the top of your `spec_helper`:
|
16
16
|
|
17
|
-
```
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
```
|
22
|
-
|
23
|
-
### ...and Rails asset gems, too?
|
24
|
-
|
25
|
-
Sure, this just looks for files in gems in the path `vendor/assets/javascripts/#{name}.js`. So if you want
|
26
|
-
to include jQuery from `jquery-rails`:
|
17
|
+
``` coffee
|
18
|
+
#= require jasmine-jquery
|
19
|
+
#= require sinon
|
20
|
+
#= require jasmine-sinon
|
27
21
|
|
28
|
-
|
29
|
-
vendored_helpers:
|
30
|
-
- 'jquery'
|
22
|
+
...make cool code...
|
31
23
|
```
|
32
24
|
|
33
|
-
Easy!
|
34
|
-
|
35
|
-
## Support in stock Jasmine yet?
|
36
|
-
|
37
|
-
Not yet, want to see how well this works first.
|
38
|
-
|
39
25
|
## Why?
|
40
26
|
|
41
|
-
|
42
|
-
|
43
|
-
* Part of the problem with testing modern Rails apps is the use of JavaScript bundled in gems, specifically in
|
44
|
-
the `vendor/assets/javascripts` folder of the gems that provide them. Normally, one uses a Railtie to find
|
45
|
-
out what provides those files, but you can also do it the slow way and look at all loaded gems for that
|
46
|
-
directory. Recent versions (on GitHub) of jasmine-headless-webkit support loading those vendored files.
|
47
|
-
|
48
|
-
* I got sick of copying jasmine-jquery and sinon to all my projects. Now with one gem, they're all available. It also
|
49
|
-
makes it easier to copy around your own JS stuff.
|
50
|
-
|
51
|
-
## How do I do this myself? I don't care if it's super-slow finding all the files.
|
52
|
-
|
53
|
-
Look at https://github.com/johnbintz/jasmine-headless-webkit/blob/master/lib/jasmine/files_list.rb#L162
|
27
|
+
I got sick of copying jasmine-jquery and sinon to all my projects. Now with one gem, they're all available. It also
|
28
|
+
makes it easier to copy around your own JS stuff.
|
54
29
|
|
55
30
|
## Warnings from the bleeding edge
|
56
31
|
|
data/jasmine-spec-extras.gemspec
CHANGED
data/lib/jasmine-spec-extras.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
/**
|
2
|
+
jasmine-sinon.js 0.1.0
|
3
|
+
**/
|
4
|
+
(function(global) {
|
5
|
+
|
6
|
+
var spyMatchers = "called calledOnce calledTwice calledThrice calledBefore calledAfter calledOn alwaysCalledOn calledWith alwaysCalledWith calledWithExactly alwaysCalledWithExactly".split(" "),
|
7
|
+
i = spyMatchers.length,
|
8
|
+
spyMatcherHash = {},
|
9
|
+
unusualMatchers = {
|
10
|
+
"returned": "toHaveReturned",
|
11
|
+
"alwaysReturned": "toHaveAlwaysReturned"
|
12
|
+
},
|
13
|
+
|
14
|
+
getMatcherFunction = function(sinonName) {
|
15
|
+
return function() {
|
16
|
+
var sinonProperty = this.actual[sinonName];
|
17
|
+
return (typeof sinonProperty === 'function') ? sinonProperty.apply(this.actual, arguments) : sinonProperty;
|
18
|
+
};
|
19
|
+
};
|
20
|
+
|
21
|
+
while(i--) {
|
22
|
+
var sinonName = spyMatchers[i],
|
23
|
+
matcherName = "toHaveBeen" + sinonName.charAt(0).toUpperCase() + sinonName.slice(1);
|
24
|
+
|
25
|
+
spyMatcherHash[matcherName] = getMatcherFunction(sinonName);
|
26
|
+
};
|
27
|
+
|
28
|
+
for (var j in unusualMatchers) {
|
29
|
+
spyMatcherHash[unusualMatchers[j]] = getMatcherFunction(j);
|
30
|
+
}
|
31
|
+
|
32
|
+
global.sinonJasmine = {
|
33
|
+
getMatchers: function() {
|
34
|
+
return spyMatcherHash;
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
})(window);
|
39
|
+
|
40
|
+
beforeEach(function() {
|
41
|
+
|
42
|
+
this.addMatchers(sinonJasmine.getMatchers());
|
43
|
+
|
44
|
+
});
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jasmine-spec-extras
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-04 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Bundle together oft-used Jasmine helper files in a clean way.
|
15
15
|
email:
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- jasmine-spec-extras.gemspec
|
26
26
|
- lib/jasmine-spec-extras.rb
|
27
27
|
- vendor/assets/javascripts/jasmine-jquery.js
|
28
|
+
- vendor/assets/javascripts/jasmine-sinon.js
|
28
29
|
- vendor/assets/javascripts/sinon.js
|
29
30
|
homepage: ''
|
30
31
|
licenses: []
|
@@ -51,3 +52,4 @@ signing_key:
|
|
51
52
|
specification_version: 3
|
52
53
|
summary: Bundle together oft-used Jasmine helper files in a clean way.
|
53
54
|
test_files: []
|
55
|
+
has_rdoc:
|