mattly-exegesis 0.2.2 → 0.2.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/test/model_test.rb CHANGED
@@ -28,51 +28,51 @@ class ExposeTestModel
28
28
  expose :other_doc, :other_docs, :as => :reference
29
29
  end
30
30
 
31
- class ExegesisModelTest < Test::Unit::TestCase
31
+ describe Exegesis::Model do
32
32
 
33
- context "class definitions" do
34
- context "default objects" do
35
- expect { WithDefaultTestModel.new['foo'].will == 'bar' }
36
- expect { WithDefaultTestModel.new({'foo' => 'baz'})['foo'].will == 'baz' }
33
+ describe "class definitions" do
34
+ describe "default objects" do
35
+ expect { WithDefaultTestModel.new['foo'].must_equal 'bar' }
36
+ expect { WithDefaultTestModel.new({'foo' => 'baz'})['foo'].must_equal 'baz' }
37
37
  end
38
38
 
39
- context "exposing keys" do
40
- context "regular declarations" do
39
+ describe "exposing keys" do
40
+ describe "regular declarations" do
41
41
  before do
42
42
  @obj = ExposeTestModel.new(:foo => 'bar', :bar => 'foo')
43
43
  end
44
- context "reading" do
45
- expect { @obj.foo.will == 'bar' }
46
- expect { @obj.bar.will == 'foo' }
44
+ describe "reading" do
45
+ expect { @obj.foo.must_equal 'bar' }
46
+ expect { @obj.bar.must_equal 'foo' }
47
47
  end
48
48
 
49
- context "writing" do
49
+ describe "writing" do
50
50
  before do
51
51
  @obj.bar = "bee"
52
52
  end
53
- expect { @obj.bar.will == "bee" }
53
+ expect { @obj.bar.must_equal "bee" }
54
54
  end
55
55
  end
56
56
 
57
- context "with a custom writer" do
58
- context "when false" do
57
+ describe "with a custom writer" do
58
+ describe "when false" do
59
59
  before { @obj = ExposeTestModel.new(:read_only => 'value') }
60
- expect { @obj.read_only.will == 'value' }
61
- expect { lambda{@obj.read_only = "other value"}.will raise_error(NoMethodError) }
60
+ expect { @obj.read_only.must_equal 'value' }
61
+ expect { lambda{@obj.read_only = "other value"}.must_raise NoMethodError }
62
62
  end
63
63
 
64
- context "when lambda" do
64
+ describe "when lambda" do
65
65
  before do
66
66
  @obj = ExposeTestModel.new(:custom_writer => 'value')
67
67
  @obj.custom_writer = 'other value'
68
68
  @expected = {'value' => 'other value'}
69
69
  end
70
- expect { @obj.custom_writer.will == @expected }
70
+ expect { @obj.custom_writer.must_equal @expected }
71
71
  end
72
72
  end
73
73
 
74
- context "when casting a value" do
75
- context "when as given" do
74
+ describe "when casting a value" do
75
+ describe "when as given" do
76
76
  before do
