couch_potato-rspec 4.1.0 → 4.2.0
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.
- checksums.yaml +4 -4
- data/lib/couch_potato/rspec/matchers/map_reduce_to_matcher.rb +1 -2
- data/lib/couch_potato/rspec/matchers/map_to_matcher.rb +1 -2
- data/lib/couch_potato/rspec/matchers.rb +0 -5
- data/spec/unit/rspec_matchers_spec.rb +2 -66
- metadata +2 -3
- data/lib/couch_potato/rspec/matchers/list_as_matcher.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d68de0bf53b36f20a95ded75fb2ce46d9f98c8f5e3f827d96a0b8a9223990a4
|
4
|
+
data.tar.gz: 13a2791430a4fcdad0b1bda153b0649654928221a55a2640f323a37e9b7854e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fda46a962a7c1294fa3e2d5b95e38e2624523b93a9c05cb78ba300ef3ccba6ac9f1a1e1bb96cb54a5b16ff44dce38d9894782aac081e74efa23378ba9fb8df9
|
7
|
+
data.tar.gz: b9e88e7081943e7dae05754bf9bd81f8ef807996171b16c8d0063fe19ebf330dee2eedf67b374213ef5e69baf0c9453d2709ec936f0194ce56f25ef588469a38
|
@@ -72,7 +72,6 @@ module CouchPotato
|
|
72
72
|
var options = #{@options.to_json};
|
73
73
|
var map = #{view_spec.map_function};
|
74
74
|
var reduce = #{view_spec.reduce_function};
|
75
|
-
var lib = #{view_spec.respond_to?(:lib) && view_spec.lib.to_json};
|
76
75
|
var collate = (function() { var module = {exports: {}}; var exports = module.exports; eval(#{File.read(File.expand_path(File.dirname(__FILE__) + '/../../../../vendor/pouchdb-collate/pouchdb-collate.js')).to_json}); return module.exports.collate;})();
|
77
76
|
|
78
77
|
// Map the input docs
|
@@ -80,7 +79,7 @@ module CouchPotato
|
|
80
79
|
var module = {exports: {}};
|
81
80
|
var exports = module.exports;
|
82
81
|
var pathArray = modulePath.split("/").slice(2);
|
83
|
-
var result =
|
82
|
+
var result = {};
|
84
83
|
for (var i in pathArray) {
|
85
84
|
result = result[pathArray[i]];
|
86
85
|
}
|
@@ -26,13 +26,12 @@ module CouchPotato
|
|
26
26
|
(function() {
|
27
27
|
var doc = #{@input_ruby.to_json};
|
28
28
|
var map = #{view_spec.map_function};
|
29
|
-
var lib = #{view_spec.respond_to?(:lib) && view_spec.lib.to_json};
|
30
29
|
var result = [];
|
31
30
|
var require = function(modulePath) {
|
32
31
|
var module = {exports: {}};
|
33
32
|
var exports = module.exports;
|
34
33
|
var pathArray = modulePath.split("/").slice(2);
|
35
|
-
var result =
|
34
|
+
var result = {};
|
36
35
|
for (var i in pathArray) {
|
37
36
|
result = result[pathArray[i]];
|
38
37
|
}
|
@@ -3,7 +3,6 @@ require 'execjs'
|
|
3
3
|
require 'couch_potato/rspec/matchers/map_to_matcher'
|
4
4
|
require 'couch_potato/rspec/matchers/reduce_to_matcher'
|
5
5
|
require 'couch_potato/rspec/matchers/map_reduce_to_matcher'
|
6
|
-
require 'couch_potato/rspec/matchers/list_as_matcher'
|
7
6
|
|
8
7
|
module RSpec
|
9
8
|
module Matchers
|
@@ -19,10 +18,6 @@ module RSpec
|
|
19
18
|
CouchPotato::RSpec::ReduceToProxy.new(keys, values, true)
|
20
19
|
end
|
21
20
|
|
22
|
-
def list(results)
|
23
|
-
CouchPotato::RSpec::ListAsProxy.new(results)
|
24
|
-
end
|
25
|
-
|
26
21
|
def map_reduce(*docs)
|
27
22
|
CouchPotato::RSpec::MapReduceToProxy.new(docs)
|
28
23
|
end
|
@@ -36,22 +36,6 @@ describe CouchPotato::RSpec::MapToMatcher do
|
|
36
36
|
expect(spec).to map({}).to([nil, "2013-05-17T15:00:00.000Z"])
|
37
37
|
end
|
38
38
|
|
39
|
-
it "should work with commonJS modules that use 'exports'" do
|
40
|
-
spec = double(
|
41
|
-
:map_function => "function(doc) { var test = require('views/lib/test'); emit(null, test.test); }",
|
42
|
-
:lib => {:test => "exports.test = 'test';"}
|
43
|
-
)
|
44
|
-
expect(spec).to map({}).to([nil, "test"])
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should work with commonJS modules that use 'module.exports'" do
|
48
|
-
spec = double(
|
49
|
-
:map_function => "function(doc) { var test = require('views/lib/test'); emit(null, test.test); }",
|
50
|
-
:lib => {:test => "module.exports.test = 'test';"}
|
51
|
-
)
|
52
|
-
expect(spec).to map({}).to([nil, "test"])
|
53
|
-
end
|
54
|
-
|
55
39
|
describe "failing specs" do
|
56
40
|
before(:each) do
|
57
41
|
@view_spec = double(:map_function => "function(doc) {emit(doc.name, null)}")
|
@@ -145,22 +129,6 @@ describe CouchPotato::RSpec::MapReduceToMatcher do
|
|
145
129
|
expect(spec).to map_reduce({}).to({"key" => nil, "value" => "2013-05-17T15:00:00.000Z"})
|
146
130
|
end
|
147
131
|
|
148
|
-
it "should handle CommonJS requires for modules that use 'exports'" do
|
149
|
-
spec = double(
|
150
|
-
:map_function => "function() { var test = require('views/lib/test'); emit(null, test.test); }",
|
151
|
-
:reduce_function => "function(keys, values) { return 'test' }",
|
152
|
-
:lib => {:test => "exports.test = 'test'"})
|
153
|
-
expect(spec).to map_reduce({}).to({"key" => nil, "value" => "test"})
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should handle CommonJS requires for modules that use 'module.exports'" do
|
157
|
-
spec = double(
|
158
|
-
:map_function => "function() { var test = require('views/lib/test'); emit(null, test.test); }",
|
159
|
-
:reduce_function => "function(keys, values) { return 'test' }",
|
160
|
-
:lib => {:test => "module.exports.test = 'test'"})
|
161
|
-
expect(spec).to map_reduce({}).to({"key" => nil, "value" => "test"})
|
162
|
-
end
|
163
|
-
|
164
132
|
it "should handle sum function" do
|
165
133
|
spec = double(
|
166
134
|
:map_function => "function(doc) { emit(null, doc.age); }",
|
@@ -240,13 +208,13 @@ describe CouchPotato::RSpec::MapReduceToMatcher do
|
|
240
208
|
it "should have a nice error message for failing should" do
|
241
209
|
expect {
|
242
210
|
expect(@view_spec).to map_reduce(@docs).with_options(:group => false).to({"key" => nil, "value" => 9})
|
243
|
-
}.to raise_error(
|
211
|
+
}.to raise_error(%r{Expected to map/reduce to \[{"key"\s*=>\s*nil, "value"\s*=>\s*9}\] but got \[{"key"\s*=>\s*nil, "value"\s*=>\s*8}\].})
|
244
212
|
end
|
245
213
|
|
246
214
|
it "should have a nice error message for failing should not" do
|
247
215
|
expect {
|
248
216
|
expect(@view_spec).not_to map_reduce(@docs).with_options(:group => false).to({"key" => nil, "value" => 8})
|
249
|
-
}.to raise_error(
|
217
|
+
}.to raise_error(%r{Expected not to map/reduce to \[{"key"\s*=>\s*nil, "value"\s*=>\s*8}\] but did.})
|
250
218
|
end
|
251
219
|
end
|
252
220
|
|
@@ -283,35 +251,3 @@ describe CouchPotato::RSpec::MapReduceToMatcher do
|
|
283
251
|
end
|
284
252
|
end
|
285
253
|
|
286
|
-
describe CouchPotato::RSpec::ListAsMatcher do
|
287
|
-
before(:each) do
|
288
|
-
@view_spec = double(:list_function => "function() {var row = getRow(); send(JSON.stringify([{text: row.text + ' world'}]));}")
|
289
|
-
end
|
290
|
-
|
291
|
-
it "should pass if the function return the expected json" do
|
292
|
-
expect(@view_spec).to list({'rows' => [{:text => 'hello'}]}).as([{'text' => 'hello world'}])
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should not pass if the function does not return the expected json" do
|
296
|
-
expect(@view_spec).not_to list({'rows' => [{:text => 'hello'}]}).as([{'text' => 'hello there'}])
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should work with date values" do
|
300
|
-
spec = double(:list_function => "function() { send(JSON.stringify([{date: new Date(1368802800000)}])); }")
|
301
|
-
expect(spec).to list({"rows" => [{}]}).as([{"date" => "2013-05-17T15:00:00.000Z"}])
|
302
|
-
end
|
303
|
-
|
304
|
-
describe "failing specs" do
|
305
|
-
it "should have a nice error message for failing should" do
|
306
|
-
expect {
|
307
|
-
expect(@view_spec).to list({'rows' => [{:text => 'hello'}]}).as([{'text' => 'hello there'}])
|
308
|
-
}.to raise_error('Expected to list as [{"text"=>"hello there"}] but got [{"text"=>"hello world"}].')
|
309
|
-
end
|
310
|
-
|
311
|
-
it "should have a nice error message for failing should not" do
|
312
|
-
expect {
|
313
|
-
expect(@view_spec).not_to list({'rows' => [{:text => 'hello'}]}).as([{'text' => 'hello world'}])
|
314
|
-
}.to raise_error('Expected to not list as [{"text"=>"hello world"}] but did.')
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_potato-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -60,7 +60,6 @@ extra_rdoc_files: []
|
|
60
60
|
files:
|
61
61
|
- lib/couch_potato/rspec.rb
|
62
62
|
- lib/couch_potato/rspec/matchers.rb
|
63
|
-
- lib/couch_potato/rspec/matchers/list_as_matcher.rb
|
64
63
|
- lib/couch_potato/rspec/matchers/map_reduce_to_matcher.rb
|
65
64
|
- lib/couch_potato/rspec/matchers/map_to_matcher.rb
|
66
65
|
- lib/couch_potato/rspec/matchers/reduce_to_matcher.rb
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module CouchPotato
|
2
|
-
module RSpec
|
3
|
-
class ListAsProxy
|
4
|
-
def initialize(results_ruby)
|
5
|
-
@results_ruby = results_ruby
|
6
|
-
end
|
7
|
-
|
8
|
-
def as(expected_ruby)
|
9
|
-
ListAsMatcher.new(expected_ruby, @results_ruby)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class ListAsMatcher
|
14
|
-
include ::RSpec::Matchers::Composable
|
15
|
-
|
16
|
-
def initialize(expected_ruby, results_ruby)
|
17
|
-
@expected_ruby = expected_ruby
|
18
|
-
@results_ruby = results_ruby
|
19
|
-
end
|
20
|
-
|
21
|
-
def matches?(view_spec)
|
22
|
-
js = <<-JS
|
23
|
-
(function() {
|
24
|
-
var results = #{@results_ruby.to_json};
|
25
|
-
var listed = '';
|
26
|
-
var list = #{view_spec.list_function};
|
27
|
-
|
28
|
-
var getRow = function() {
|
29
|
-
return results.rows.shift();
|
30
|
-
};
|
31
|
-
var send = function(text) {
|
32
|
-
listed = listed + text;
|
33
|
-
};
|
34
|
-
list();
|
35
|
-
return JSON.stringify(JSON.parse(listed));
|
36
|
-
})()
|
37
|
-
|
38
|
-
JS
|
39
|
-
@actual_ruby = JSON.parse(ExecJS.eval(js))
|
40
|
-
|
41
|
-
values_match? @expected_ruby, @actual_ruby
|
42
|
-
end
|
43
|
-
|
44
|
-
def failure_message
|
45
|
-
"Expected to list as #{@expected_ruby.inspect} but got #{@actual_ruby.inspect}."
|
46
|
-
end
|
47
|
-
|
48
|
-
def failure_message_when_negated
|
49
|
-
"Expected to not list as #{@expected_ruby.inspect} but did."
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|