teabag 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +99 -92
- data/app/assets/javascripts/teabag/base/fixture.coffee +99 -0
- data/app/assets/javascripts/teabag/base/teabag.coffee +1 -0
- data/app/assets/javascripts/teabag/jasmine.coffee +34 -2
- data/app/assets/javascripts/teabag/mocha.coffee +24 -2
- data/app/assets/javascripts/teabag/qunit.coffee +14 -5
- data/app/assets/javascripts/teabag-jasmine.js +244 -4
- data/app/assets/javascripts/teabag-mocha.js +228 -4
- data/app/assets/javascripts/teabag-qunit.js +200 -9
- data/app/assets/stylesheets/teabag.css +1 -0
- data/app/views/teabag/spec/index.html.erb +8 -9
- data/lib/generators/teabag/install/templates/initializer.rb +26 -28
- data/lib/teabag/suite.rb +9 -1
- data/lib/teabag/version.rb +1 -1
- data/spec/dummy/log/development.log +69910 -0
- data/spec/dummy/log/test.log +85 -0
- data/spec/dummy/tmp/cache/assets/C13/B50/sprockets%2F431452d41e5087d2211162d23c63789b +0 -0
- data/spec/dummy/tmp/cache/assets/C1C/2A0/sprockets%2F5820652740cdd23312489d2168c02e69 +0 -0
- data/spec/dummy/tmp/cache/assets/C59/250/sprockets%2Fa80d3fe493d2476e58c4323996064512 +0 -0
- data/spec/dummy/tmp/cache/assets/C72/150/sprockets%2F4194031b4b51b6422c14ac697e3455e5 +0 -0
- data/spec/dummy/tmp/cache/assets/C75/D50/sprockets%2F5302968a40e08d2c011aa38666d273f6 +0 -0
- data/spec/dummy/tmp/cache/assets/C8A/460/sprockets%2F77bffd9959420103906722b404ae8d59 +0 -0
- data/spec/dummy/tmp/cache/assets/C91/FA0/sprockets%2F2eb81283f5789ae91a69344552db3856 +0 -0
- data/spec/dummy/tmp/cache/assets/C9D/E90/sprockets%2F3045c9533f179d3e1c805d163ed002a0 +0 -0
- data/spec/dummy/tmp/cache/assets/CA6/2F0/sprockets%2F20040c18b672e4c4d2731a2a929d8b97 +0 -0
- data/spec/dummy/tmp/cache/assets/CA6/DF0/sprockets%2F7da83747ce56e49393b6b8726587f846 +0 -0
- data/spec/dummy/tmp/cache/assets/CA9/C40/sprockets%2F932b7e2cd1e067289ab51190800814df +0 -0
- data/spec/dummy/tmp/cache/assets/CAD/410/sprockets%2F651414e5c7e86f05c5108dc71626b25c +0 -0
- data/spec/dummy/tmp/cache/assets/CAF/0F0/sprockets%2F6000e67cf3f2377f860c24da7c819701 +0 -0
- data/spec/dummy/tmp/cache/assets/CB4/6A0/sprockets%2F7373c9de844b711519cb49c4f1b16822 +0 -0
- data/spec/dummy/tmp/cache/assets/CBB/FA0/sprockets%2F74922109263bdc965b2e9567eec6d154 +0 -0
- data/spec/dummy/tmp/cache/assets/CBD/AF0/sprockets%2Fd687ec33822256e9444e8cd04f1b4873 +0 -0
- data/spec/dummy/tmp/cache/assets/CBF/630/sprockets%2F707d2db81468088470d476abff35388d +0 -0
- data/spec/dummy/tmp/cache/assets/CC2/EC0/sprockets%2F76bf80cb571ca530357f78db78167866 +0 -0
- data/spec/dummy/tmp/cache/assets/CC8/830/sprockets%2F0b287580513a016ea8cc914bbfe03016 +0 -0
- data/spec/dummy/tmp/cache/assets/CCE/C50/sprockets%2Fe12774c2fea852112414bb379a71f31a +0 -0
- data/spec/dummy/tmp/cache/assets/CD1/620/sprockets%2F06a3eb05fcb4175a679d6084a06026a6 +0 -0
- data/spec/dummy/tmp/cache/assets/CD3/460/sprockets%2F7f3f6802b0b309ed142d0b671c9640c4 +0 -0
- data/spec/dummy/tmp/cache/assets/CE0/090/sprockets%2F48d5d35ae87d0723318b8bc257fa2237 +0 -0
- data/spec/dummy/tmp/cache/assets/CE6/270/sprockets%2F2c98152560d18470fec8cf4c6829b4d0 +0 -0
- data/spec/dummy/tmp/cache/assets/CE6/7C0/sprockets%2Fa03a2c86ce6724be8542295e1cf24798 +0 -0
- data/spec/dummy/tmp/cache/assets/CE7/A60/sprockets%2Ff58eee249aa167d23f8220087bb46684 +0 -0
- data/spec/dummy/tmp/cache/assets/CE9/9E0/sprockets%2F135480d497ed7e4884462dc0ef0b80d7 +0 -0
- data/spec/dummy/tmp/cache/assets/CEB/090/sprockets%2F55dcd7ace406b77208c380d496e37864 +0 -0
- data/spec/dummy/tmp/cache/assets/CEB/B40/sprockets%2F1150bf8d912aa100a132251eefaf6045 +0 -0
- data/spec/dummy/tmp/cache/assets/CF7/F10/sprockets%2F8c45854ebd195b52cc42bf3f99996336 +0 -0
- data/spec/dummy/tmp/cache/assets/CFA/D20/sprockets%2Fb26796b39b3c5d6ed70be7989637a493 +0 -0
- data/spec/dummy/tmp/cache/assets/CFC/380/sprockets%2Fa7443cbd671446a589867dd5f4a4f989 +0 -0
- data/spec/dummy/tmp/cache/assets/D00/110/sprockets%2F6a6353b7723a8b21708e0fbfe04bd422 +0 -0
- data/spec/dummy/tmp/cache/assets/D00/F60/sprockets%2F42e279b52511c47d26c0adb125fd04e8 +0 -0
- data/spec/dummy/tmp/cache/assets/D03/630/sprockets%2F5d8da32dba6a7be70426a1d554773701 +0 -0
- data/spec/dummy/tmp/cache/assets/D04/170/sprockets%2F76ab1dc02e6c7618852708a1e05a2df3 +0 -0
- data/spec/dummy/tmp/cache/assets/D04/480/sprockets%2F8bd8f10500b21d2f9d94e4cd1401c936 +0 -0
- data/spec/dummy/tmp/cache/assets/D05/8D0/sprockets%2F319f8f235f452343f1ebf03cb262d23d +0 -0
- data/spec/dummy/tmp/cache/assets/D09/BF0/sprockets%2F9e6bca5d26f50d9484385d51ba04312c +0 -0
- data/spec/dummy/tmp/cache/assets/D0B/740/sprockets%2F781d3a2f0449451e9f35c5b0e3e2df41 +0 -0
- data/spec/dummy/tmp/cache/assets/D0E/570/sprockets%2F90fe371bf8091e88a712124d9cdae260 +0 -0
- data/spec/dummy/tmp/cache/assets/D12/F40/sprockets%2Fb6f95541e256c15909e0a5a5fbf2a359 +0 -0
- data/spec/dummy/tmp/cache/assets/D1B/730/sprockets%2Fcf6ce779d043d29aae915f599a413380 +0 -0
- data/spec/dummy/tmp/cache/assets/D1E/AA0/sprockets%2F5c8741a556bc955cd36e61c88582b6dc +0 -0
- data/spec/dummy/tmp/cache/assets/D21/240/sprockets%2Ffdd497fc5d8257a9e4a0aa2473798184 +0 -0
- data/spec/dummy/tmp/cache/assets/D31/9C0/sprockets%2Fbd102a4f5a4985c3519dd6ab0295a1c6 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/500/sprockets%2F6927df5a24d91c75d001e2b5600ab8be +0 -0
- data/spec/dummy/tmp/cache/assets/D35/7C0/sprockets%2Ff536a2606eaf7d542c0985104cb62baf +0 -0
- data/spec/dummy/tmp/cache/assets/D3C/840/sprockets%2Fc6202ec91d567a85bd3d46dc43ea9108 +0 -0
- data/spec/dummy/tmp/cache/assets/D44/E90/sprockets%2F05cfc0bf7c9938963d1d1c63248db80d +0 -0
- data/spec/dummy/tmp/cache/assets/D47/A90/sprockets%2Fe7ca382b607c595ea6505853f7fb63da +0 -0
- data/spec/dummy/tmp/cache/assets/D49/A10/sprockets%2Fc4656bd995a6f297c26d19b13aadb963 +0 -0
- data/spec/dummy/tmp/cache/assets/D50/D70/sprockets%2Fe2a3e6c95b11e0801a4eebae3a026026 +0 -0
- data/spec/dummy/tmp/cache/assets/D51/400/sprockets%2Ff5e433d8a31e80985b75ce598de236be +0 -0
- data/spec/dummy/tmp/cache/assets/D60/060/sprockets%2Fe8a6ac51dd42491eaa2f9130c1629eb2 +0 -0
- data/spec/dummy/tmp/cache/assets/D67/BC0/sprockets%2F35d2c2b45981ade5a2db2a9c7f37a615 +0 -0
- data/spec/dummy/tmp/cache/assets/D69/F90/sprockets%2F6a0795b7b38bd7e6142cd1b88211dade +0 -0
- data/spec/dummy/tmp/cache/assets/D6B/6E0/sprockets%2F266d99da1afe084cac250a6ba864c565 +0 -0
- data/spec/dummy/tmp/cache/assets/D6D/DA0/sprockets%2Fac936bf40b42227a2bf9d474ae9ec149 +0 -0
- data/spec/dummy/tmp/cache/assets/D6F/5B0/sprockets%2F5dcc801a7a6c340c5baf525839f9b8b6 +0 -0
- data/spec/dummy/tmp/cache/assets/D73/C00/sprockets%2F9cf4bfb486e4ab461e3f275a3d974c30 +0 -0
- data/spec/dummy/tmp/cache/assets/D78/2F0/sprockets%2F3c61f8915b8f717b1de788e6ecad122c +0 -0
- data/spec/dummy/tmp/cache/assets/D78/870/sprockets%2F8f3a7d4fcd104fa8e47f552f6630a49e +0 -0
- data/spec/dummy/tmp/cache/assets/D78/F10/sprockets%2Fa2d995664d1a9bf976c1bfbbb90f8710 +0 -0
- data/spec/dummy/tmp/cache/assets/D8C/520/sprockets%2F221cd58a042baac534d27e4cfedc1188 +0 -0
- data/spec/dummy/tmp/cache/assets/D93/BD0/sprockets%2Ff5e1b60201e08e3ddf8d3de5211f3d5e +0 -0
- data/spec/dummy/tmp/cache/assets/DA5/0A0/sprockets%2F7a4b5928cec69ab65afff309a04d6b47 +0 -0
- data/spec/dummy/tmp/cache/assets/DA6/D80/sprockets%2F8702dce2e6b9879a6add309e92ace2f0 +0 -0
- data/spec/dummy/tmp/cache/assets/DA8/C50/sprockets%2F0810627fddce930a399fc60d3be97fed +0 -0
- data/spec/dummy/tmp/cache/assets/DA9/BF0/sprockets%2Fc59f8f7bf494fe030610bc86bb7cc5e5 +0 -0
- data/spec/dummy/tmp/cache/assets/DAE/6C0/sprockets%2F77c7a8676aeefa73156c55dfcf51cc46 +0 -0
- data/spec/dummy/tmp/cache/assets/DB3/5D0/sprockets%2Fce1d4d75832c9bdeafd869f6f7b61725 +0 -0
- data/spec/dummy/tmp/cache/assets/DB5/040/sprockets%2F9a9da5df88713663b9fbc945facca891 +0 -0
- data/spec/dummy/tmp/cache/assets/DC4/860/sprockets%2Fa01a3cf460ff15daae0f928d0f85f52e +0 -0
- data/spec/dummy/tmp/cache/assets/DC7/A10/sprockets%2F84a8af0fcbf401864e1ae5bf092cba94 +0 -0
- data/spec/dummy/tmp/cache/assets/DE3/6C0/sprockets%2F51c550cc1b3b021aa9aede66a5a36aff +0 -0
- data/spec/dummy/tmp/cache/assets/DEB/110/sprockets%2F2dbdab0ce5babca645cdb5780004f875 +0 -0
- data/spec/dummy/tmp/cache/assets/DF6/0E0/sprockets%2F85b10db6e1afe643aba6d396abdd77f0 +0 -0
- data/spec/dummy/tmp/cache/assets/DF7/E10/sprockets%2F25e4253aba9a9adcefb72552fb1ff0c8 +0 -0
- data/spec/dummy/tmp/cache/assets/DFC/C20/sprockets%2Fd9178ad7e3b401c9fceafd64ea2b50d6 +0 -0
- data/spec/dummy/tmp/cache/assets/DFC/C30/sprockets%2Fb50a07cb30b0bd0eec8e98e5de79d65d +0 -0
- data/spec/dummy/tmp/cache/assets/E02/6E0/sprockets%2F63d6a5cdb8cefa64ef76b5c6e0fd3720 +0 -0
- data/spec/dummy/tmp/cache/assets/E08/F20/sprockets%2F4fc5cdcd6974efe7adfe809b30bd6513 +0 -0
- data/spec/dummy/tmp/cache/assets/E14/8E0/sprockets%2Fb8d902ffcf8758fde63d0fa579ba6d4e +0 -0
- data/spec/dummy/tmp/cache/assets/E16/D30/sprockets%2Fd69469e6e7439baacd8df989c0fdacc2 +0 -0
- data/spec/dummy/tmp/cache/assets/E17/EF0/sprockets%2Fa291ad64a26afd055dfadabbdf03f154 +0 -0
- data/spec/dummy/tmp/cache/assets/E2F/790/sprockets%2F7fac280deaa7ef20a77d5c9b5b9cfc34 +0 -0
- data/spec/dummy/tmp/cache/assets/E41/250/sprockets%2F97cf8fe3d7ffaff076f655aefb36da03 +0 -0
- data/spec/dummy/tmp/cache/assets/E6E/260/sprockets%2Fd9f8ab8b91ef582cc6c99a3ba0dedfe6 +0 -0
- data/spec/dummy/tmp/cache/assets/F79/360/sprockets%2F0ce035fefee5ebdabc8efabfbdbd6ee4 +0 -0
- data/spec/javascripts/fixtures/fixture.json +4 -0
- data/spec/javascripts/teabag/base/fixture_spec.coffee +93 -0
- data/spec/javascripts/teabag/jasmine/jasmine_jspec.coffee +16 -0
- data/spec/javascripts/teabag/mocha/mocha_mspec.coffee +16 -3
- data/spec/teabag/suite_spec.rb +23 -1
- metadata +15 -4
data/README.md
CHANGED
@@ -9,9 +9,7 @@ Ok, another test runner, right? Really? Yeah, that's a tough one, but we're pret
|
|
9
9
|
|
10
10
|
The intention is to be the simplest but most complete Javascript testing solution for Rails, taking full advantage of the asset pipeline. It ships with support for Jasmine, Mocha and QUnit, and has custom reporters for each.
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
[Follow @modeset_ on twitter](https://twitter.com/modeset_)
|
12
|
+
Feedback, ideas and pull requests are always welcome, or you can hit us up [@modeset_](https://twitter.com/modeset_).
|
15
13
|
|
16
14
|
|
17
15
|
## Screenshots
|
@@ -32,16 +30,16 @@ We've just released Teabag, and we expect to be working on it for a while to get
|
|
32
30
|
2. [Quickstart](#quickstart)
|
33
31
|
3. [Usage](#usage)
|
34
32
|
4. [Writing Specs](#writing-specs)
|
35
|
-
5. [
|
36
|
-
6. [
|
37
|
-
7. [
|
38
|
-
8. [
|
39
|
-
9. [
|
40
|
-
10. [
|
33
|
+
5. [Fixtures](#fixtures)
|
34
|
+
6. [Suites](#suites)
|
35
|
+
7. [Configuration](#configuration)
|
36
|
+
8. [Test Frameworks](#test-frameworks)
|
37
|
+
9. [Support Libraries](#support-libraries)
|
38
|
+
10. [CI Support](#ci-support)
|
41
39
|
|
42
40
|
## Installation
|
43
41
|
|
44
|
-
Add it to your Gemfile. In
|
42
|
+
Add it to your Gemfile. In most cases you'll want to restrict it to the `:asset`, or `:development, :test` groups.
|
45
43
|
|
46
44
|
```ruby
|
47
45
|
group :assets do
|
@@ -49,7 +47,7 @@ group :assets do
|
|
49
47
|
end
|
50
48
|
```
|
51
49
|
|
52
|
-
Optionally run the install generator to get the initializer and a basic spec helper
|
50
|
+
Optionally run the install generator to get the initializer and a basic spec helper.
|
53
51
|
|
54
52
|
```
|
55
53
|
rails generate teabag:install
|
@@ -67,19 +65,17 @@ rails generate teabag:install
|
|
67
65
|
|
68
66
|
The install generator will create a `spec/javascripts` directory for you. Teabag will automatically pick up any specs written in that folder named `[classname]_spec.(js|coffee|js.coffee)`.
|
69
67
|
|
70
|
-
Let's write a basic
|
68
|
+
Let's write a basic implementation in CoffeeScript using Jasmine (you could just as easily use vanilla Javascript). Create a `spec/javascripts/calculator_spec.coffee` and put this in it:
|
71
69
|
|
72
70
|
```coffeescript
|
73
71
|
#= require calculator
|
72
|
+
describe "Calculator", ->
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
it 'should add two digits', ->
|
78
|
-
calc = new Calculator()
|
79
|
-
expect( calc.add(2,2) ).toBe(4)
|
74
|
+
it "should add two digits", ->
|
75
|
+
expect( new Calculator().add(2,2) ).toBe(4)
|
80
76
|
```
|
81
77
|
|
82
|
-
|
78
|
+
Now let's create an `app/assets/javascripts/calculator.coffee` and add:
|
83
79
|
|
84
80
|
```coffeescript
|
85
81
|
class @Calculator
|
@@ -94,23 +90,23 @@ Failures:
|
|
94
90
|
Failure/Error: TypeError: 'undefined' is not a function
|
95
91
|
```
|
96
92
|
|
97
|
-
|
93
|
+
To make the test pass we just need to implement the `add` method.
|
98
94
|
|
99
95
|
```coffeescript
|
100
96
|
add: (a, b) ->
|
101
97
|
a + b
|
102
98
|
```
|
103
99
|
|
104
|
-
|
100
|
+
`rake teabag` again and that spec should be passing!
|
105
101
|
|
106
102
|
If you'd prefer, you can also run your tests in the browser. Fire up your Rails server and visit [localhost:3000/teabag](http://localhost:3000/teabag) to run the specs in whichever browser you want.
|
107
103
|
|
108
104
|
|
109
105
|
## Usage
|
110
106
|
|
111
|
-
Teabag uses the Rails asset pipeline to serve files
|
107
|
+
Teabag uses the Rails asset pipeline to serve files. This simplifies the fixtures as well and lets you use things like HAML or RABL/JBuilder to generate your fixtures.
|
112
108
|
|
113
|
-
If you want a more visual experience you can browse to the specs in the browser, or you can use the rake task to run them
|
109
|
+
If you want a more visual experience you can browse to the specs in the browser, or you can use the rake task to run them headlessly with PhantomJS or with Selenium WebDriver.
|
114
110
|
|
115
111
|
### Browser
|
116
112
|
|
@@ -136,23 +132,15 @@ Specify the suite with the rake task by using:
|
|
136
132
|
rake teabag suite=my_fantastic_suite
|
137
133
|
```
|
138
134
|
|
139
|
-
|
140
|
-
|
141
|
-
You can override a few configurations by using environment variables. `FAILS_FALSE=[true/false]`, `SUPPRESS_LOGS=[false/true]` and `FORMATTERS=tap_y`. You can read more about these configuration directives below.
|
135
|
+
You can override a few configurations by using environment variables. `FAILS_FALSE=[true/false]`, `SUPPRESS_LOGS=[false/true]` and `FORMATTERS=tap_y` (read more about [configuration](#configuration) below.)
|
142
136
|
|
143
|
-
Teabag has support for [tapout](https://github.com/rubyworks/tapout).
|
137
|
+
Teabag also has support for [tapout](https://github.com/rubyworks/tapout). Use the tap_y formatter and pipe the results to tapout to use any of the reporters that tapout provides.
|
144
138
|
|
145
139
|
```
|
146
140
|
rake teabag SUPPRESS_LOG=true FORMATTERS=tap_y | tapout progress
|
147
141
|
```
|
148
142
|
|
149
|
-
**Note:** By default the rake task runs within the development environment, but you can specify the environment using`RAILS_ENV=test rake teabag`. This is an asset compilation optimization, and to keep consistent with what you might see in the browser (since that's likely running in development).
|
150
|
-
|
151
|
-
**Note:** We usually like to include our Javascript specs into the default rake task, like so:
|
152
|
-
|
153
|
-
```ruby
|
154
|
-
task :default => [:spec, :teabag, :cucumber]
|
155
|
-
```
|
143
|
+
**Note:** By default the rake task runs within the development environment, but you can specify the environment using `RAILS_ENV=test rake teabag`. This is an asset compilation optimization, and to keep consistent with what you might see in the browser (since that's likely running in development).
|
156
144
|
|
157
145
|
|
158
146
|
## Writing Specs
|
@@ -175,11 +163,11 @@ describe("My great feature", function() {
|
|
175
163
|
});
|
176
164
|
```
|
177
165
|
|
178
|
-
Check out
|
166
|
+
Check out examples of a [Mocha Spec](https://github.com/modeset/teabag/wiki/Using-Mocha) and a [QUnit Test](https://github.com/modeset/teabag/wiki/Using-QUnit).
|
179
167
|
|
180
168
|
### Pending Specs
|
181
169
|
|
182
|
-
We've normalized declaring that a spec is pending between
|
170
|
+
We've normalized declaring that a spec is pending between Mocha and Jasmine. Since Jasmine lacks the concept we've added it in, and since Mocha has several ways to accomplish it we thought it would be worth mentioning what we consider the standard between the two to be.
|
183
171
|
|
184
172
|
To mark a spec as pending you can either not provide a function as the second argument to `it`, or you can use `xit` and `xdescribe`. Mocha provides some additional ways to accomplish this, but to keep it consistent we've normalized on what they both support.
|
185
173
|
|
@@ -197,47 +185,75 @@ describe "My great feature", ->
|
|
197
185
|
expect(true).to.be(false)
|
198
186
|
```
|
199
187
|
|
200
|
-
If you're using
|
188
|
+
If you're using a specific framework and you want to take advantage of the things that that framerowk provides you're free to do so, and this is provided as a recommended standard. The Teabag reporters understand the techniques above and have specs for them. QUnit doesn't support specifying a test as pending.
|
189
|
+
|
190
|
+
### Deferring Execution
|
191
|
+
|
192
|
+
Teabag allows deferring execution in the cases when you're using AMD or other asynchronous libraries. This is especially useful if you're using [CommonJS](http://www.commonjs.org/) or [RequireJS](http://requirejs.org/), etc. You can tell Teabag to defer and then execute the runner yourself later -- after loading asychronously.
|
193
|
+
|
194
|
+
```coffeescript
|
195
|
+
Teabag.defer = true
|
196
|
+
setTimeout(Teabag.execute, 1000) # defers execution for 1 second
|
197
|
+
```
|
198
|
+
|
201
199
|
|
202
|
-
|
200
|
+
## Fixtures
|
203
201
|
|
204
|
-
|
202
|
+
You're free to use your own fixture library (like jasmine-jquery, which we've included as a support library), but Teabag ships with a fixture library that works with Mocha, Jasmine, and QUnit with a minimum of effort and a nice API.
|
205
203
|
|
206
|
-
|
204
|
+
The fixture path is configurable within Teabag, and the views will be rendered by a standard controller. This allows you to use things like RABL/JBuilder if you're building JSON, or HAML if you're building markup. The element that Teabag creates is "#teabag-fixtures", in case you need to access it directly.
|
207
205
|
|
208
|
-
The fixture path is configurable, and the views will be rendered by a controller. This allows you to use things like rabl if you're building JSON, or haml if you're building markup.
|
209
206
|
|
210
|
-
|
207
|
+
### Loading Files
|
211
208
|
|
212
|
-
|
213
|
-
#= require jquery
|
214
|
-
#= require support/jasmine-jquery
|
215
|
-
describe "fixtures", ->
|
209
|
+
Loading fixtures allows you to specify any number of files to load, and if they should be appended to the fixture element, or replace what's currently there.
|
216
210
|
|
217
|
-
|
218
|
-
loadFixtures("fixture.html")
|
219
|
-
expect($("#fixture_view")).toExist()
|
220
|
-
```
|
211
|
+
`fixture.load(url[, url, ...], append = false)` or `fixture(url[, url, ...], append = false)`
|
221
212
|
|
222
|
-
###
|
213
|
+
### Setting Manually
|
223
214
|
|
224
|
-
|
215
|
+
If you don't want to load files directly from the server you can provide strings instead of files, otherwise functions exactly like `fixture.load`.
|
225
216
|
|
226
|
-
|
217
|
+
`fixture.set(html[, html, ...], append = false)`
|
218
|
+
|
219
|
+
### Cleaning Up
|
220
|
+
|
221
|
+
You shouldn't have to cleanup (we do that for you based on your test framework), but if you need it.
|
222
|
+
|
223
|
+
`fixture.cleanup()`
|
224
|
+
|
225
|
+
### Preloading Files
|
226
|
+
|
227
|
+
Some test cases require stubbing Ajax requests, and in those cases you may want to preload the fixture files -- this caches them for later. You can preload fixtures in your spec helper, or before you start mocking Ajax methods.
|
228
|
+
|
229
|
+
`fixture.preload(url[, url, ...])`
|
230
|
+
|
231
|
+
### Example Usage
|
227
232
|
|
228
233
|
```coffeescript
|
229
|
-
|
230
|
-
|
234
|
+
fixture.preload("fixture.html", "fixture.json") # make the actual requests for the files
|
235
|
+
describe "Using fixtures", ->
|
236
|
+
|
237
|
+
fixture.set("<h2>Another Title</h2>") # create some markup manually (will be in a beforeEach)
|
238
|
+
|
239
|
+
beforeEach ->
|
240
|
+
@fixtures = fixture.load("fixture.html", "fixture.json", true) # append these fixtures which were already cached
|
241
|
+
|
242
|
+
it "loads fixtures", ->
|
243
|
+
expect($("h1", fixture.el).text()).toBe("Title") # using fixture.el as a jquery scope
|
244
|
+
expect($("h2", fixture.el).text()).toBe("Another Title")
|
245
|
+
expect(@fixtures[0]).toBe(fixture.el) # the element is available as a return value and through fixture.el
|
246
|
+
expect(@fixtures[1]).toEqual(fixture.json[0]) # the json for json fixtures is returned, and available in fixture.json
|
231
247
|
```
|
232
248
|
|
249
|
+
Check out an example of using fixtures with [Mocha](https://github.com/modeset/teabag/wiki/Using-Mocha) and [QUnit](https://github.com/modeset/teabag/wiki/Using-QUnit).
|
233
250
|
|
234
|
-
## Suites
|
235
251
|
|
236
|
-
|
252
|
+
## Suites
|
237
253
|
|
238
|
-
You can define suites in the configuration, and for brevity `config` is the argument passed to the `Teabag.setup` block.
|
254
|
+
Teabag uses the concept of suites to group your tests at a high level. These suites are run in isolation from one another, and can have different configurations. You can define suites in the configuration, and for brevity `config` is the argument passed to the `Teabag.setup` block.
|
239
255
|
|
240
|
-
When creating a suite
|
256
|
+
When creating a suite provide a name (optional) and a block. The following example defines a suite named "my_suite". You can focus to just this suite by browsing to `/teabag/my_suite` or running the rake task with `suite=my_suite`.
|
241
257
|
|
242
258
|
```ruby
|
243
259
|
config.suite :my_suite do |suite|
|
@@ -245,7 +261,7 @@ config.suite :my_suite do |suite|
|
|
245
261
|
end
|
246
262
|
```
|
247
263
|
|
248
|
-
There's always a "default" suite defined, and
|
264
|
+
There's always a "default" suite defined, and to modify this suite just don't specify a name, or use `:default`. In this example we're setting the default suite configuration.
|
249
265
|
|
250
266
|
```ruby
|
251
267
|
config.suite do |suite|
|
@@ -253,18 +269,18 @@ config.suite do |suite|
|
|
253
269
|
end
|
254
270
|
```
|
255
271
|
|
256
|
-
|
272
|
+
**Note:** Suites don't inherit from the default suite, but instead always fall back to the defaults outlined below.
|
257
273
|
|
258
274
|
### Manifest Style
|
259
275
|
|
260
|
-
Teabag is happy to look for files for you, but you can disable this feature and maintain a manifest yourself.
|
276
|
+
Teabag is happy to look for files for you, but you can disable this feature and maintain a manifest yourself. Each suite can utilize a different spec helper and you can use these to create your own manifest using the `= require` directive.
|
261
277
|
|
262
278
|
Tell the suite that you don't want it to match any files, and then require files in your spec helper.
|
263
279
|
|
264
280
|
```ruby
|
265
281
|
config.suite do |suite|
|
266
282
|
suite.matcher = nil
|
267
|
-
suite.helper = "
|
283
|
+
suite.helper = "spec_manifest"
|
268
284
|
end
|
269
285
|
```
|
270
286
|
|
@@ -272,29 +288,27 @@ end
|
|
272
288
|
|
273
289
|
#### `matcher`
|
274
290
|
|
275
|
-
You can specify a file matcher
|
291
|
+
You can specify a file matcher and all matching files will be loaded when the suite is run. It's important that these files are serve-able from sprockets.
|
276
292
|
|
277
|
-
**Note:**
|
293
|
+
**Note:** Can also be set to `nil`.
|
278
294
|
|
279
295
|
**default:** `"{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}"`
|
280
296
|
|
281
297
|
|
282
298
|
#### `helper`
|
283
299
|
|
284
|
-
Each suite can load a different spec helper, which can in turn require additional files. This file is loaded before your specs are loaded
|
300
|
+
Each suite can load a different spec helper, which can in turn require additional files. This file is loaded before your specs are loaded, and can be used as a manifest.
|
285
301
|
|
286
302
|
**default:** `"spec_helper"`
|
287
303
|
|
288
304
|
#### `javascripts`
|
289
305
|
|
290
|
-
These are the core Teabag javascripts.
|
306
|
+
These are the core Teabag javascripts. It's strongly encouraged to include only the base files here. You can require other support libraries in your spec helper, which allows you to change them without having to restart the server.
|
291
307
|
|
292
308
|
Available frameworks: teabag-jasmine, teabag-mocha, teabag-qunit
|
293
309
|
|
294
310
|
**Note:** To use the CoffeeScript source files use `"teabag/jasmine"` etc.
|
295
311
|
|
296
|
-
**Note:** It's strongly encouraged to include only the base files in the `javascripts` directive. You can require other support libraries in your spec helper, which makes them easier to change (you don't have to restart the server.)
|
297
|
-
|
298
312
|
**default:** `["teabag-jasmine"]`
|
299
313
|
|
300
314
|
#### `stylesheets`
|
@@ -308,41 +322,41 @@ If you want to change how Teabag looks, or include your own stylesheets you can
|
|
308
322
|
|
309
323
|
The best way to read about the configuration options is to generate the initializer, but we've included the info here too.
|
310
324
|
|
311
|
-
**Note:** `Teabag.setup` may not be available in all environments
|
325
|
+
**Note:** `Teabag.setup` may not be available in all environments. The generator provides a check wrapped around Teabag.setup.
|
312
326
|
|
313
327
|
#### `mount_at`
|
314
328
|
|
315
|
-
This determines where the Teabag
|
329
|
+
This determines where the Teabag routes will be mounted. Changing this to "/jasmine" would allow you to browse to http://localhost:3000/jasmine to run your specs.
|
316
330
|
|
317
331
|
**default:** `"/teabag"`
|
318
332
|
|
319
333
|
#### `root`
|
320
334
|
|
321
|
-
|
335
|
+
This defaults to Rails.root if left nil. If you're testing an engine using a dummy application it can be useful to set this to your engines root.. E.g. `Teabag::Engine.root`
|
322
336
|
|
323
337
|
**default:** `nil`
|
324
338
|
|
325
339
|
#### `asset_paths`
|
326
340
|
|
327
|
-
These paths are appended to the
|
341
|
+
These paths are appended to the Rails assets paths (relative to config.root), and by default is an array that you can replace or add to.
|
328
342
|
|
329
343
|
**default:** `["spec/javascripts", "spec/javascripts/stylesheets", "test/javascripts", "test/javascripts/stylesheets"]`
|
330
344
|
|
331
345
|
#### `fixture_path`
|
332
346
|
|
333
|
-
Fixtures are
|
347
|
+
Fixtures are rendered through a standard controller. This means you can use things like HAML or RABL/JBuilder, etc. to generate fixtures within this path.
|
334
348
|
|
335
349
|
**default:** `"spec/javascripts/fixtures"`
|
336
350
|
|
337
351
|
#### `server_timeout`
|
338
352
|
|
339
|
-
Timeout for starting the server in seconds. If your server is slow to start you may have to bump
|
353
|
+
Timeout for starting the server in seconds. If your server is slow to start you may have to bump this, or you may want to lower this if you know it shouldn't take long to start.
|
340
354
|
|
341
355
|
**default:** `20`
|
342
356
|
|
343
357
|
#### `driver`
|
344
358
|
|
345
|
-
Allows you to specify which driver you want to run your specs with -- Supports [PhantomJS](http://phantomjs.org/) and [Selenium Webdriver](http://seleniumhq.org/docs/03_webdriver.jsp).
|
359
|
+
Allows you to specify which driver you want to run your specs with -- Supports [PhantomJS](http://phantomjs.org/) and [Selenium Webdriver](http://seleniumhq.org/docs/03_webdriver.jsp). Check the wiki for more information about [Using Selenium WebDriver](https://github.com/modeset/teabag/wiki/Using-Selenium-WebDriver), and this one if you're having issues with [PhantomJS on Linux](https://github.com/modeset/teabag/wiki/PhantomJS-on-Linux).
|
346
360
|
|
347
361
|
Supported drivers: phantomjs, selenium
|
348
362
|
|
@@ -352,27 +366,27 @@ Supported drivers: phantomjs, selenium
|
|
352
366
|
|
353
367
|
#### `formatters`
|
354
368
|
|
355
|
-
|
369
|
+
You can specify the formatters that Teabag will use when outputting the results.
|
356
370
|
|
357
371
|
Supported formatters: dot, tap_y, swayze_or_oprah
|
358
372
|
|
359
|
-
**Note:** Override this directive by running `rake teabag FORMATTERS=dot,
|
373
|
+
**Note:** Override this directive by running `rake teabag FORMATTERS=dot,swayze_or_oprah`.
|
360
374
|
|
361
375
|
**default:** `"dot"`
|
362
376
|
|
363
377
|
#### `fail_fast`
|
364
378
|
|
365
|
-
|
379
|
+
If you have several suites it can be useful to make Teabag fail directly after any suite contains failures, but in environments like CI this may not be desirable.
|
366
380
|
|
367
|
-
**Note:**
|
381
|
+
**Note:** Override this directive by running `rake teabag FAIL_FAST=false`
|
368
382
|
|
369
383
|
**default:** `true`
|
370
384
|
|
371
385
|
#### `suppress_log`
|
372
386
|
|
373
|
-
|
387
|
+
Teabag pipes all console[log/debug/error] calls to STDOUT. This is useful to catch places where you've forgotten to remove them, but in verbose applications this may not be desirable.
|
374
388
|
|
375
|
-
**Note:**
|
389
|
+
**Note:** Override this directive by running `rake teabag SUPPRESS_LOG=true`
|
376
390
|
|
377
391
|
**default:** `false`
|
378
392
|
|
@@ -383,18 +397,18 @@ When you run Teabag from the console, it will pipe all console.log/debug/etc. ca
|
|
383
397
|
|
384
398
|
[Mocha](http://visionmedia.github.com/mocha) came up while we were working on Teabag -- we read up about it and thought it was a pretty awesome library with some really great approaches to some of the things that some of us browser types should consider more often, so we included it and added support for it. We encourage you to give it a try. Read more about [Using Mocha](https://github.com/modeset/teabag/wiki/Using-Mocha) with Teabag.
|
385
399
|
|
386
|
-
[QUnit](http://qunitjs.com) We're not sure about how many people use QUnit, but we like jQuery,
|
400
|
+
[QUnit](http://qunitjs.com) We're not sure about how many people use QUnit, but we like jQuery, so we added it. Read more about [Using QUnit](https://github.com/modeset/teabag/wiki/Using-QUnit) with Teabag.
|
387
401
|
|
388
402
|
|
389
403
|
## Support Libraries
|
390
404
|
|
391
|
-
|
405
|
+
We know that testing usually requires more than just the test framework, so we've included some of the libraries that we use on a regular basis.
|
392
406
|
|
393
407
|
- [jasmine-jquery.js](https://github.com/velesin/jasmine-jquery) jQuery matchers and fixture support (Jasmine).
|
394
|
-
- [Sinon.JS](https://github.com/cjohansen/Sinon.JS) Great for stubbing / spying, and mocking Ajax (Mocha/Jasmine).
|
395
408
|
- [expect.js](https://github.com/LearnBoost/expect.js) Minimalistic BDD assertion toolkit (Mocha).
|
409
|
+
- [Sinon.JS](https://github.com/cjohansen/Sinon.JS) Great for stubbing / spying, and mocking Ajax.
|
396
410
|
|
397
|
-
You can require these files in your spec helper using:
|
411
|
+
You can require these files in your spec helper by using:
|
398
412
|
|
399
413
|
```javascript
|
400
414
|
//=require support/jasmine-jquery
|
@@ -410,13 +424,6 @@ There's a few things that we're doing to make Teabag nicer on CI. We're in the p
|
|
410
424
|
More on this shortly....
|
411
425
|
|
412
426
|
|
413
|
-
## Roadmap
|
414
|
-
|
415
|
-
So, there's lots of directions we can take the Teabag project, but we'll give it some time to see what people are looking for.
|
416
|
-
|
417
|
-
Check the [issues](https://github.com/modeset/teabag/issues) to see / discuss features that we're considering or are working on.
|
418
|
-
|
419
|
-
|
420
427
|
## License
|
421
428
|
|
422
429
|
Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/)
|
@@ -0,0 +1,99 @@
|
|
1
|
+
class Teabag.fixture
|
2
|
+
|
3
|
+
@cache: {}
|
4
|
+
@el: null
|
5
|
+
@json: []
|
6
|
+
|
7
|
+
# Public API
|
8
|
+
|
9
|
+
@preload: (urls...) -> preload(url) for url in urls
|
10
|
+
|
11
|
+
|
12
|
+
@load: (urls..., append = false) ->
|
13
|
+
unless typeof(append) == "boolean"
|
14
|
+
urls.push(append)
|
15
|
+
append = false
|
16
|
+
load(url, append || index > 0) for url, index in urls
|
17
|
+
|
18
|
+
|
19
|
+
@set: (htmls..., append = false) ->
|
20
|
+
unless typeof(append) == "boolean"
|
21
|
+
htmls.push(append)
|
22
|
+
append = false
|
23
|
+
set(html, append || index > 0) for html, index in htmls
|
24
|
+
|
25
|
+
|
26
|
+
@cleanup: -> cleanup()
|
27
|
+
|
28
|
+
|
29
|
+
# behaves like load, and is only provided as a convenience
|
30
|
+
constructor: -> Teabag.fixture.load.apply(window, arguments)
|
31
|
+
|
32
|
+
|
33
|
+
# Private
|
34
|
+
|
35
|
+
xhr = null
|
36
|
+
|
37
|
+
preload = (url) =>
|
38
|
+
load(url, false, true)
|
39
|
+
|
40
|
+
|
41
|
+
load = (url, append, preload = false) =>
|
42
|
+
return loadComplete(url, cached.type, cached.content, append, preload) if cached = Teabag.fixture.cache[url]
|
43
|
+
value = null
|
44
|
+
xhrRequest url, ->
|
45
|
+
return unless xhr.readyState == 4
|
46
|
+
throw("Unable to load fixture \"#{url}\".") unless xhr.status == 200
|
47
|
+
value = loadComplete(url, xhr.getResponseHeader("content-type"), xhr.responseText, append, preload)
|
48
|
+
return value
|
49
|
+
|
50
|
+
|
51
|
+
loadComplete = (url, type, content, append, preload) =>
|
52
|
+
Teabag.fixture.cache[url] = {type: type, content: content}
|
53
|
+
return @json[@json.push(JSON.parse(content)) - 1] if type.match(/application\/json;/)
|
54
|
+
return content if preload
|
55
|
+
if append then addContent(content) else putContent(content)
|
56
|
+
return Teabag.fixture.el
|
57
|
+
|
58
|
+
|
59
|
+
set = (content, append) ->
|
60
|
+
if append then addContent(content) else putContent(content)
|
61
|
+
|
62
|
+
|
63
|
+
putContent = (content) =>
|
64
|
+
cleanup()
|
65
|
+
create()
|
66
|
+
Teabag.fixture.el.innerHTML = content
|
67
|
+
|
68
|
+
|
69
|
+
addContent = (content) =>
|
70
|
+
create() unless Teabag.fixture.el
|
71
|
+
Teabag.fixture.el.innerHTML += content
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
create = =>
|
76
|
+
Teabag.fixture.el = document.createElement("div")
|
77
|
+
Teabag.fixture.el.id = "teabag-fixtures"
|
78
|
+
document.body?.appendChild(Teabag.fixture.el)
|
79
|
+
|
80
|
+
|
81
|
+
cleanup = =>
|
82
|
+
Teabag.fixture.el ||= document.getElementById("teabag-fixtures")
|
83
|
+
Teabag.fixture.el?.parentNode?.removeChild(Teabag.fixture.el)
|
84
|
+
Teabag.fixture.el = null
|
85
|
+
|
86
|
+
|
87
|
+
xhrRequest = (url, callback) ->
|
88
|
+
if window.XMLHttpRequest # Mozilla, Safari, ...
|
89
|
+
xhr = new XMLHttpRequest()
|
90
|
+
else if window.ActiveXObject # IE
|
91
|
+
try xhr = new ActiveXObject("Msxml2.XMLHTTP")
|
92
|
+
catch e
|
93
|
+
try xhr = new ActiveXObject("Microsoft.XMLHTTP")
|
94
|
+
catch e
|
95
|
+
throw("Unable to make Ajax Request") unless xhr
|
96
|
+
|
97
|
+
xhr.onreadystatechange = callback
|
98
|
+
xhr.open("GET", "#{Teabag.root}/fixtures/#{url}", false)
|
99
|
+
xhr.send()
|
@@ -4,8 +4,6 @@
|
|
4
4
|
|
5
5
|
class Teabag.Runner extends Teabag.Runner
|
6
6
|
|
7
|
-
env = jasmine.getEnv()
|
8
|
-
|
9
7
|
constructor: ->
|
10
8
|
super
|
11
9
|
env.execute()
|
@@ -84,3 +82,37 @@ class Teabag.Suite
|
|
84
82
|
@link = "?grep=#{encodeURIComponent(@fullDescription)}"
|
85
83
|
@parent = @suite.parentSuite
|
86
84
|
@viewId = @suite.viewId
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
class Teabag.fixture extends Teabag.fixture
|
89
|
+
|
90
|
+
window.fixture = @
|
91
|
+
|
92
|
+
@load: ->
|
93
|
+
args = arguments
|
94
|
+
throw "Teabag can't load fixtures outside of describe." unless env.currentSuite || env.currentSpec
|
95
|
+
if env.currentSuite
|
96
|
+
env.beforeEach => fixture.__super__.constructor.load.apply(@, args)
|
97
|
+
env.afterEach => @cleanup()
|
98
|
+
super
|
99
|
+
else
|
100
|
+
env.currentSpec.after => @cleanup()
|
101
|
+
super
|
102
|
+
|
103
|
+
|
104
|
+
@set: ->
|
105
|
+
args = arguments
|
106
|
+
throw "Teabag can't load fixtures outside of describe." unless env.currentSuite || env.currentSpec
|
107
|
+
if env.currentSuite
|
108
|
+
env.beforeEach => fixture.__super__.constructor.set.apply(@, args)
|
109
|
+
env.afterEach => @cleanup()
|
110
|
+
super
|
111
|
+
else
|
112
|
+
env.currentSpec.after => @cleanup()
|
113
|
+
super
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
# set the environment
|
118
|
+
env = jasmine.getEnv()
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
class Teabag.Runner extends Teabag.Runner
|
7
7
|
|
8
|
-
env = mocha.setup("bdd")
|
9
|
-
|
10
8
|
constructor: ->
|
11
9
|
super
|
12
10
|
env.run()
|
11
|
+
env.started = true
|
12
|
+
afterEach -> Teabag.fixture.cleanup()
|
13
13
|
|
14
14
|
|
15
15
|
setup: ->
|
@@ -65,3 +65,25 @@ class Teabag.Suite
|
|
65
65
|
@link = "?grep=#{encodeURIComponent(@fullDescription)}"
|
66
66
|
@parent = if @suite.parent.root then null else @suite.parent
|
67
67
|
@viewId = @suite.viewId
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
class Teabag.fixture extends Teabag.fixture
|
72
|
+
|
73
|
+
window.fixture = @
|
74
|
+
|
75
|
+
@load: ->
|
76
|
+
args = arguments
|
77
|
+
if env.started then super
|
78
|
+
else beforeEach => fixture.__super__.constructor.load.apply(@, args)
|
79
|
+
|
80
|
+
|
81
|
+
@set: ->
|
82
|
+
args = arguments
|
83
|
+
if env.started then super
|
84
|
+
else beforeEach => fixture.__super__.constructor.set.apply(@, args)
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
# set the environment
|
89
|
+
env = mocha.setup("bdd")
|
@@ -5,10 +5,6 @@
|
|
5
5
|
|
6
6
|
class Teabag.Runner extends Teabag.Runner
|
7
7
|
|
8
|
-
env = QUnit
|
9
|
-
env.config.autostart = false
|
10
|
-
env.config.altertitle = false
|
11
|
-
|
12
8
|
constructor: ->
|
13
9
|
super
|
14
10
|
env.start()
|
@@ -25,7 +21,7 @@ class Teabag.Spec
|
|
25
21
|
constructor: (@spec) ->
|
26
22
|
@fullDescription = "#{@spec.module} #{@spec.name}"
|
27
23
|
@description = "#{@spec.name} (#{@spec.failed}, #{@spec.passed}, #{@spec.total})"
|
28
|
-
@link = "?grep=#{encodeURIComponent(@
|
24
|
+
@link = "?grep=#{encodeURIComponent("#{@spec.module}: #{@spec.name}")}"
|
29
25
|
@parent = if @spec.module then new Teabag.Suite({description: @spec.module}) else null
|
30
26
|
@suiteName = @spec.module
|
31
27
|
@viewId = @spec.viewId
|
@@ -59,3 +55,16 @@ class Teabag.Suite
|
|
59
55
|
@description = @suite.description
|
60
56
|
@link = "?grep=#{encodeURIComponent(@fullDescription)}"
|
61
57
|
@parent = null
|
58
|
+
|
59
|
+
|
60
|
+
# set the environment
|
61
|
+
env = QUnit
|
62
|
+
env.config.autostart = false
|
63
|
+
env.config.altertitle = false
|
64
|
+
env.config.filter = Teabag.Runner.prototype.getParams()["grep"]
|
65
|
+
|
66
|
+
window.fixture = Teabag.fixture
|
67
|
+
originalReset = env.reset
|
68
|
+
env.reset = ->
|
69
|
+
originalReset()
|
70
|
+
Teabag.fixture.cleanup()
|