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/README.rdoc CHANGED
@@ -51,13 +51,18 @@ CouchDB is table-less, and Exegesis's design reflects this. In CouchDB, Document
51
51
 
52
52
  == Requirements:
53
53
 
54
- * RestClient
54
+ * RestClient 0.9 or later.
55
55
 
56
56
  For running the tests:
57
57
 
58
- * Test::Unit (you got it)
59
- * Context (http://github.com/jeremymcanally/context, can install from github gems)
60
- * Matchy (http://github.com/jeremymcanally/matchy, github gem version out of date; clone, build & install for now)
61
- * Zebra (http://github.com/giraffesoft/zerba, depends on jeremymcanally-matchy, which is out of date; clone, build & install for now)
58
+ * MiniTest
59
+ MiniTest is the default testing framework for Ruby 1.9
60
+ However, these tests require the trunk version, and my patches against the trunk version.
61
+ The trunk version is here: http://github.com/seattlerb/minitest
62
+ My patches are in my fork: http://github.com/mattly/minitest
63
+ You will need to clone my repo and from its directory, do the following:
64
+ `rake gem`
65
+ `sudo gem install pkg/minitest-1.3.1`
66
+ Once MiniTest 1.3.2 is released you should be able to use the standard gem.
62
67
 
63
- The test suite creates and destroys a database for each test that requires access to the database. This is slow, and the test suite may take some time to run. However, I would rather the test suite be slow and accurate than quick and full of mocking.
68
+ The test suite creates and destroys a database for each test that requires access to the database. This is slow, and the test suite may take some time to run. However, I would rather the test suite be slow and accurate than quick and full of mocking or possibly error-prone deleting.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 2
4
+ :patch: 4
@@ -21,7 +21,7 @@ module Exegesis
21
21
  end
22
22
 
23
23
  def self.compose_canonical
24
- Dir[design_directory + 'views' + '**/*.js'].each do |view_func|
24
+ Dir[(design_directory + 'views' + '**/*.js').to_s].each do |view_func|
25
25
  path = view_func.split('/')
26
26
  func = path.pop.sub(/\.js$/,'')
27
27
  name = path.pop
@@ -4,18 +4,18 @@ class AttachmentsDocumentTest
4
4
  include Exegesis::Document
5
5
  end
6
6
 
7
- class ExegesisAttachmentsTest < Test::Unit::TestCase
7
+ describe Exegesis::Document::Attachments do
8
8
  before do
9
9
  reset_db
10
10
  @doc = AttachmentsDocumentTest.new({}, @db)
11
11
  end
12
12
 
13
- context "document methods" do
14
- expect { @doc.attachments.kind_of?(Exegesis::Document::Attachments).will == true }
15
- expect { @doc.attachments.size.will == 0 }
13
+ describe "document methods" do
14
+ expect { @doc.attachments.must_be_kind_of Exegesis::Document::Attachments }
15
+ expect { @doc.attachments.size.must_equal 0 }
16
16
  end
17
17
 
18
- context "reading existing attachments" do
18
+ describe "reading existing attachments" do
19
19
  before do
20
20
  @doc.save
21
21
  @text = "this is a file"
@@ -23,20 +23,20 @@ class ExegesisAttachmentsTest < Test::Unit::TestCase
23
23
  @doc = @db.get(@doc['_id'])
24
24
  end
25
25
 
26
- expect { @doc.attachments.size.will == 1 }
27
- expect { @doc.attachments.keys.will == %w(file.txt) }
28
- expect { @doc.attachments['file.txt'].content_type.will == 'text/plain' }
29
- expect { @doc.attachments['file.txt'].length.will == @text.length }
30
- expect { @doc.attachments['file.txt'].stub?.will == true }
31
- expect { @doc.attachments['file.txt'].file.will == @text }
26
+ expect { @doc.attachments.size.must_equal 1 }
27
+ expect { @doc.attachments.keys.must_equal %w(file.txt) }
28
+ expect { @doc.attachments['file.txt'].content_type.must_equal 'text/plain' }
29
+ expect { @doc.attachments['file.txt'].length.must_equal @text.length }
30
+ expect { assert @doc.attachments['file.txt'].stub? }
31
+ expect { @doc.attachments['file.txt'].file.must_equal @text }
32
32
  end
33
33
 
34
- context "writing attachments" do
34
+ describe "writing attachments" do
35
35
  before do
36
36
  @doc.save
37
37
  end
38
- context "directly using attachments put" do
39
- context "with the file's contents as a string" do
38
+ describe "directly using attachments put" do
39
+ describe "with the file's contents as a string" do
40
40
  before do
41
41
  @contents = "this is the contents of a text file"
42
42
  @type = 'text/plain'
@@ -44,62 +44,62 @@ class ExegesisAttachmentsTest < Test::Unit::TestCase
44
44
  @putting.call 'f.txt', @contents, @type
45
45
  end
46
46
 
47
- context "when they don't exist yet" do
48
- expect { RestClient.get("#{@doc.uri}/f.txt").will == @contents }
49
- expect { @doc.attachments['f.txt'].file.will == @contents }
50
- expect { @doc.rev.will == @db.raw_get(@doc.id)['_rev'] }
47
+ describe "when they don't exist yet" do
48
+ expect { RestClient.get("#{@doc.uri}/f.txt").must_equal @contents }
49
+ expect { @doc.attachments['f.txt'].file.must_equal @contents }
50
+ expect { @doc.rev.must_equal @db.raw_get(@doc.id)['_rev'] }
51
51
  end
52
52
 
53
- context "when they do exist" do
53
+ describe "when they do exist" do
54
54
  before do
55
55
  @putting.call 'f.txt', "foo", @type
56
56
  end
57
- expect { @doc.attachments['f.txt'].file.will == "foo" }
57
+ expect { @doc.attachments['f.txt'].file.must_equal "foo" }
58
58
  end
59
59
  end
60
60
 
61
61
  # it turns out rest-client doesn't actually support streaming uploads/downloads yet
62
- # context "streaming the file as a block given" do
62
+ # describe "streaming the file as a block given" do
63
63
  # before do
64
64
  # @file = File.open(fixtures_path('attachments/flavakitten.jpg'))
65
65
  # @type = 'image/jpeg'
66
66
  # @doc.attachments.put('kitten.jpg', @type) { @file.read }
67
67
  # end
68
68
  #
69
- # expect { @doc.will satisfy(lambda{|e| e.attachments['kitten.jpg'].file == @file.read })}
69
+ # expect { lambda{|e| e.attachments['kitten.jpg'].file == @file.read }.must_be true }
70
70
  # end
71
71
  end
72
72
 
73
- context "indirectly, saved with the document" do
73
+ describe "indirectly, saved with the document" do
74
74
  before do
75
75
  @content = "this is an example file"
76
76
  @doc.attachments['file.txt'] = @content, 'text/plain'
77
77
  end
78
78
 
79
- expect { @doc.attachments['file.txt'].content_type.will == 'text/plain' }
80
- expect { @doc.attachments['file.txt'].metadata['data'].will == Base64.encode64(@content).gsub(/\s/,'') }
81
- expect { @doc.attachments['file.txt'].length.will == @content.length }
82
- expect { @doc.attachments.dirty?.will == true }
79
+ expect { @doc.attachments['file.txt'].content_type.must_equal 'text/plain' }
80
+ expect { @doc.attachments['file.txt'].metadata['data'].must_equal Base64.encode64(@content).strip }
81
+ expect { @doc.attachments['file.txt'].length.must_equal @content.length }
82
+ expect { assert @doc.attachments.dirty? }
83
83
 
84
- context "when saving" do
84
+ describe "when saving" do
85
85
  before do
86
86
  @doc.save
87
87
  end
88
88
 
89
- expect { @doc.attachments['file.txt'].file.will == @content }
90
- expect { @doc.attachments['file.txt'].stub?.will == true }
91
- expect { @doc.attachments['file.txt'].metadata.has_key?('data').will == false }
92
- expect { @doc.attachments.dirty?.will == false }
89
+ expect { @doc.attachments['file.txt'].file.must_equal @content }
90
+ expect { assert @doc.attachments['file.txt'].stub? }
91
+ expect { refute @doc.attachments['file.txt'].metadata.has_key?('data') }
92
+ expect { refute @doc.attachments.dirty? }
93
93
  end
94
94
  end
95
95
  end
96
96
 
97
- context "removing attachments" do
98
- context "from the document" do
97
+ describe "removing attachments" do
98
+ describe "from the document" do
99
99
 
100
100
  end
101
101
 
102
- context "directly from the database" do
102
+ describe "directly from the database" do
103
103
 
104
104
  end
105
105
  end
@@ -21,52 +21,52 @@ class DatabaseTestDocument
21
21
  include Exegesis::Document
22
22
  end
23
23
 
24
- class ExegesisDatabaseTest < Test::Unit::TestCase
25
- before(:all) do
24
+ describe Exegesis::Database do
25
+ before do
26
26
  @server = Exegesis::Server.new('http://localhost:5984')
27
27
  RestClient.delete("#{@server.uri}/exegesis-test") rescue nil
28
28
  RestClient.delete("#{@server.uri}/exegesis-test-nonexistent") rescue nil
29
29
  RestClient.put("#{@server.uri}/exegesis-test", '')
30
30
  end
31
31
 
32
- context "initializing" do
33
- context "with server and name arguments" do
32
+ describe "initializing" do
33
+ describe "with server and name arguments" do
34
34
  before do
35
- @db =DatabaseTest.new(@server, 'exegesis-test')
35
+ @db = DatabaseTest.new(@server, 'exegesis-test')
36
36
  end
37
37
 
38
- expect { @db.is_a?(DatabaseTest).will == true }
39
- expect { @db.uri.will == "#{@server.uri}/exegesis-test"}
38
+ expect { @db.must_be_kind_of DatabaseTest }
39
+ expect { @db.uri.must_equal "#{@server.uri}/exegesis-test"}
40
40
 
41
- context "when the database does not exist" do
41
+ describe "when the database does not exist" do
42
42
  before do
43
43
  @action = lambda { DatabaseTest.new(@server, 'exegesis-test-nonexistent') }
44
44
  end
45
45
 
46
- expect { @action.will raise_error(RestClient::ResourceNotFound) }
46
+ expect { @action.must_raise(RestClient::ResourceNotFound) }
47
47
  end
48
48
  end
49
49
 
50
- context "with a url argument" do
50
+ describe "with a url argument" do
51
51
  before do
52
52
  @db = DatabaseTest.new('http://localhost:5984/exegesis-test')
53
53
  end
54
54
 
55
- expect { @db.is_a?(DatabaseTest).will == true }
56
- expect { @db.uri.will == 'http://localhost:5984/exegesis-test' }
55
+ expect { @db.must_be_kind_of DatabaseTest }
56
+ expect { @db.uri.must_equal 'http://localhost:5984/exegesis-test' }
57
57
  end
58
58
 
59
- context "with a name argument" do
59
+ describe "with a name argument" do
60
60
  before do
61
61
  @db = DatabaseTest.new('exegesis-test')
62
62
  end
63
63
 
64
- expect { @db.is_a?(DatabaseTest).will == true }
65
- expect { @db.uri.will == "http://localhost:5984/exegesis-test" }
64
+ expect { @db.must_be_kind_of DatabaseTest }
65
+ expect { @db.uri.must_equal "http://localhost:5984/exegesis-test" }
66
66
  end
67
67
  end
68
68
 
69
- context "retrieving documents by id" do
69
+ describe "retrieving documents by id" do
70
70
  before do
71
71
  @db = DatabaseTest.new @server, 'exegesis-test'
72
72
  RestClient.put "#{@db.uri}/test-document", {'key'=>'value', 'class'=>'DatabaseTestDocument'}.to_json rescue nil
@@ -77,63 +77,63 @@ class ExegesisDatabaseTest < Test::Unit::TestCase
77
77
  RestClient.delete("#{@db.uri}/test-document?rev=#{@doc['_rev']}") rescue nil
78
78
  end
79
79
 
80
- expect { @doc.is_a?(DatabaseTestDocument).will == true }
81
- expect { @doc.id.will == 'test-document' }
82
- expect { @doc['key'].will == 'value' }
80
+ expect { @doc.must_be_kind_of DatabaseTestDocument }
81
+ expect { @doc.id.must_equal 'test-document' }
82
+ expect { @doc['key'].must_equal 'value' }
83
83
 
84
- context "retrieving the raw document" do
84
+ describe "retrieving the raw document" do
85
85
  before do
86
86
  @doc = @db.raw_get('test-document')
87
87
  end
88
88
 
89
- expect { @doc.is_a?(Hash).will == true }
90
- expect { @doc['_id'].will == 'test-document' }
91
- expect { @doc['key'].will == 'value' }
92
- expect { @doc['class'].will == 'DatabaseTestDocument' }
89
+ expect { @doc.must_be_kind_of Hash }
90
+ expect { @doc['_id'].must_equal 'test-document' }
91
+ expect { @doc['key'].must_equal 'value' }
92
+ expect { @doc['class'].must_equal 'DatabaseTestDocument' }
93
93
  end
94
94
 
95
- context "retrieving multiple documents" do
95
+ describe "retrieving multiple documents" do
96
96
  before do
97
97
  docs = [{"_id"=>"a"},{"_id"=>"b"},{"_id"=>"c"}].map{|d| d.update('class' => 'DatabaseTestDocument')}
98
98
  RestClient.post("#{@db.uri}/_bulk_docs", {"docs"=>docs}.to_json)
99
99
  end
100
100
 
101
- expect { @db.get(%w(a b c)).size.will == 3 }
102
- expect { @db.get(%w(a b c)).all?{|doc| doc.is_a?(DatabaseTestDocument)}.will == true }
101
+ expect { @db.get(%w(a b c)).size.must_equal 3 }
102
+ expect { @db.get(%w(a b c)).each{|doc| doc.must_be_kind_of DatabaseTestDocument} }
103
103
  end
104
104
  end
105
105
 
106
- context "saving docs" do
106
+ describe "saving docs" do
107
107
  before do
108
108
  reset_db
109
109
  @db = DatabaseTest.new('exegesis-test')
110
110
  end
111
111
 
112
- context "a single doc" do
112
+ describe "a single doc" do
113
113
  before { @doc = {'foo' => 'bar'} }
114
114
 
115
- context "without an id" do
115
+ describe "without an id" do
116
116
  before do
117
117
  @db.save(@doc)
118
118
  @rdoc = @db.get(@doc['_id'])
119
119
  end
120
- expect { @doc['_rev'].will == @rdoc['_rev'] }
121
- expect { @rdoc['foo'].will == @doc['foo'] }
120
+ expect { @doc['_rev'].must_equal @rdoc['_rev'] }
121
+ expect { @rdoc['foo'].must_equal @doc['foo'] }
122
122
  end
123
123
 
124
- context "with an id" do
124
+ describe "with an id" do
125
125
  before { @doc['_id'] = 'test-document' }
126
126
 
127
- context "when the document doesn't exist yet" do
127
+ describe "when the document doesn't exist yet" do
128
128
  before do
129
129
  @db.save(@doc)
130
130
  @rdoc = @db.get('test-document')
131
131
  end
132
- expect { @doc['_rev'].will == @rdoc['_rev'] }
133
- expect { @rdoc['foo'].will == @doc['foo'] }
132
+ expect { @doc['_rev'].must_equal @rdoc['_rev'] }
133
+ expect { @rdoc['foo'].must_equal @doc['foo'] }
134
134
  end
135
135
 
136
- context "when the document exists already" do
136
+ describe "when the document exists already" do
137
137
  before do
138
138
  response = @db.post(@doc)
139
139
  @doc['_id'] = response['id']
@@ -141,18 +141,18 @@ class ExegesisDatabaseTest < Test::Unit::TestCase
141
141
  @doc['foo'] = 'bee'
142
142
  end
143
143
 
144
- expect { lambda { @db.save(@doc) }.wont raise_error }
144
+ expect { @db.save(@doc)['_rev'].must_match /2-\d+/ }
145
145
 
146
- context "without a valid rev" do
146
+ describe "without a valid rev" do
147
147
  before { @doc.delete('_rev') }
148
- expect { lambda { @db.save(@doc) }.will raise_error }
148
+ expect { lambda{ @db.save(@doc) }.must_raise RestClient::RequestFailed }
149
149
  end
150
150
  end
151
151
 
152
152
  end
153
153
  end
154
154
 
155
- context "multiple docs" do
155
+ describe "multiple docs" do
156
156
  before do
157
157
  @updated = @db.post({'_id' => 'updated', 'key' => 'original'})
158
158
  @deleted = @db.post({'_id' => 'deleted', 'key' => 'original'})
@@ -165,53 +165,53 @@ class ExegesisDatabaseTest < Test::Unit::TestCase
165
165
  }
166
166
  end
167
167
 
168
- context "without conflicts" do
168
+ describe "without conflicts" do
169
169
  before { @saving.call }
170
- expect { @db.get('new')['key'].will == 'new' }
171
- expect { @db.get('updated')['key'].will == 'new' }
172
- expect { lambda {@db.get('deleted')}.will raise_error(RestClient::ResourceNotFound) }
170
+ expect { @db.get('new')['key'].must_equal 'new' }
171
+ expect { @db.get('updated')['key'].must_equal 'new' }
172
+ expect { lambda {@db.get('deleted')}.must_raise RestClient::ResourceNotFound }
173
173
  end
174
174
  end
175
175
  end
176
176
 
177
- context "setting the designs directory" do
178
- expect { DatabaseTest.designs_directory.will == Pathname.new('designs') }
179
- expect { CustomDesignDirDatabaseTest.designs_directory.will == Pathname.new('app/designs') }
177
+ describe "setting the designs directory" do
178
+ expect { DatabaseTest.designs_directory.must_equal Pathname.new('designs') }
179
+ expect { CustomDesignDirDatabaseTest.designs_directory.must_equal Pathname.new('app/designs') }
180
180
  end
181
181
 
182
- context "with a named document" do
183
- context "that doesn't exist yet" do
182
+ describe "with a named document" do
183
+ describe "that doesn't exist yet" do
184
184
  before do
185
185
  reset_db
186
186
  @db = NamedDocumentDatabaseTest.new('exegesis-test')
187
+ @db.settings
187
188
  end
188
189
 
189
- expect { @db.settings.kind_of?(NamedDocumentDatabaseTest::Settings).will == true }
190
- expect { @db.settings.rev.will =~ /1-\d{7,12}/ }
191
- expect { @db.settings.respond_to?(:things).will == true }
192
- expect { @db.settings; lambda{ @db.get('settings') }.wont raise_error(RestClient::ResourceNotFound) }
190
+ expect { @db.settings.must_be_kind_of NamedDocumentDatabaseTest::Settings }
191
+ expect { @db.settings.rev.must_match /1-\d{7,12}/ }
192
+ expect { @db.settings.must_respond_to :things }
193
+ expect { @db.get('settings').must_be_kind_of NamedDocumentDatabaseTest::Settings }
193
194
  end
194
195
 
195
- context "that does exist" do
196
+ describe "that does exist" do
196
197
  before do
197
198
  reset_db
198
199
  @db = NamedDocumentDatabaseTest.new('exegesis-test')
199
200
  @doc = @db.save({'_id' => 'settings', 'things' => %w(foo bar baz), 'class' => 'NamedDocumentDatabaseTest::Settings'})
200
201
  end
201
202
 
202
- expect { lambda { @db.get('settings') }.wont raise_error(RestClient::ResourceNotFound) }
203
- expect { @db.settings.rev.will == @doc['_rev'] }
204
- expect { @db.settings.rev.will =~ /1-\d{7,12}/ }
205
- expect { @db.settings.things.will == %w(foo bar baz) }
203
+ expect { @db.settings.rev.must_equal @doc['_rev'] }
204
+ expect { @db.settings.rev.must_match /1-\d{7,12}/ }
205
+ expect { @db.settings.things.must_equal %w(foo bar baz) }
206
206
  end
207
207
 
208
- context "when the declaration does not have a block" do
208
+ describe "when the declaration does not have a block" do
209
209
  before do
210
210
  reset_db
211
211
  @db = NamedDocumentWithoutBlockDatabaseTest.new('exegesis-test')
212
212
  end
213
213
 
214
- expect { @db.blah.kind_of?(NamedDocumentWithoutBlockDatabaseTest::Blah).will == true }
214
+ expect { @db.blah.must_be_kind_of NamedDocumentWithoutBlockDatabaseTest::Blah }
215
215
  end
216
216
  end
217
217