rspec-given 2.3.0 → 2.3.1.beta.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # rspec-given
2
2
 
3
- Covering rspec-given, version 2.3.0.
3
+ Covering rspec-given, version 2.3.1.beta.1.
4
4
 
5
5
  rspec-given is an RSpec extension to allow Given/When/Then notation in
6
6
  RSpec specifications. It is a natural extension of the experimental
@@ -17,7 +17,7 @@ RSpec specifications.
17
17
 
18
18
  ## Status
19
19
 
20
- _rspec-given_ is ready for production use.
20
+ rspec-given is ready for production use.
21
21
 
22
22
  ## Example
23
23
 
@@ -118,7 +118,7 @@ for side effects. Since there is no accessor, the code block is
118
118
  executed immediately (i.e. no lazy evaluation).
119
119
 
120
120
  The preconditions are run in order of definition. Nested contexts
121
- will inherit the preconditions from the enclosing context, with out
121
+ will inherit the preconditions from the enclosing context, with outer
122
122
  preconditions running before inner preconditions.
123
123
 
124
124
  #### Given examples:
@@ -127,8 +127,8 @@ preconditions running before inner preconditions.
127
127
  Given(:stack) { Stack.new }
128
128
  ```
129
129
 
130
- The block for the given clause is lazily run if 'stack' is ever
131
- referenced in the test and the value of the block is bound to 'stack'.
130
+ The block for the given clause is lazily run and its value bound to
131
+ 'stack' if 'stack' is ever referenced in the test.
132
132
  The first reference to 'stack' in the specification will cause the
133
133
  code block to execute. Futher references to 'stack' will reuse the
134
134
  previously generated value.
@@ -259,7 +259,7 @@ be empty. If it is not empty, the test will fail.
259
259
 
260
260
  The _And_ clause is similar to _Then_, but does not form its own RSpec
261
261
  example. This means that _And_ clauses reuse the setup from a sibling
262
- _Then_ clause. Using a single _Then_ an multiple _And_ clauses in an
262
+ _Then_ clause. Using a single _Then_ and multiple _And_ clauses in an
263
263
  example group means the setup for that group is run only once (for the
264
264
  _Then_ clause) and reused for all the _And_ clauses. This can be a
265
265
  significant speed savings where the setup for an example group is
@@ -267,30 +267,30 @@ expensive.
267
267
 
268
268
  Some things to keep in mind about _And_ clauses:
269
269
 
270
- 1. There must be at least one _Then_ in the example group and it must
271
- be declared before the _And_ clauses. Forgetting the _Then_ clause
272
- is an error.
270
+ * There must be at least one _Then_ in the example group and it must
271
+ be declared before the _And_ clauses. Forgetting the _Then_ clause
272
+ is an error.
273
273
 
274
- 1. The code in the _And_ clause is run immediately after the first
275
- (executed) _Then_ of an example group.
274
+ * The code in the _And_ clause is run immediately after the first
275
+ (executed) _Then_ of an example group.
276
276
 
277
- 1. And assertion failures in a _Then_ clause or a _And_ clause will
278
- cause all the subsequent _And_ clauses to be skipped.
277
+ * An assertion failure in a _Then_ clause or an _And_ clause will
278
+ cause all the subsequent _And_ clauses to be skipped.
279
279
 
280
- 1. Since _And_ clauses do not form their own RSpec examples, they are
281
- not represented in the formatted output of RSpec. That means _And_
282
- clauses do not produce dots in the Progress format, nor do they
283
- appear in the documentation, html or textmate formats (options
284
- -fhtml, -fdoc, or -ftextmate).
280
+ * Since _And_ clauses do not form their own RSpec examples, they are
281
+ not represented in the formatted output of RSpec. That means _And_
282
+ clauses do not produce dots in the Progress format, nor do they
283
+ appear in the documentation, html or textmate formats (options
284
+ -fhtml, -fdoc, or -ftextmate).
285
285
 
286
- 1. Like _Then_ clauses, _And_ clauses must be idempotent. That means
287
- they should not execute any code that changes global program state.
288
- (See the section on the _Then_ clause).
286
+ * Like _Then_ clauses, _And_ clauses must be idempotent. That means
287
+ they should not execute any code that changes global program state.
288
+ (See the section on the _Then_ clause).
289
289
 
290
290
  The choice to use an _And_ clause is primarily a speed consideration.
291
291
  If an example group has expensive setup and there are a lot of _Then_
292
292
  clauses, then choosing to make some of the _Then_ clauses into _And_
293
- clause will speed up the spec. Otherwise it is probably better to
293
+ clauses will speed up the spec. Otherwise it is probably better to
294
294
  stick with _Then_ clauses.
295
295
 
296
296
  #### Then/And examples:
@@ -326,18 +326,19 @@ used in contexts that define that accessor.
326
326
 
327
327
  Notes:
328
328
 
329
- 1. Since Invariants do not form their own RSpec example, they are not
330
- represented in the RSpec formatted output (e.g. the '--format html'
331
- option).
329
+ * Since Invariants do not form their own RSpec example, they are not
330
+ represented in the RSpec formatted output (e.g. the '--format html'
331
+ option).
332
332
 
333
333
  ## Execution Ordering
334
334
 
335
335
  When running the test for a specific _Then_ clause, the following will
336
336
  be true:
337
337
 
338
- * The _Given_ clauses will be run in the order that they are
338
+ * The non-lazy _Given_ clauses will be run in the order that they are
339
339
  specified, from the outermost scope to the innermost scope
340
- containing the _Then_.
340
+ containing the _Then_. (The lazy _Given_ clauses will be run upon
341
+ demand).
341
342
 
342
343
  * All of the _Given_ clauses in all of the relevant scopes will run
343
344
  before the first (outermost) _When_ clause in those same scopes.
@@ -347,21 +348,22 @@ be true:
347
348
 
348
349
  * _When_ clauses and RSpec _before_ blocks will be executed in the
349
350
  order that they are specified, from the outermost block to the
350
- innermost block. This makes _before_ blocks an excellent choice
351
- when writing narrative tests to specify actions that happen between
352
- the "whens" of a narrative.
351
+ innermost block. This makes _before_ blocks an excellent choice when
352
+ writing narrative tests to specify actions that happen between the
353
+ "whens" of a narrative-style test.
353
354
 
354
355
  Note that the ordering between _Given_ clauses and _before_ blocks are
355
- a not strongly specified. Hoisting a _When_ clause out of an inner
356
- scope to an outer scope may change the ordering of when the _Given_
357
- clause runs in relation to a _before_ block (the hoisting will cause
358
- the givens to possibly run earlier). Because of this, do not split
359
- order dependent code between _Given_ clauses and _before_ blocks.
356
+ not strongly specified. Hoisting a _When_ clause out of an inner scope
357
+ to an outer scope may change the order of execution between related
358
+ _Given_ clauses and any _before_ blocks (hoisting the _When_ clause
359
+ might cause the related _Given_ clauses to possibly run earlier).
360
+ Because of this, do not split order dependent code between _Given_
361
+ clauses and _before_ blocks.
360
362
 
361
363
  ## Natural Assertions
362
364
 
363
- **NOTE:** <em>Natural assertions are an experimental feature of
364
- RSpec/Given. They are currently disabled by default. They can be
365
+ **NOTE:** <em>Natural assertions are currently an experimental feature
366
+ of RSpec/Given. They are currently disabled by default, but can be
365
367
  enabled by a simple configuration option (see "use_natural_assertions"
366
368
  below).</em>
367
369
 
@@ -380,6 +382,10 @@ natural assertions:
380
382
  Natural assertions must be enabled, either globally or on a per
381
383
  context basis, to be recognized.
382
384
 
385
+ Here's a heads up: If you use natural assertions, but fail to enable
386
+ them, all your specs will mysteriously pass. This is why the **red**
387
+ part of _Red/Green/Refactor_ is so important.
388
+
383
389
  ### Failure Messages with Natural Assertions
384
390
 
385
391
  Since natural assertions do not depend upon matchers, you don't get
@@ -418,26 +424,26 @@ broken down into subexpressions and values for each subexpression.
418
424
  This gives you all the information you need to figure out exactly what
419
425
  part of the expression is causing the failure.
420
426
 
421
- Natural expressions will give additional information (e.g. "expected:
427
+ Natural assertions will give additional information (e.g. "expected:
422
428
  3 to equal: 2") for top level expressions involving any of the
423
429
  comparison operators (==, !=, <, <=, >, >=) or matching operators (=~,
424
430
  !~).
425
431
 
426
432
  ### Caveats on Natural Assertions
427
433
 
428
- Keep the following in mind when using Natural Assertions.
434
+ Keep the following in mind when using natural assertions.
429
435
 
430
436
  * Only a single expression/assertion per _Then_. The single expression
431
437
  of the _Then_ block will be considered when determining pass/fail
432
438
  for the assertion. If you _want_ to express a complex condition for
433
439
  the _Then_, you need to use ||, && or some other logical operation
434
440
  to join the conditions into a single expression (and the failure
435
- message will breakdown the values for each part).
441
+ message will break down the values for each part).
436
442
 
437
443
  * Then clauses need be **idempotent**. This is true in general, but it
438
- is particularly important for Natural assertions to obey this
444
+ is particularly important for natural assertions to obey this
439
445
  restriction. This means that assertions in a Then clause should not
440
- change anything. Since the natural assertion error message contains
446
+ change anything. Since the Natural Assertion error message contains
441
447
  the values of all the subexpressions, the expression and its
442
448
  subexpressions will be evaluated multiple times. If the Then clause
443
449
  is not idempotent, you will get changing answers as the
@@ -458,8 +464,8 @@ initially return 1). But when the error message is formated, the
458
464
  system reports that <code>ary.delete(1)</code> returns nil. You will
459
465
  scratch your head over that for a good while.
460
466
 
461
- Instead, move the state changing code into a When block, then just
462
- assert what you need about the result from the when block. Something
467
+ Instead, move the state changing code into a _When(:result)_ block, then
468
+ assert what you need to about :result. Something
463
469
  like this is good:
464
470
 
465
471
  ```ruby
