rspec-deep-matchers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ .rvmrc
6
+ *.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in deep-matchers.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2, :cli => "--color --format nested" do
5
+ watch(%r{^spec/.+_spec\.rb})
6
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1 @@
1
+ require "rspec/matchers/deep_eql"
@@ -0,0 +1 @@
1
+ require "rspec/matchers/deep_eql.rb"
@@ -0,0 +1,45 @@
1
+ module RSpec
2
+ module Matchers
3
+
4
+ def deep_eql(expected)
5
+ DeepEql.new(expected)
6
+ end
7
+
8
+ class DeepEql
9
+
10
+ def initialize(expectation)
11
+ @expectation = expectation
12
+ end
13
+
14
+ def matches?(target)
15
+ result = true
16
+ @target = target
17
+ case @expectation
18
+ when Hash
19
+ result &&= @target.is_a?(Hash) && @target.keys.count == @expectation.keys.count
20
+ @expectation.keys.each do |key|
21
+ result &&= @target.has_key?(key) &&
22
+ DeepEql.new(@expectation[key]).matches?(@target[key])
23
+ end
24
+ when Array
25
+ result &&= @target.is_a?(Array) && @target.count == @expectation.count
26
+ @expectation.each_index do |index|
27
+ result &&= DeepEql.new(@expectation[index]).matches?(@target[index])
28
+ end
29
+ else
30
+ result &&= @target == @expectation
31
+ end
32
+ result
33
+ end
34
+
35
+ def failure_message_for_should
36
+ "expected #{@target.inspect} to be deep_eql with #{@expectation.inspect}"
37
+ end
38
+
39
+ def failure_message_for_should_not
40
+ "expected #{@target.inspect} not to be in deep_eql with #{@expectation.inspect}"
41
+ end
42
+ end
43
+
44
+ end
45
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,7 @@
1
+ module RSpec
2
+ module Deep
3
+ module Matchers
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rspec-deep-matchers"
7
+ s.version = RSpec::Deep::Matchers::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["vitalish"]
10
+ s.email = ["vitalish@4life.com.ua"]
11
+ s.homepage = "http://github.com/vitalish/rspec-deep-matchers"
12
+ s.summary = %q{Deep Hash matcher for rspec}
13
+ s.description = s.summary
14
+
15
+ s.rubyforge_project = "rspec-deep-matchers"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'rspec', '>= 2.0.0'
23
+
24
+ s.add_development_dependency('guard-rspec')
25
+ s.add_development_dependency('growl')
26
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'deep_eql' do
4
+
5
+ context "should match" do
6
+ after(:each) do
7
+ @actual.should deep_eql(@expect)
8
+ end
9
+
10
+ it "eql strings" do
11
+ @actual = "true"
12
+ @expect = "true"
13
+ end
14
+
15
+ context "arrays" do
16
+
17
+ it "that are eql" do
18
+ @actual = [1,2,3]
19
+ @expect = [1,2,3]
20
+ end
21
+
22
+ it "with hash with different order" do
23
+ @actual = [1, 2, {"one" => 1, "two" => 2, "three" => 3 }]
24
+ @expect = [1, 2, {"three" => 3, "one" => 1, "two" => 2 }]
25
+ end
26
+
27
+ end
28
+
29
+ context "hash with" do
30
+
31
+ it "differen key order" do
32
+ @actual = {:yes => 'yes', :no => 'no'}
33
+ @expect = {:no => 'no', :yes => 'yes'}
34
+ end
35
+
36
+ it "same key order" do
37
+ @actual = {:yes => 'yes', :no => 'no'}
38
+ @expect = {:yes => 'yes', :no => 'no'}
39
+ end
40
+
41
+ context "nested hash" do
42
+
43
+ it "with differen key order" do
44
+ @actual = {:yes => 'yes', :no => {:label => "name", :name => "Name"} }
45
+ @expect = {:no => {:label => "name", :name => "Name"}, :yes => 'yes'}
46
+ end
47
+
48
+ it "with differen key order in nested hashes" do
49
+ @actual = {:yes => 'yes', :no => {:label => "name", :name => "Name"} }
50
+ @expect = {:no => {:name => "Name", :label => "name"}, :yes => 'yes'}
51
+ end
52
+
53
+ it "with 3 levels" do
54
+ @actual = {:yes => 'yes', :no => {:label => "name", :name => {:first_name => "John", :last_name => "Smith"} } }
55
+ @expect = {:no => {:name => {:first_name => "John", :last_name => "Smith"}, :label => "name"}, :yes => 'yes'}
56
+ end
57
+
58
+ end
59
+
60
+ context "array" do
61
+
62
+ it "with strict order" do
63
+ @actual = {:yes => 'yes', :maybe => [:true, :false] }
64
+ @expect = {:maybe => [:true, :false], :yes => 'yes'}
65
+ end
66
+
67
+ it "2 level" do
68
+ @actual = {:yes => 'yes', :maybe => [[:true, :false], [:yes, :no]] }
69
+ @expect = {:maybe => [[:true, :false], [:yes, :no]], :yes => 'yes'}
70
+ end
71
+
72
+ it "that has hash with different order" do
73
+ @actual = {:yes => 'yes', :maybe => [{:true => "yes", :false => "no"}, [:yes, :no]] }
74
+ @expect = {:maybe => [{:false => "no", :true => "yes"}, [:yes, :no]], :yes => 'yes'}
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+
81
+
82
+ end
83
+
84
+
85
+ context "should not match" do
86
+
87
+ after(:each) do
88
+ @actual.should_not deep_eql(@expect)
89
+ end
90
+
91
+ it "different strings" do
92
+ @actual = "true"
93
+ @expect = "false"
94
+ end
95
+
96
+ context "hash with" do
97
+
98
+ it "differen key number ( @actual < @expect)" do
99
+ @actual = {:yes => 'yes', :no => 'no'}
100
+ @expect = {:yes => 'yes', :no => 'no', :maybe =>'maybe'}
101
+ end
102
+
103
+ it "differen key number ( @actual > @expect)" do
104
+ @actual = {:yes => 'yes', :no => 'no', :maybe =>'maybe'}
105
+ @expect = {:yes => 'yes', :no => 'no'}
106
+ end
107
+
108
+ it "differen value" do
109
+ @actual = {:yes => 'yes', :no => 'maybe'}
110
+ @expect = {:yes => 'yes', :no => 'no'}
111
+ end
112
+
113
+ end
114
+
115
+ context "array with" do
116
+
117
+ it "different size ( @actual < @expect)" do
118
+ @actual = [1,2,3]
119
+ @expect = [1,2,3,4]
120
+ end
121
+
122
+ it "different size ( @actual > @expect)" do
123
+ @actual = [1,2,3,4]
124
+ @expect = [1,2,3]
125
+ end
126
+
127
+ it "differen value" do
128
+ @actual = [1,2,4]
129
+ @expect = [1,2,3]
130
+ end
131
+
132
+ end
133
+
134
+
135
+ end
136
+
137
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'rspec-deep-matchers'
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-deep-matchers
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - vitalish
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-02 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ version: 2.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: guard-rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: growl
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ description: Deep Hash matcher for rspec
66
+ email:
67
+ - vitalish@4life.com.ua
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - Guardfile
78
+ - Rakefile
79
+ - lib/rspec-deep-matchers.rb
80
+ - lib/rspec/matchers.rb
81
+ - lib/rspec/matchers/deep_eql.rb
82
+ - lib/version.rb
83
+ - rspec-deep-matchers.gemspec
84
+ - spec/lib/rspec/matchers/deep_eql_spec.rb
85
+ - spec/spec_helper.rb
86
+ has_rdoc: true
87
+ homepage: http://github.com/vitalish/rspec-deep-matchers
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project: rspec-deep-matchers
116
+ rubygems_version: 1.3.7
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Deep Hash matcher for rspec
120
+ test_files:
121
+ - spec/lib/rspec/matchers/deep_eql_spec.rb
122
+ - spec/spec_helper.rb