evergreen 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/README.rdoc +30 -4
  2. data/config/routes.rb +1 -1
  3. data/lib/evergreen.rb +14 -50
  4. data/lib/evergreen/application.rb +46 -0
  5. data/lib/evergreen/cli.rb +2 -2
  6. data/lib/evergreen/rails.rb +4 -0
  7. data/lib/evergreen/resources/evergreen.css +3 -1
  8. data/lib/evergreen/resources/evergreen.js +3 -0
  9. data/lib/evergreen/runner.rb +124 -36
  10. data/lib/evergreen/server.rb +9 -18
  11. data/lib/evergreen/spec.rb +26 -14
  12. data/lib/evergreen/suite.rb +44 -0
  13. data/lib/evergreen/tasks.rb +6 -0
  14. data/lib/evergreen/template.rb +7 -10
  15. data/lib/evergreen/version.rb +1 -1
  16. data/lib/evergreen/views/layout.erb +1 -0
  17. data/lib/evergreen/views/list.erb +2 -2
  18. data/lib/evergreen/views/spec.erb +18 -10
  19. data/lib/jasmine/Gemfile +6 -0
  20. data/lib/jasmine/MIT.LICENSE +2 -2
  21. data/lib/jasmine/README.markdown +5 -459
  22. data/lib/jasmine/Rakefile +22 -16
  23. data/lib/jasmine/example/SpecRunner.html +1 -1
  24. data/lib/jasmine/jsdoc-template/allclasses.tmpl +17 -0
  25. data/lib/jasmine/jsdoc-template/allfiles.tmpl +56 -0
  26. data/lib/jasmine/jsdoc-template/class.tmpl +646 -0
  27. data/lib/jasmine/jsdoc-template/index.tmpl +39 -0
  28. data/lib/jasmine/jsdoc-template/publish.js +184 -0
  29. data/lib/jasmine/jsdoc-template/static/default.css +162 -0
  30. data/lib/jasmine/jsdoc-template/static/header.html +2 -0
  31. data/lib/jasmine/jsdoc-template/static/index.html +19 -0
  32. data/lib/jasmine/jsdoc-template/symbol.tmpl +35 -0
  33. data/lib/jasmine/lib/jasmine-html.js +12 -6
  34. data/lib/jasmine/lib/jasmine.js +122 -44
  35. data/lib/jasmine/spec/runner.html +0 -1
  36. data/lib/jasmine/spec/suites/CustomMatchersSpec.js +18 -9
  37. data/lib/jasmine/spec/suites/MatchersSpec.js +241 -162
  38. data/lib/jasmine/spec/suites/SpecRunningSpec.js +120 -62
  39. data/lib/jasmine/spec/suites/TrivialReporterSpec.js +3 -0
  40. data/lib/jasmine/spec/suites/WaitsForBlockSpec.js +9 -9
  41. data/lib/jasmine/src/Env.js +1 -0
  42. data/lib/jasmine/src/Matchers.js +35 -17
  43. data/lib/jasmine/src/Queue.js +6 -1
  44. data/lib/jasmine/src/Spec.js +34 -2
  45. data/lib/jasmine/src/WaitsForBlock.js +28 -13
  46. data/lib/jasmine/src/base.js +15 -8
  47. data/lib/jasmine/src/html/TrivialReporter.js +12 -6
  48. data/lib/jasmine/src/version.json +2 -2
  49. data/lib/tasks/evergreen.rake +1 -1
  50. data/spec/meta_spec.rb +21 -2
  51. data/spec/runner_spec.rb +16 -18
  52. data/spec/spec_helper.rb +12 -4
  53. data/spec/spec_spec.rb +4 -11
  54. data/spec/suite1/spec/javascripts/invalid_coffee_spec.coffee +1 -0
  55. data/spec/suite1/spec/javascripts/spec_helper.coffee +1 -1
  56. data/spec/suite2/config/evergreen.rb +5 -0
  57. data/spec/suite2/public_html/foo.js +1 -0
  58. data/spec/suite2/spec/awesome_spec.js +12 -0
  59. data/spec/suite2/spec/failing_spec.js +5 -0
  60. data/spec/suite2/templates/foo.html +1 -0
  61. data/spec/suite_spec.rb +26 -0
  62. data/spec/template_spec.rb +3 -9
  63. metadata +52 -20
  64. data/lib/jasmine/lib/consolex.js +0 -28
