rspec-given 2.3.0.beta.2 → 2.3.0.beta.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # rspec-given
2
2
 
3
- Covering rspec-given, version 2.3.0.beta.2.
3
+ Covering rspec-given, version 2.3.0.beta.3.
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
data/lib/rspec/given.rb CHANGED
@@ -15,4 +15,5 @@ else
15
15
  require 'rspec/given/core'
16
16
  require 'rspec/given/have_failed'
17
17
  require 'rspec/given/configure'
18
+ require 'rspec/given/monkey'
18
19
  end
@@ -47,7 +47,7 @@ module RSpec
47
47
  return false unless nassert.has_content?
48
48
  use_na = _rg_na_configured?
49
49
  return true if use_na == :always
50
- return false if nassert.using_rspec_assertion?
50
+ return false if !RSpec::Given::MONKEY && nassert.using_rspec_assertion?
51
51
  use_na
52
52
  end
53
53
 
@@ -101,8 +101,9 @@ module RSpec
101
101
 
102
102
  # Evaluate a Then, And, or Invariant assertion.
103
103
  def _rg_evaluate(block) # :nodoc:
104
+ RSpec::Given.matcher_called = false
104
105
  passed = instance_eval(&block)
105
- if ! passed && _rg_na_configured?
106
+ if ! passed && _rg_na_configured? && ! RSpec::Given.matcher_called
106
107
  nassert = NaturalAssertion.new(block, binding, self.class._rgc_lines)
107
108
  ::RSpec::Expectations.fail_with nassert.message if _rg_need_na_message?(nassert)
108
109
  end
@@ -1,5 +1,13 @@
1
1
  module RSpec
2
2
  module Given
3
+ def self.matcher_called
4
+ @matcher_called
5
+ end
6
+
7
+ def self.matcher_called=(value)
8
+ @matcher_called = value
9
+ end
10
+
3
11
  def self.source_caching_disabled
4
12
  @_rg_source_caching_disabled
5
13
  end
@@ -0,0 +1,40 @@
1
+ require 'rspec'
2
+
3
+ # Monkey patch RSpec to detect matchers used in expectations.
4
+
5
+ unless defined?(RSpec::Given::MONKEY)
6
+
7
+ if defined?(RSpec::Expectations::PositiveExpectationHandler) &&
8
+ defined?(RSpec::Expectations::NegativeExpectationHandler)
9
+
10
+ RSpec::Given::MONKEY = true
11
+
12
+ module RSpec
13
+ module Expectations
14
+ class PositiveExpectationHandler
15
+ class << self
16
+ alias _rg_rspec_original_handle_matcher handle_matcher
17
+ def handle_matcher(actual, matcher, message=nil, &block)
18
+ RSpec::Given.matcher_called = true
19
+ _rg_rspec_original_handle_matcher(actual, matcher, message, &block)
20
+ end
21
+ end
22
+ end
23
+
24
+ class NegativeExpectationHandler
25
+ class << self
26
+ alias _rg_rspec_original_handle_matcher handle_matcher
27
+ def handle_matcher(actual, matcher, message=nil, &block)
28
+ RSpec::Given.matcher_called = true
29
+ _rg_rspec_original_handle_matcher(actual, matcher, message, &block)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ else
37
+ RSpec::Given::MONKEY = false
38
+ end
39
+
40
+ end
@@ -1,5 +1,6 @@
1
1
  require 'ripper'
2
2
  require 'sorcerer'
3
+ require 'rspec/given/monkey'
3
4
 
4
5
  module RSpec
5
6
  module Given
@@ -97,7 +98,7 @@ module RSpec
97
98
  end
98
99
 
99
100
  def source
100
- @line_extractor.line(@code_file, @code_line)
101
+ @source ||= @line_extractor.line(@code_file, @code_line)
101
102
  end
102
103
 
103
104
  def set_file_and_line
@@ -5,7 +5,7 @@ module RSpec
5
5
  VERSION_MINOR = 3,
6
6
  VERSION_BUILD = 0,
7
7
  'beta',
8
- VERSION_BETA = 2,
8
+ VERSION_BETA = 3,
9
9
  ]
10
10
  VERSION = VERSION_NUMBERS.join(".")
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-given
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0.beta.2
4
+ version: 2.3.0.beta.3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000 Z
12
+ date: 2013-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>'
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.2.8
21
+ version: '2.11'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>'
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.2.8
29
+ version: '2.11'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: sorcerer
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +115,7 @@ files:
115
115
  - lib/rspec/given/have_failed.rb
116
116
  - lib/rspec/given/line_extractor.rb
117
117
  - lib/rspec/given/module_methods.rb
118
+ - lib/rspec/given/monkey.rb
118
119
  - lib/rspec/given/natural_assertion.rb
119
120
  - lib/rspec/given/rspec1_given.rb
120
121
  - lib/rspec/given/version.rb