77
77
  @obj = ExposeTestModel.new({
78
78
  :castee => {'foo' => 'foo', 'class' => 'FooTestModel'},
@@ -85,69 +85,69 @@ class ExegesisModelTest < Test::Unit::TestCase
85
85
  @obj.castees
86
86
  end
87
87
 
88
- expect { @obj.castee.class.will == FooTestModel }
89
- expect { @obj.castee['foo'].will == 'foo' }
90
- expect { @obj.castee.parent.will == @obj }
88
+ expect { @obj.castee.must_be_kind_of FooTestModel }
89
+ expect { @obj.castee['foo'].must_equal 'foo' }
90
+ expect { @obj.castee.parent.must_equal @obj }
91
91
 
92
- expect { @obj.castees.class.will == Array }
93
- expect { @obj.castees[0].class.will == FooTestModel }
94
- expect { @obj.castees[0]['foo'].will == 'foo' }
95
- expect { @obj.castees[0].parent.will == @obj }
96
- expect { @obj.castees[1].class.will == BarTestModel }
97
- expect { @obj.castees[1]['foo'].will == 'bar' }
98
- expect { @obj.castees[1].parent.will == @obj }
92
+ expect { @obj.castees.must_be_kind_of Array }
93
+ expect { @obj.castees[0].must_be_kind_of FooTestModel }
94
+ expect { @obj.castees[0]['foo'].must_equal 'foo' }
95
+ expect { @obj.castees[0].parent.must_equal @obj }
96
+ expect { @obj.castees[1].must_be_kind_of BarTestModel }
97
+ expect { @obj.castees[1]['foo'].must_equal 'bar' }
98
+ expect { @obj.castees[1].parent.must_equal @obj }
99
99
 
100
- context "defining the writer" do
100
+ describe "defining the writer" do
101
101
  before do
102
102
  @obj = ExposeTestModel.new
103
103
  @foo = FooTestModel.new({'foo' => 'bar'})
104
104
  @obj.castee = @foo
105
105
  end
106
- expect { @obj.castee.will == @foo }
106
+ expect { @obj.castee.must_equal @foo }
107
107
  end
108
108
  end
109
109
 
110
- context "when as time" do
110
+ describe "when as time" do
111
111
  before do
112
112
  @obj = ExposeTestModel.new({:time => Time.now.to_json, :times => [Time.local(2009,3,1).to_json, Time.local(2009,2,1).to_json]})
113
113
  @obj.time
114
114
  @obj.times
115
115
  end
116
116
 
117
- expect { @obj.time.class.will == Time }
118
- expect { @obj.time.to_f.will be_close(Time.now.to_f, 1) }
117
+ expect { @obj.time.must_be_kind_of Time }
118
+ expect { @obj.time.to_f.must_be_close_to Time.now.to_f, 1 }
119
119
 
120
- expect { @obj.times.class.will == Array }
121
- expect { @obj.times[0].class.will == Time }
122
- expect { @obj.times[0].will == Time.local(2009,3,1) }
123
- expect { @obj.times[1].class.will == Time }
124
- expect { @obj.times[1].will == Time.local(2009,2,1) }
120
+ expect { @obj.times.must_be_kind_of Array }
121
+ expect { @obj.times[0].must_be_kind_of Time }
122
+ expect { @obj.times[0].must_equal Time.local(2009,3,1) }
123
+ expect { @obj.times[1].must_be_kind_of Time }
124
+ expect { @obj.times[1].must_equal Time.local(2009,2,1) }
125
125
 
126
- context "writing times" do
126
+ describe "writing times" do
127
127
  before do
128
128
  @obj = ExposeTestModel.new
129
129
  @time = Time.local(2009,4,16,20,14,26)
130
130
  end
131
- context "from a time object" do
131
+ describe "from a time object" do
132
132
  before do
133
133
  @obj.time = @time
134
134
  @obj.times = [@time, @time]
135
135
  end
136
- expect { @obj.time.will == @time }
137
- expect { @obj.times.will == [@time, @time] }
136
+ expect { @obj.time.must_equal @time }
137
+ expect { @obj.times.must_equal [@time, @time] }
138
138
  end
139
- context "from a string" do
139
+ describe "from a string" do
140
140
  before do
141
141
  @obj.time = @time.xmlschema
142
142
  @obj.times = [@time.rfc2822, @time.getutc.strftime("%a, %d %b %Y %H:%M:%S GMT")]
143
143
  end
144
- expect { @obj.time.will == @time }
145
- expect { @obj.times.map{|time| time.localtime }.will == [@time, @time] }
144
+ expect { @obj.time.must_equal @time }
145
+ expect { @obj.times.map{|time| time.localtime }.must_equal [@time, @time] }
146
146
  end
147
147
  end
148
148
  end
149
149
 
150
- context "when as non document class" do
150
+ describe "when as non document class" do
151
151
  before do
152
152
  @obj = ExposeTestModel.new({
153
153
  :regex => 'foo',
@@ -157,24 +157,24 @@ class ExegesisModelTest < Test::Unit::TestCase
157
157
  @obj.regexen
158
158
  end
159
159
 
160
- expect { @obj.regex.will == /foo/ }
160
+ expect { @obj.regex.must_equal /foo/ }
161
161
 
162
- expect { @obj.regexen.class.will == Array }
163
- expect { @obj.regexen[0].will == /foo/ }
164
- expect { @obj.regexen[1].will == /bar/ }
162
+ expect { @obj.regexen.must_be_kind_of Array }
163
+ expect { @obj.regexen[0].must_equal /foo/ }
164
+ expect { @obj.regexen[1].must_equal /bar/ }
165
165
 
166
- context "writing values from the class" do
166
+ describe "writing values from the class" do
167
167
  before do
168
168
  @obj = ExposeTestModel.new
169
169
  @regex = /foo/
170
170
  @obj.regex = @regex
171
171
  end
172
- expect { @obj.regex.will == @regex }
172
+ expect { @obj.regex.must_equal @regex }
173
173
  end
174
174
  end
175
175
 
176
- context "when as reference" do
177
- context "with a database present" do
176
+ describe "when as reference" do
177
+ describe "with a database present" do
178
178
  before do
179
179
  reset_db
180
180
  @obj = ExposeTestModel.new(:other_doc => "other_doc",
@@ -183,7 +183,7 @@ class ExegesisModelTest < Test::Unit::TestCase
183
183
  @obj.parent = @doc
184
184
  end
185
185
 
186
- context "when the referenced document exists" do
186
+ describe "when the referenced document exists" do
187
187
  before do
188
188
  [ {'class' => 'ModelTestDocument', '_id' => 'other_doc'},
189
189
  {'class' => 'ModelTestDocument', '_id' => 'other_docs_1'},
@@ -191,15 +191,15 @@ class ExegesisModelTest < Test::Unit::TestCase
191
191
  ].each {|doc| @db.put(doc.delete('_id'), doc) }
192
192
  end
193
193
 
194
- expect { @obj.other_doc['_rev'].will == @db.get('other_doc')['_rev'] }
195
- expect { @obj.other_doc.class.will == ModelTestDocument }
196
- expect { @obj.other_docs.class.will == Array }
197
- expect { @obj.other_docs[0]['_rev'].will == @db.get('other_docs_1')['_rev'] }
198
- expect { @obj.other_docs[0].class.will == ModelTestDocument }
199
- expect { @obj.other_docs[1]['_rev'].will == @db.get('other_docs_2')['_rev'] }
200
- expect { @obj.other_docs[1].class.will == ModelTestDocument }
194
+ expect { @obj.other_doc['_rev'].must_equal @db.get('other_doc')['_rev'] }
195
+ expect { @obj.other_doc.must_be_kind_of ModelTestDocument }
196
+ expect { @obj.other_docs.must_be_kind_of Array }
197
+ expect { @obj.other_docs[0]['_rev'].must_equal @db.get('other_docs_1')['_rev'] }
198
+ expect { @obj.other_docs[0].must_be_kind_of ModelTestDocument }
199
+ expect { @obj.other_docs[1]['_rev'].must_equal @db.get('other_docs_2')['_rev'] }
200
+ expect { @obj.other_docs[1].must_be_kind_of ModelTestDocument }
201
201
 
202
- context "caching" do
202
+ describe "caching" do
203
203
  before do
204
204
  @obj.other_doc # load it
205
205
  doc = @db.get('other_doc')
@@ -207,32 +207,32 @@ class ExegesisModelTest < Test::Unit::TestCase
207
207
  @db.put(doc['_id'], doc.attributes)
208
208
  end
209
209
 
210
- expect { @obj.other_doc['foo'].will be(nil) }
211
- expect { @obj.other_doc(true)['foo'].will == 'updated' }
210
+ expect { @obj.other_doc['foo'].must_be_nil }
211
+ expect { @obj.other_doc(true)['foo'].must_equal 'updated' }
212
212
  end
213
213
  end
214
214
 
215
- context "when the document is missing" do
216
- expect { lambda{@obj.other_doc}.will raise_error(RestClient::ResourceNotFound) }
217
- expect { lambda{@obj.other_docs}.will raise_error(RestClient::ResourceNotFound) }
215
+ describe "when the document is missing" do
216
+ expect { lambda{@obj.other_doc}.must_raise RestClient::ResourceNotFound }
217
+ expect { lambda{@obj.other_docs}.must_raise RestClient::ResourceNotFound }
218
218
  end
219
219
 
220
- context "when the model has a parent" do
220
+ describe "when the model has a parent" do
221
221
  before do
222
222
  @obj.castee = {'class' => 'FooTestModel', 'ref' => 'other_doc'}
223
223
  @db.put('other_doc', {'class' => 'ModelTestDocument', '_id' => 'other_doc'})
224
224
  end
225
225
 
226
- expect { @obj.castee.ref['_rev'].will == @db.get('other_doc')['_rev'] }
226
+ expect { @obj.castee.ref['_rev'].must_equal @db.get('other_doc')['_rev'] }
227
227
  end
228
228
  end
229
229
 
230
- context "without any database present" do
230
+ describe "without any database present" do
231
231
  before { @obj = ExposeTestModel.new(:other_doc => "some_doc_id") }
232
- expect { lambda{@obj.other_doc}.will raise_error(ArgumentError) }
232
+ expect { lambda{@obj.other_doc}.must_raise ArgumentError }
233
233
  end
234
234
 
235
- context "setting references" do
235
+ describe "setting references" do
236
236
  before do
237
237
  reset_db
238
238
  @parent = ModelTestDocument.new({}, @db)
@@ -241,59 +241,59 @@ class ExegesisModelTest < Test::Unit::TestCase
241
241
  @doc = ModelTestDocument.new({}, @db)
242
242
  @doc.save
243
243
  end
244
- context "from a doc that has been saved" do
244
+ describe "from a doc that has been saved" do
245
245
  before do
246
246
  @obj.other_doc = @doc
247
247
  end
248
- expect { @obj['other_doc'].will == @doc.id }
249
- expect { @obj.other_doc.will == @doc }
248
+ expect { @obj['other_doc'].must_equal @doc.id }
249
+ expect { @obj.other_doc.must_equal @doc }
250
250
  end
251
- context "from an id" do
251
+ describe "from an id" do
252
252
  before do
253
253
  @obj.other_doc = @doc.id
254
254
  end
255
- expect { @obj['other_doc'].will == @doc.id }
256
- expect { @obj.other_doc.will == @doc }
255
+ expect { @obj['other_doc'].must_equal @doc.id }
256
+ expect { @obj.other_doc.must_equal @doc }
257
257
  end
258
258
  end
259
259
  end
260
260
 
261
- context "when the value is nil" do
261
+ describe "when the value is nil" do
262
262
  before do
263
263
  @obj = ExposeTestModel.new({:castee => nil, :castees => nil, :regexen => ['foo', nil]})
264
264
  end
265
- expect { @obj.castee.will be(nil) }
266
- expect { @obj.castees.will be(nil) }
267
- expect { @obj.regexen.will == [/foo/] }
265
+ expect { @obj.castee.must_be_nil }
266
+ expect { @obj.castees.must_be_nil }
267
+ expect { @obj.regexen.must_equal [/foo/] }
268
268
  end
269
269
 
270
270
  end
271
271
  end
272
272
  end
273
273
 
274
- context "instance methods" do
274
+ describe "instance methods" do
275
275
  before do
276
276
  @obj = ExposeTestModel.new({:read_only => 'bar'})
277
277
  end
278
- context "update" do
278
+ describe "update" do
279
279
  before do
280
280
  @obj.update({:read_only => 'bee'})
281
281
  end
282
282
 
283
- expect { @obj.read_only.will == 'bee' }
283
+ expect { @obj.read_only.must_equal 'bee' }
284
284
  end
285
285
 
286
- context "update" do
287
- context "with a writer" do
286
+ describe "update" do
287
+ describe "with a writer" do
288
288
  before do
289
289
  @obj.update_attributes(:foo => 'foo')
290
290
  end
291
291
 
292
- expect { @obj.foo.will == "foo" }
292
+ expect { @obj.foo.must_equal "foo" }
293
293
  end
294
294
 
295
- context "without a writer" do
296
- expect { lambda{@obj.update_attributes({:read_only => 'bee'})}.will raise_error(NoMethodError) }
295
+ describe "without a writer" do
296
+ expect { lambda{@obj.update_attributes({:read_only => 'bee'})}.must_raise NoMethodError }
297
297
  end
298
298
  end
299
299
  end
data/test/server_test.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
2
 
3
- class ExegesisServerTest < Test::Unit::TestCase
3
+ describe Exegesis::Server do
4
4
 
5
- before(:all) do
5
+ before do
6
6
  @db = 'http://localhost:5984/exegesis-test'
7
7
  RestClient.delete @db rescue nil
8
8
  RestClient.delete "#{@db}-2" rescue nil
@@ -11,16 +11,16 @@ class ExegesisServerTest < Test::Unit::TestCase
11
11
  @server = Exegesis::Server.new('http://localhost:5984')
12
12
  end
13
13
 
14
- context "listing databases" do
15
- expect { @server.databases.include?('exegesis-test').will == true }
14
+ describe "listing databases" do
15
+ expect { @server.databases.must_include('exegesis-test') }
16
16
  end
17
17
 
18
- context "creating a database" do
18
+ describe "creating a database" do
19
19
  before do
20
20
  @response = @server.create_database('exegesis-test-2')
21
21
  end
22
22
 
23
- expect { @response['ok'].will == true }
23
+ expect { assert @response['ok'] }
24
24
  end
25
25
 
26
26
  end
data/test/test_helper.rb CHANGED
@@ -1,15 +1,14 @@
1
1
  require 'rubygems'
2
- require 'test/unit'
2
+ require 'minitest/spec'
3
+ MiniTest::Unit.autorun
3
4
 
4
- require 'context' # with github: gem install jeremymcanally-context
5
- require 'matchy' # best bet for now: clone from github and build yourself; when jeremy fixes matchy, jeremymcanally-matchy
6
- require 'zebra' # until jeremy updates matchy, download and build yourself, after that, with github: gem install giraffesoft-zebra
7
-
8
- begin
9
- require 'ruby-debug'
10
- Debugger.start
11
- rescue
12
- puts "no ruby-debug installed? REAlLY? ok, if that's how you roll..."
5
+ unless RUBY_VERSION =~ /^1\.9/
6
+ begin
7
+ require 'ruby-debug'
8
+ Debugger.start
9
+ rescue
10
+ puts "protip: `(sudo) gem install ruby-debug` for superhuman debugging powers"
11
+ end
13
12
  end
14
13
 
15
14
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -19,7 +18,17 @@ class TestingDatabase
19
18
  include Exegesis::Database
20
19
  end
21
20
 
22
- class Test::Unit::TestCase
21
+ class MiniTest::Spec
22
+ # beacuse test names are really just comments, and therefore a code smell
23
+ def self.expect(desc=nil, &block)
24
+ @counter ||= 0; @counter += 1
25
+ desc ||= "[#{@counter}]"
26
+ name = ["test_", description_stack.join(' '), desc].join(' ')
27
+ define_method name, &block
28
+ end
29
+ end
30
+
31
+ class MiniTest::Unit::TestCase
23
32
 
24
33
  def fixtures_path fixtures
25
34
  File.join(File.dirname(__FILE__), 'fixtures', fixtures)
@@ -30,10 +39,10 @@ class Test::Unit::TestCase
30
39
  end
31
40
 
32
41
  # todo: extract to some helper methods to include ala RR, etc
33
- def reset_db(name=nil)
42
+ def reset_db(name=nil, klass=TestingDatabase)
34
43
  RestClient.delete "http://localhost:5984/#{db(name)}" rescue nil
35
44
  db_server.create_database(db(name))
36
- @db = TestingDatabase.new(db_server, db(name))
45
+ @db = klass.new(db_server, db(name))
37
46
  end
38
47
 
39
48
  def db(name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattly-exegesis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Lyon