@@ -1,26 +1,29 @@
1
+ require 'open3'
2
+
1
3
  module Evergreen
2
4
  class Spec
5
+ class CoffeeScriptError < StandardError; end
3
6
 
4
- def self.all(root)
5
- Dir.glob(File.join(root, 'spec/javascripts', '*_spec.{js,coffee}')).map do |path|
6
- new(root, File.basename(path))
7
- end
8
- end
9
-
10
- attr_reader :name, :root
7
+ attr_reader :name, :suite
11
8
 
12
- def initialize(root, name)
13
- @root = root
9
+ def initialize(suite, name)
10
+ @suite = suite
14
11
  @name = name
15
12
  end
16
13
 
14
+ def root
15
+ suite.root
16
+ end
17
+
17
18
  def full_path
18
- File.join(root, 'spec/javascripts', name)
19
+ File.join(root, Evergreen.spec_dir, name)
19
20
  end
20
21
 
21
22
  def read
22
23
  if full_path =~ /\.coffee$/
23
- %x(coffee -p #{full_path})
24
+ stdout, stderr = Open3.popen3("coffee -p #{full_path}")[1,2].map { |b| b.read }
25
+ raise CoffeeScriptError, stderr unless stderr.empty?
26
+ stdout
24
27
  else
25
28
  File.read(full_path)
26
29
  end
@@ -31,13 +34,22 @@ module Evergreen
31
34
  "/run/#{name}"
32
35
  end
33
36
 
37
+ def passed?
38
+ runner.passed?
39
+ end
40
+
41
+ def failure_messages
42
+ runner.failure_messages
43
+ end
44
+
34
45
  def exist?
35
46
  File.exist?(full_path)
36
47
  end
37
48
 
38
- def templates
39
- Evergreen::Template.all(root)
40
- end
49
+ protected
41
50
 
51
+ def runner
52
+ @runner ||= suite.runner.spec_runner(self)
53
+ end
42
54
  end
43
55
  end
@@ -0,0 +1,44 @@
1
+ module Evergreen
2
+ class Suite
3
+ attr_reader :root, :runner, :server, :driver, :application
4
+
5
+ def initialize(root)
6
+ @root = root
7
+
8
+ paths = [
9
+ File.expand_path("config/evergreen.rb", root),
10
+ File.expand_path(".evergreen", root),
11
+ "#{ENV["HOME"]}/.evergreen"
12
+ ]
13
+ paths.each { |path| load(path) if File.exist?(path) }
14
+
15
+ @runner = Runner.new(self)
16
+ @server = Server.new(self)
17
+ @application = Evergreen.application(self)
18
+ end
19
+
20
+ def run
21
+ runner.run
22
+ end
23
+
24
+ def serve
25
+ server.serve
26
+ end
27
+
28
+ def get_spec(name)
29
+ Spec.new(self, name)
30
+ end
31
+
32
+ def specs
33
+ Dir.glob(File.join(root, Evergreen.spec_dir, '*_spec.{js,coffee}')).map do |path|
34
+ Spec.new(self, File.basename(path))
35
+ end
36
+ end
37
+
38
+ def templates
39
+ Dir.glob(File.join(root, Evergreen.template_dir, '*')).map do |path|
40
+ Template.new(self, File.basename(path))
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ require 'evergreen'
2
+
3
+ Dir[File.join(File.dirname(__FILE__), '..', 'tasks', '*.rake')].each do |f|
4
+ load f
5
+ end
6
+
@@ -1,21 +1,18 @@
1
1
  module Evergreen
2
2
  class Template
3
+ attr_reader :name, :suite
3
4
 
4
- def self.all(root)
5
- Dir.glob(File.join(root, 'spec/javascripts/templates', '*')).map do |path|
6
- new(root, File.basename(path))
7
- end
5
+ def initialize(suite, name)
6
+ @suite = suite
7
+ @name = name
8
8
  end
9
9
 
10
- attr_reader :name, :root
11
-
12
- def initialize(root, name)
13
- @root = root
14
- @name = name
10
+ def root
11
+ suite.root
15
12
  end
16
13
 
17
14
  def full_path
18
- File.join(root, 'spec/javascripts/templates', name)
15
+ File.join(root, Evergreen.template_dir, name)
19
16
  end
20
17
 
21
18
  def read
@@ -1,3 +1,3 @@
1
1
  module Evergreen
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -5,6 +5,7 @@
5
5
  <title>Evergreen</title>
6
6
  <link rel="stylesheet" type="text/css" href="<%= url('/jasmine/jasmine.css') %>"/>
7
7
  <link rel="stylesheet" type="text/css" href="<%= url('/resources/evergreen.css') %>"/>
8
+ <meta http-equiv="content-type" content="text/html;charset=utf-8" />
8
9
  </head>
9
10
  <body>
10
11
  <%= yield %>
@@ -2,8 +2,8 @@
2
2
  <h1>Evergreen</h1>
3
3
 
4
4
  <ul id="specs">
5
- <% @specs.each do |spec| %>
5
+ <% @suite.specs.each do |spec| %>
6
6
  <li><a href="<%= url(spec.url) %>"><%= spec.name %></a></li>
7
7
  <% end %>
8
8
  </ul>
9
- </div>
9
+ </div>
@@ -1,25 +1,33 @@
1
1
  <script type="text/javascript" src="<%= url("/jasmine/jasmine.js") %>"></script>
2
2
  <script type="text/javascript" src="<%= url("/jasmine/jasmine-html.js") %>"></script>
3
3
  <script type="text/javascript" src="<%= url("/resources/evergreen.js") %>"></script>
4
- <% if @js_spec_helper.exist? %>
5
- <script type="text/javascript" src="<%= url("/spec/#{@js_spec_helper.name}") %>"></script>
6
- <% end %>
7
- <% if @coffee_spec_helper.exist? %>
8
- <script type="text/javascript" src="<%= url("/spec/#{@coffee_spec_helper.name}") %>"></script>
9
- <% end %>
10
- <script type="text/javascript" src="<%= url("/spec/#{@spec.name}") %>"></script>
4
+ <script type="text/javascript">
5
+ // <![CDATA[
6
+ <% begin %>
7
+ <%= @js_spec_helper.read.to_s + ";" if @js_spec_helper.exist? %>
8
+ <%= @coffee_spec_helper.read.to_s + ";" if @coffee_spec_helper.exist? %>
9
+ <%= @spec.read %>;
10
+ <% rescue StandardError => e %>
11
+ describe("failure", function() {
12
+ it("should not fail", function() {
13
+ throw(<%= "#{e.class}: #{e.message}".to_json %>);
14
+ });
15
+ });
16
+ <% end %>
17
+ // ]]>
18
+ </script>
11
19
 
12
20
  <div id="page">
13
21
  <h1>Evergreen</h1>
14
- <a class="back" href="<%= url("/list") %>">Back to list</a>
22
+ <a class="back" href="<%= url("/") %>">Back to list</a>
15
23
  </div>
16
24
 
17
25
  <div id="test"></div>
18
26
 
19
27
  <script type="text/javascript">
20
28
  (function() {
21
- Evergreen.driver = <%= @driver.to_json %>;
22
- <% @spec.templates.each do |template| %>
29
+ Evergreen.driver = <%= Evergreen.driver.to_json %>;
30
+ <% @suite.templates.each do |template| %>
23
31
  Evergreen.templates[<%= template.name.to_json %>] = <%= template.read.to_json %>;
24
32
  <% end %>
25
33
  var jasmineEnv = jasmine.getEnv();
@@ -0,0 +1,6 @@
1
+ source :gemcutter
2
+
3
+ gem "jekyll", "0.6.2"
4
+ gem "json_pure", "~>1.4.3"
5
+ gem "ragaskar-jsdoc_helper"
6
+ gem "rake", "0.8.7"
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Pivotal Labs
1
+ Copyright (c) 2008-2010 Pivotal Labs
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,463 +1,12 @@
1
- [Jasmine](http://pivotal.github.com/jasmine)
1
+ <a name="README">[Jasmine](http://pivotal.github.com/jasmine/)</a>
2
2
  =======
3
3
  **A JavaScript Testing Framework**
4
4
 
5
- Quick Start
6
- ----------
5
+ Want to use Jasmine in a project? Go HERE: [http://pivotal.github.com/jasmine/](http://pivotal.github.com/jasmine/)
7
6
 
8
- 1. Get the latest release from the [downloads page](http://github.com/pivotal/jasmine/downloads).
9
- 2. Open `SpecRunner.html` in your favorite browser.
7
+ Want to contribute to Jasmine? Read on...
10
8
 
11
- For running within a Ruby environment, including automated execution with Selenium, please use
12
- the [jasmine gem](http://github.com/pivotal/jasmine-gem).
13
-
14
- ### Which Release Should I Use?
15
-
16
- Please use the latest version unless you have a good reason not to. Some of this documentation may not be applicable to older versions. Please see [[Release Notes]](http://wiki.github.com/pivotal/jasmine/release-notes) for change information.
17
-
18
- Why Another JavaScript TDD/BDD Framework?
19
- -----------
20
-
21
- There are some great JavaScript testing frameworks out there already, so why did we write another?
22
-
23
- None of the existing frameworks quite worked the way we wanted. Many only work from within a browser. Most don't support testing asynchronous code like event callbacks. Some have syntax that's hard for JS developers or IDEs to understand.
24
-
25
- So we decided to start from scratch.
26
-
27
- Enter Jasmine
28
- ------------
29
-
30
- Jasmine is our dream JavaScript testing framework. It's heavily influenced by, and borrows the best parts of, ScrewUnit, JSSpec, [JSpec](http://github.com/visionmedia/jspec/tree/master), and of course RSpec.
31
-
32
- Jasmine was designed with a few principles in mind. We believe that a good JavaScript testing framework:
33
-
34
- * should not be tied to any browser, framework, platform, or host language.
35
- * should have idiomatic and unsurprising syntax.
36
- * should work anywhere JavaScript can run, including browsers, servers, phones, etc.
37
- * shouldn't intrude in your application's territory (e.g. by cluttering the global namespace).
38
- * should play well with IDEs (e.g. test code should pass static analysis).
39
-
40
- Some of our goals while writing Jasmine:
41
-
42
- * it should encourage good testing practices.
43
- * it should integrate easily with continuous build systems.
44
- * it should be simple to get started with.
45
-
46
- The result is Jasmine, and we love test-driving our code with it. Enjoy.
47
-
48
- How To
49
- ------
50
-
51
- There is a simple example of how to use Jasmine in the /example directory. But here's more information.
52
-
53
- ### Specs
54
-
55
- Each spec is, naturally, a JavaScript function. You tell Jasmine about this spec with a call to `it()` with a string and the function. The string is a description that will be helpful to you when reading a report.
56
-
57
- it('should be a test', function () {
58
- var foo = 0;
59
- foo++;
60
- });
61
-
62
- ### Expectations
63
-
64
- Within your spec you will want to express expectations about the behavior of your application code. These are made with the `expect()` function and expectation matchers, like this:
65
-
66
- it('should be a test', function () {
67
- var foo = 0; // set up the world
68
- foo++; // call your application code
69
-
70
- expect(foo).toEqual(1); // passes because foo == 1
71
- });
72
-
73
- Results of the expectations are logged for later for reporting.
74
-
75
- #### Expectation Matchers
76
-
77
- Jasmine has several built-in matchers. Here are a few:
78
-
79
- >`expect(x).toEqual(y);` compares objects or primitives `x` and `y` and passes if they are equivalent
80
- >
81
- >`expect(x).toMatch(pattern);` compares `x` to string or regular expression `pattern` and passes if they match
82
- >
83
- >`expect(x).toBeDefined();` passes if `x` is not `undefined`
84
- >
85
- >`expect(x).toBeNull();` passes if `x` is `null`
86
- >
87
- >`expect(x).toBeTruthy();` passes if `x` evaluates to true
88
- >
89
- >`expect(x).toBeFalsy();` passes if `x` evaluates to false
90
- >
91
- >`expect(x).toContain(y);` passes if array or string `x` contains `y`
92
-
93
- Every matcher's criteria can be inverted by prepending `.not`:
94
-
95
- >`expect(x).not.toEqual(y);` compares objects or primitives `x` and `y` and passes if they are *not* equivalent
96
-
97
- #### Writing New Matchers
98
-
99
- We've provided a small set of matchers that cover many common situations. However, we recommend that you write custom matchers when you want to assert a more specific sort of expectation. Custom matchers help to document the intent of your specs, and can help to remove code duplication in your specs.
100
-
101
- It's extremely easy to create new matchers for your app. A matcher function receives the actual value as `this.actual`, and zero or more arguments may be passed in the function call. The function should return `true` if the actual value passes the matcher's requirements, and `false` if it does not.
102
-
103
- Here's the definition of `toBeLessThan()`:
104
-
105
- toBeLessThan: function(expected) {
106
- return this.actual < expected;
107
- };
108
-
109
- To add the matcher to your suite, call `this.addMatchers()` from within a `before` or `it` block. Call it with an object mapping matcher name to function:
110
-
111
- beforeEach(function() {
112
- this.addMatchers({
113
- toBeVisible: function() { return this.actual.isVisible(); }
114
- });
115
- });
116
-
117
- ### Suites
118
-
119
- Specs are grouped in Suites. Suites are defined using the global `describe()` function:
120
-
121
- describe('One suite', function () {
122
- it('has a test', function () {
123
- ...
124
- });
125
-
126
- it('has another test', function () {
127
- ...
128
- });
129
- });
130
-
131
- The Suite name is so that reporting is more descriptive.
132
-
133
- Suites are executed in the order in which `describe()` calls are made, usually in the order in which their script files are included. Additionally, specs within a suite share a functional scope. So you may declare variables inside a describe block and they are accessible from within your specs. For example:
134
-
135
- describe('A suite with some variables', function () {
136
- var bar = 0
137
-
138
- it('has a test', function () {
139
- bar++;
140
- expect(bar).toEqual(1);
141
- });
142
-
143
- it('has another test', function () {
144
- bar++;
145
- expect(bar).toEqual(2);
146
- });
147
- });
148
-
149
- #### beforeEach
150
-
151
- A suite can have a beforeEach declaration. It takes a function that is run before each spec. For example:
152
-
153
- describe('some suite', function () {
154
-
155
- var suiteWideFoo;
156
-
157
- beforeEach(function () {
158
- suiteWideFoo = 1;
159
- });
160
-
161
- it('should equal bar', function () {
162
- expect(suiteWideFoo).toEqual(1);
163
- });
164
- });
165
-
166
- A runner can also have beforeEach declarations. Runner beforeEach functions are executed before every spec in all suites, and execute BEFORE suite beforeEach functions. For example:
167
-
168
- var runnerWideFoo = [];
169
-
170
- beforeEach(function () {
171
- runnerWideFoo.push('runner');
172
- });
173
-
174
- describe('some suite', function () {
175
-
176
- beforeEach(function () {
177
- runnerWideFoo.push('suite');
178
- });
179
-
180
- it('should equal bar', function () {
181
- expect(runnerWideFoo).toEqual(['runner', 'suite']);
182
- });
183
- });
184
-
185
- #### afterEach
186
-
187
- Similarly, there is an afterEach declaration. It takes a function that is run after each spec. For example:
188
-
189
- describe('some suite', function () {
190
-
191
- var suiteWideFoo;
192
- afterEach(function () {
193
- suiteWideFoo = 0;
194
- });
195
-
196
- it('should equal 1', function () {
197
- expect(suiteWideFoo).toEqual(1);
198
- });
199
-
200
- it('should equal 0 after', function () {
201
- expect(suiteWideFoo).toEqual(0);
202
- };
203
- });
204
-
205
- A runner can also have an afterEach declarations. Runner afterEach functions are executed after every spec in all suites, and execute AFTER suite afterEach functions. For example:
206
-
207
- var runnerWideFoo = [];
208
-
209
- afterEach(function () {
210
- runnerWideFoo.push('runner');
211
- });
212
-
213
- describe('some suite', function () {
214
-
215
- afterEach(function () {
216
- runnerWideFoo.push('suite');
217
- });
218
-
219
- it('should be empty', function () {
220
- expect(runnerWideFoo).toEqual([]);
221
- });
222
-
223
- it('should be populated after', function () {
224
- expect(runnerWideFoo).toEqual(['suite', 'runner']);
225
- };
226
- });
227
-
228
- ### Single-spec After functions
229
-
230
- A spec may ask Jasmine to execute some code after the spec has finished running; the code will run whether the spec finishes successfully or not. Multiple after functions may be given.
231
-
232
- describe('some suite', function () {
233
- it(function () {
234
- var originalTitle = window.title;
235
- this.after(function() { window.title = originalTitle; });
236
- MyWindow.setTitle("new value");
237
- expect(window.title).toEqual("new value");
238
- });
239
-
240
-
241
- ### Nested Describes
242
- Jasmine supports nested describes. An example:
243
-
244
- describe('some suite', function () {
245
-
246
- var suiteWideFoo;
247
-
248
- beforeEach(function () {
249
- suiteWideFoo = 0;
250
- });
251
-
252
- describe('some nested suite', function() {
253
- var nestedSuiteBar;
254
- beforeEach(function() {
255
- nestedSuiteBar=1;
256
- });
257
-
258
- it('nested expectation', function () {
259
- expect(suiteWideFoo).toEqual(0);
260
- expect(nestedSuiteBar).toEqual(1);
261
- });
262
-
263
- });
264
-
265
- it('top-level describe', function () {
266
- expect(suiteWideFoo).toEqual(0);
267
- expect(nestedSuiteBar).toEqual(undefined);
268
- });
269
- });
270
-
271
- ### Spies
272
-
273
- Jasmine integrates 'spies' that permit many spying, mocking, and faking behaviors.
274
-
275
- Here are a few examples:
276
-
277
- var Klass = function () {
278
- };
279
-
280
- var Klass.prototype.method = function (arg) {
281
- return arg;
282
- };
283
-
284
- var Klass.prototype.methodWithCallback = function (callback) {
285
- return callback('foo');
286
- };
287
-
288
- ...
289
-
290
- it('should spy on Klass#method') {
291
- spyOn(Klass, 'method');
292
- Klass.method('foo argument');
293
-
294
- expect(Klass.method).toHaveBeenCalledWith('foo argument');
295
- });
296
-
297
- it('should spy on Klass#methodWithCallback') {
298
- var callback = Jasmine.createSpy();
299
- Klass.methodWithCallback(callback);
300
-
301
- expect(callback).toHaveBeenCalledWith('foo');
302
- });
303
-
304
-
305
- Spies can be very useful for testing AJAX or other asynchronous behaviors that take callbacks by faking the method firing an async call.
306
-
307
- var Klass = function () {
308
- };
309
-
310
- var Klass.prototype.asyncMethod = function (callback) {
311
- someAsyncCall(callback);
312
- };
313
-
314
- ...
315
-
316
- it('should test async call') {
317
- spyOn(Klass, 'asyncMethod');
318
- var callback = Jasmine.createSpy();
319
-
320
- Klass.asyncMethod(callback);
321
- expect(callback).not.toHaveBeenCalled();
322
-
323
- var someResponseData = 'foo';
324
- Klass.asyncMethod.mostRecentCall.args[0](someResponseData);
325
- expect(callback).toHaveBeenCalledWith(someResponseData);
326
-
327
- });
328
-
329
- There are spy-specfic matchers that are very handy.
330
-
331
- `expect(x).toHaveBeenCalled()` passes if `x` is a spy and was called
332
-
333
- `expect(x).toHaveBeenCalledWith(arguments)` passes if `x` is a spy and was called with the specified arguments
334
-
335
- `expect(x).not.toHaveBeenCalled()` passes if `x` is a spy and was not called
336
-
337
- `expect(x).not.toHaveBeenCalledWith(arguments)` passes if `x` is a spy and was not called with the specified arguments
338
-
339
- The old matchers `wasCalled`, `wasNotCalled`, `wasCalledWith`, and `wasNotCalledWith` have been deprecated and will be removed in a future release. Please change your specs to use `toHaveBeenCalled`, `not.toHaveBeenCalled`, `toHaveBeenCalledWith`, and `not.toHaveBeenCalledWith` respectively.
340
-
341
- Spies can be trained to respond in a variety of ways when invoked:
342
-
343
- `spyOn(x, 'method').andCallThrough()`: spies on AND calls the original function spied on
344
-
345
- `spyOn(x, 'method').andReturn(arguments)`: returns passed arguments when spy is called
346
-
347
- `spyOn(x, 'method').andThrow(exception)`: throws passed exception when spy is called
348
-
349
- `spyOn(x, 'method').andCallFake(function)`: calls passed function when spy is called
350
-
351
- Spies have some useful properties:
352
-
353
- `callCount`: returns number of times spy was called
354
-
355
- `mostRecentCall.args`: returns argument array from last call to spy.
356
-
357
- `argsForCall[i]` returns arguments array for call `i` to spy.
358
-
359
- Spies are automatically removed after each spec. They may be set in the beforeEach function.
360
-
361
- ### Disabling Tests & Suites
362
-
363
- Specs may be disabled by calling `xit()` instead of `it()`. Suites may be disabled by calling `xdescribe()` instead of `describe()`. A simple find/replace in your editor of choice will allow you to run a subset of your specs.
364
-
365
- ### Asynchronous Specs
366
-
367
- You may be thinking, "That's all very nice, but what's this about asynchronous tests?"
368
-
369
- Well, say you need to make a call that is asynchronous - an AJAX API, event callback, or some other JavaScript library. That is, the call returns immediately, yet you want to make expectations 'at some point in the future' after some magic happens in the background.
370
-
371
- Jasmine allows you to do this with `runs()` and `waits()` blocks.
372
-
373
- `runs()` blocks by themselves simply run as if they were called directly. The following snippets of code should provide similar results:
374
-
375
- it('should be a test', function () {
376
- var foo = 0
377
- foo++;
378
-
379
- expect(foo).toEqual(1);
380
- });
381
-
382
- and
383
-
384
- it('should be a test', function () {
385
- runs( function () {
386
- var foo = 0
387
- foo++;
388
-
389
- expect(foo).toEqual(1);
390
- });
391
- });
392
-
393
- multiple `runs()` blocks in a spec will run serially. For example,
394
-
395
- it('should be a test', function () {
396
- runs( function () {
397
- var foo = 0
398
- foo++;
399
-
400
- expect(foo).toEqual(1);
401
- });
402
- runs( function () {
403
- var bar = 0
404
- bar++;
405
-
406
- expect(bar).toEqual(1);
407
- });
408
- });
409
-
410
- `runs()` blocks share functional scope -- `this` properties will be common to all blocks, but declared `var`'s will not!
411
-
412
- it('should be a test', function () {
413
- runs( function () {
414
- this.foo = 0
415
- this.foo++;
416
- var bar = 0;
417
- bar++;
418
-
419
- expect(this.foo).toEqual(1);
420
- expect(bar).toEqual(1);
421
- });
422
- runs( function () {
423
- this.foo++;
424
- var bar = 0
425
- bar++;
426
-
427
- expect(foo).toEqual(2);
428
- expect(bar).toEqual(1);
429
- });
430
- });
431
-
432
- `runs()` blocks exist so you can test asynchronous processes. The function `waits()` works with `runs()` to provide a naive
433
- timeout before the next block is run. You supply a time to wait before the next `runs()` function is executed. For example:
434
-
435
- it('should be a test', function () {
436
- runs(function () {
437
- this.foo = 0;
438
- var that = this;
439
- setTimeout(function () {
440
- that.foo++;
441
- }, 250);
442
- });
443
-
444
- runs(function () {
445
- this.expects(this.foo).toEqual(0);
446
- });
447
-
448
- waits(500);
449
-
450
- runs(function () {
451
- this.expects(this.foo).toEqual(1);
452
- });
453
- });
454
-
455
- What's happening here?
456
-
457
- * The first call to `runs()` sets call for 1/4 of a second in the future that increments `this.foo`.
458
- * The second `runs()` is executed immediately and then verifies that `this.foo` was indeed initialized to zero in the previous `runs()`.
459
- * Then we wait for half a second.
460
- * Then the last call to `runs()` expects that `this.foo` was incremented by the `setTimeout`.
9
+ <i>(More developer docs to come...)</i>
461
10
 
462
11
  ## Support
463
12
  We now have a Google Group for support & discussion.
@@ -476,7 +25,4 @@ We now have a Google Group for support & discussion.
476
25
  ## Developers
477
26
  We welcome your contributions! Jasmine is currently maintained by Davis Frank ([infews](http://github.com/infews)), Rajan Agaskar ([ragaskar](http://github.com/ragaskar)), and Christian Williams ([Xian](http://github.com/Xian)). You can help us by removing all other recipients from your pull request.
478
27
 
479
- ## Acknowledgments
480
- * A big shout out to the various JavaScript test framework authors, especially TJ for [JSpec](http://github.com/visionmedia/jspec/tree/master) - we played with it a bit before deciding that we really needed to roll our own.
481
- * Thanks to Pivot [Jessica Miller](http://www.jessicamillerworks.com/) for our fancy pass/fail/pending icons
482
- * Huge contributions have been made by [Adam Abrons](mailto:adam@pivotallabs.com), [Lee Byrd](mailto:lee@pivotallabs.com), [Erik Hanson](mailto:erik@pivotallabs.com), [Carl Jackson](mailto:carl@pivotallabs.com), and many other Pivots.
28
+ Copyright (c) 2008-2010 Pivotal Labs. This software is licensed under the MIT License.