safe_spec 0.1

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.
@@ -0,0 +1,9 @@
1
+ require 'safe_spec'
2
+
3
+ module RSpec
4
+ module Mocks
5
+ module Methods
6
+ include SafeSpec
7
+ end
8
+ end
9
+ end
data/lib/safe_spec.rb ADDED
@@ -0,0 +1,19 @@
1
+ module SafeSpec
2
+ def assert_valid_methods!(sym_or_hash)
3
+ methods_to_stub = Hash === sym_or_hash ? sym_or_hash.keys : [sym_or_hash]
4
+ methods_to_stub.each do |meth|
5
+ raise NoMethodError, "#{meth} was not found in the method list on #{self}" unless self.respond_to?(meth)
6
+ end
7
+ end
8
+
9
+ def method_missing(meth, *args, &block)
10
+ method_regex = /^safe_(.+)/
11
+ if meth.to_s =~ method_regex
12
+ assert_valid_methods!(args.first)
13
+ delegate_to = method_regex.match(meth.to_s)[1]
14
+ self.send(delegate_to, *args, &block)
15
+ else
16
+ super
17
+ end
18
+ end
19
+ end
data/safe_spec.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'safe_spec'
3
+ s.version = '0.1'
4
+ s.date = '2011-10-25'
5
+
6
+ s.summary = "Safer Rspec testing"
7
+ s.description = "Raises NoMethodError if object does not respond to method when stubbing or setting expectations"
8
+
9
+ s.authors = ["Jacob Richardson"]
10
+ s.email = 'jacob.ninja.dev@gmail.com'
11
+
12
+ s.require_paths = %w[lib]
13
+
14
+ s.add_dependency('rspec')
15
+
16
+ # = MANIFEST =
17
+ s.files = %w[
18
+ safe_spec.gemspec
19
+ lib/safe_spec.rb
20
+ lib/rspec_safe_spec_monkeypatch.rb
21
+ ]
22
+ # = MANIFEST =
23
+
24
+ s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
25
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: safe_spec
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jacob Richardson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2160142480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2160142480
25
+ description: Raises NoMethodError if object does not respond to method when stubbing
26
+ or setting expectations
27
+ email: jacob.ninja.dev@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - safe_spec.gemspec
33
+ - lib/safe_spec.rb
34
+ - lib/rspec_safe_spec_monkeypatch.rb
35
+ homepage:
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.10
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Safer Rspec testing
59
+ test_files: []