@@ -510,7 +516,7 @@ when an assertion is not met. Natural assertions provide
510
516
  self-explanatory failure messages for most things without requiring
511
517
  any special matchers from the programmer.
512
518
 
513
- In the rare case that some extra information would be hepful, it is
519
+ In the rare case that some extra information would be helpful, it is
514
520
  useful to create special objects that respond to the == operator.
515
521
 
516
522
  #### Asserting Nearly Equal
@@ -520,7 +526,7 @@ exactly equal, therefore it is useful to assert that two floating
520
526
  point numbers are nearly equal.
521
527
 
522
528
  For example, the following asserts that the square root of 10 is about
523
- 3.1523 with an accuracy of 0.1 percent.
529
+ 3.1523 with an accuracy of 1 percent.
524
530
 
525
531
  ```ruby
526
532
  Then { Math.sqrt(10) == about(3.1623).percent(1) }
@@ -562,7 +568,8 @@ For example, the following two Then clauses are equivalent:
562
568
 
563
569
  ### Processing Natural Assertions
564
570
 
565
- When natural assertions are enabled, they are only used if:
571
+ When natural assertions are enabled, they are only used if all of the
572
+ following are true:
566
573
 
567
574
  1. The block does not throw an RSpec assertion failure (or any other
568
575
  exception for that matter).
@@ -588,8 +595,8 @@ Conover](http://rubygems.org/profiles/sconoversf).
588
595
  Just require 'rspec/given' in the spec helper of your project and it
589
596
  is ready to go.
590
597
 
591
- If the RSpec format option document, html or textmate are chosen,
592
- RSpec/Given will automatically add addition source code information to
598
+ If the RSpec format option document, html or textmate is chosen,
599
+ RSpec/Given will automatically add additional source code information to
593
600
  the examples to produce better looking output. If you don't care about
594
601
  the pretty output and wish to disable source code caching
595
602
  unconditionally, then add the following line to your spec helper file:
data/Rakefile CHANGED
@@ -93,6 +93,13 @@ task :verify_rspec2 do
93
93
  end
94
94
  end
95
95
 
96
+ task :load_check do
97
+ SRC_FILES = FileList['lib/rspec/given/*.rb'].exclude(/rspec1/)
98
+ SRC_FILES.each do |fn|
99
+ sh %{ruby -Ilib -e 'load "#{fn}"'}
100
+ end
101
+ end
102
+
96
103
  # Formatting the README ----------------------------------------------
97
104
 
98
105
  directory 'html'
@@ -1,3 +1,3 @@
1
1
  $LOAD_PATH << './examples/stack'
2
2
 
3
- require 'rspec/given'
3
+ require 'spec_helper'
@@ -3,7 +3,7 @@ require 'example_helper'
3
3
 
4
4
  describe "Then" do
5
5
  context "empty thens with natural assertions" do
6
- use_natural_assertions
6
+ use_natural_assertions_if_supported
7
7
  Then { }
8
8
  end
9
9
  end
@@ -206,6 +206,8 @@ module RSpec
206
206
  begin
207
207
  _rg_establish_givens
208
208
  instance_eval(&block)
209
+ rescue RSpec::Core::Pending::PendingDeclaredInExample => ex
210
+ raise
209
211
  rescue Exception => ex
210
212
  Failure.new(ex)
211
213
  end
@@ -252,6 +254,7 @@ module RSpec
252
254
  end
253
255
 
254
256
  def use_natural_assertions(enabled=true)
257
+ RSpec::Given.ok_to_use_natural_assertions(enabled)
255
258
  _rgc_context_info[:natural_assertions_enabled] = enabled
256
259
  end
257
260
  end
@@ -1,3 +1,5 @@
1
+ require 'rspec'
2
+
1
3
  module RSpec
2
4
  module Given
3
5
  module HaveFailed
@@ -1,5 +1,7 @@
1
1
  module RSpec
2
2
  module Given
3
+ NATURAL_ASSERTIONS_SUPPORTED = ! defined?(JRUBY_VERSION)
4
+
3
5
  def self.matcher_called
4
6
  @matcher_called
5
7
  end
@@ -22,9 +24,16 @@ module RSpec
22
24
  end
23
25
 
24
26
  def self.use_natural_assertions(enabled=true)
27
+ ok_to_use_natural_assertions(enabled)
25
28
  @natural_assertions_enabled = enabled
26
29
  end
27
30
 
31
+ def self.ok_to_use_natural_assertions(enabled)
32
+ if enabled && ! NATURAL_ASSERTIONS_SUPPORTED
33
+ fail ArgumentError, "Natural Assertions are disabled for JRuby"
34
+ end
35
+ end
36
+
28
37
  def self.natural_assertions_enabled?
29
38
  @natural_assertions_enabled
30
39
  end
@@ -1,4 +1,5 @@
1
1
  require 'rspec'
2
+ require 'rspec/given/module_methods'
2
3
 
3
4
  # Monkey patch RSpec to detect matchers used in expectations.
4
5
 
@@ -1,6 +1,11 @@
1
- require 'ripper'
2
- require 'sorcerer'
3
- require 'rspec/given/monkey'
1
+ require 'rspec'
2
+ require 'rspec/given/module_methods'
3
+
4
+ if RSpec::Given::NATURAL_ASSERTIONS_SUPPORTED
5
+ require 'ripper'
6
+ require 'sorcerer'
7
+ require 'rspec/given/monkey'
8
+ end
4
9
 
5
10
  module RSpec
6
11
  module Given
@@ -160,7 +165,7 @@ module RSpec
160
165
  width = suggest_width(pairs)
161
166
  pairs.each do |x, v|
162
167
  fmt = (v.size > WRAP_WIDTH) ?
163
- " %-#{width+2}s\n #{' '*(width+2)} <- %s\n" :
168
+ " %-#{width+2}s\n #{' '*(width+2)} <- %s\n" :
164
169
  " %-#{width+2}s <- %s\n"
165
170
  @output << sprintf(fmt, v, x)
166
171
  end
@@ -2,7 +2,8 @@ require 'rspec/given/version'
2
2
  require 'rspec/given/extensions'
3
3
 
4
4
  class Spec::ExampleGroup
5
- extend RSpec::Given::Extensions
5
+ extend RSpec::Given::ClassExtensions
6
+ include RSpec::Given::InstanceExtensions
6
7
 
7
8
  class << self
8
9
  alias Then specify
@@ -3,7 +3,8 @@ module RSpec
3
3
  VERSION_NUMBERS = [
4
4
  VERSION_MAJOR = 2,
5
5
  VERSION_MINOR = 3,
6
- VERSION_BUILD = 0,
6
+ VERSION_BUILD = 1,
7
+ 'beta', 1
7
8
  ]
8
9
  VERSION = VERSION_NUMBERS.join(".")
9
10
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-given
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
5
- prerelease:
4
+ version: 2.3.1.beta.1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jim Weirich
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '2.11'
30
- - !ruby/object:Gem::Dependency
31
- name: sorcerer
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: 0.3.7
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: 0.3.7
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: bluecloth
48
32
  requirement: !ruby/object:Gem::Requirement
@@ -154,9 +138,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
138
  required_rubygems_version: !ruby/object:Gem::Requirement
155
139
  none: false
156
140
  requirements:
157
- - - ! '>='
141
+ - - ! '>'
158
142
  - !ruby/object:Gem::Version
159
- version: '0'
143
+ version: 1.3.1
160
144
  requirements: []
161
145
  rubyforge_project: given
162
146
  rubygems_version: 1.8.24