Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Organize tests a bit

  • Loading branch information...
commit 133ee5c3cb5ef3671def3e0c7309df228c0afd95 1 parent 7d63fb0
@bmarini bmarini authored ches committed
Showing with 97 additions and 87 deletions.
  1. +1 −1  test/caching_test.rb
  2. +96 −0 test/config_test.rb
  3. +0 −86 test/gridfs_test.rb
View
2  test/caching_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class Rack::GridFSTest < Test::Unit::TestCase
+class CachingTest < Test::Unit::TestCase
include Rack::Test::Methods
include Rack::GridFS::Test::Methods
View
96 test/config_test.rb
@@ -0,0 +1,96 @@
+require 'test_helper'
+
+class ConfigTest < Test::Unit::TestCase
+ include Rack::Test::Methods
+ include Rack::GridFS::Test::Methods
+
+ context "Rack::GridFS" do
+ context "on initialization" do
+
+ setup do
+ stub_mongodb_connection
+ @options = {
+ :hostname => 'myhostname.mydomain',
+ :port => 8765,
+ :database => 'mydatabase',
+ :prefix => 'myprefix',
+ :username => 'bob',
+ :password => 'so-s3cur3'
+ }
+ end
+
+ should "have a hostname option" do
+ mware = Rack::GridFS::Endpoint.new(@options)
+ assert_equal @options[:hostname], mware.instance_variable_get(:@hostname)
+ end
+
+ should "have a default hostname" do
+ mware = Rack::GridFS::Endpoint.new(@options.except(:hostname))
+ assert_equal 'localhost', mware.instance_variable_get(:@hostname)
+ end
+
+ should "have a port option" do
+ mware = Rack::GridFS::Endpoint.new(@options)
+ assert_equal @options[:port], mware.instance_variable_get(:@port)
+ end
+
+ should "have a default port" do
+ mware = Rack::GridFS::Endpoint.new(@options.except(:port))
+ assert_equal Mongo::Connection::DEFAULT_PORT, mware.instance_variable_get(:@port)
+ end
+
+ should "have a database option" do
+ mware = Rack::GridFS::Endpoint.new(@options)
+ assert_equal @options[:database], mware.instance_variable_get(:@database)
+ end
+
+ should "not have a default database" do
+ mware = Rack::GridFS::Endpoint.new(@options.except(:database))
+ assert_nil mware.instance_variable_get(:@database)
+ end
+
+ should "have a prefix option" do
+ mware = Rack::GridFS.new(nil, @options)
+ assert_equal mware.instance_variable_get(:@options)[:prefix], 'myprefix'
+ end
+
+ should "have a default prefix" do
+ mware = Rack::GridFS.new(nil, @options.except(:prefix))
+ assert_equal mware.instance_variable_get(:@options)[:prefix], 'gridfs'
+ end
+
+ should "have a normalize prefix" do
+ mware = Rack::GridFS.new(nil, @options.merge({:prefix => '/myprefix'}))
+ assert_equal mware.instance_variable_get(:@options)[:prefix], 'myprefix'
+ end
+
+ should "have a username option" do
+ mware = Rack::GridFS::Endpoint.new(@options)
+ assert_equal @options[:username], mware.instance_variable_get(:@username)
+ end
+
+ should "have a password option" do
+ mware = Rack::GridFS::Endpoint.new(@options)
+ assert_equal @options[:password], mware.instance_variable_get(:@password)
+ end
+
+ should "not have a default username" do
+ mware = Rack::GridFS::Endpoint.new(@options.except(:username))
+ assert_nil mware.instance_variable_get(:@username)
+ end
+
+ should "not have a default password" do
+ mware = Rack::GridFS::Endpoint.new(@options.except(:password))
+ assert_nil mware.instance_variable_get(:@password)
+ end
+
+ should "connect to the MongoDB server" do
+ Rack::GridFS::Endpoint.any_instance.expects(:connect!).returns(true).once
+ Rack::GridFS::Endpoint.new(@options).db
+ end
+
+ end
+ end
+
+end
+
View
86 test/gridfs_test.rb
@@ -20,92 +20,6 @@ def app; setup_app end
assert_equal file2.filename, file3.filename
end
- context "on initialization" do
-
- setup do
- stub_mongodb_connection
- @options = {
- :hostname => 'myhostname.mydomain',
- :port => 8765,
- :database => 'mydatabase',
- :prefix => 'myprefix',
- :username => 'bob',
- :password => 'so-s3cur3'
- }
- end
-
- should "have a hostname option" do
- mware = Rack::GridFS::Endpoint.new(@options)
- assert_equal @options[:hostname], mware.instance_variable_get(:@hostname)
- end
-
- should "have a default hostname" do
- mware = Rack::GridFS::Endpoint.new(@options.except(:hostname))
- assert_equal 'localhost', mware.instance_variable_get(:@hostname)
- end
-
- should "have a port option" do
- mware = Rack::GridFS::Endpoint.new(@options)
- assert_equal @options[:port], mware.instance_variable_get(:@port)
- end
-
- should "have a default port" do
- mware = Rack::GridFS::Endpoint.new(@options.except(:port))
- assert_equal Mongo::Connection::DEFAULT_PORT, mware.instance_variable_get(:@port)
- end
-
- should "have a database option" do
- mware = Rack::GridFS::Endpoint.new(@options)
- assert_equal @options[:database], mware.instance_variable_get(:@database)
- end
-
- should "not have a default database" do
- mware = Rack::GridFS::Endpoint.new(@options.except(:database))
- assert_nil mware.instance_variable_get(:@database)
- end
-
- should "have a prefix option" do
- mware = Rack::GridFS.new(nil, @options)
- assert_equal mware.instance_variable_get(:@options)[:prefix], 'myprefix'
- end
-
- should "have a default prefix" do
- mware = Rack::GridFS.new(nil, @options.except(:prefix))
- assert_equal mware.instance_variable_get(:@options)[:prefix], 'gridfs'
- end
-
- should "have a normalize prefix" do
- mware = Rack::GridFS.new(nil, @options.merge({:prefix => '/myprefix'}))
- assert_equal mware.instance_variable_get(:@options)[:prefix], 'myprefix'
- end
-
- should "have a username option" do
- mware = Rack::GridFS::Endpoint.new(@options)
- assert_equal @options[:username], mware.instance_variable_get(:@username)
- end
-
- should "have a password option" do
- mware = Rack::GridFS::Endpoint.new(@options)
- assert_equal @options[:password], mware.instance_variable_get(:@password)
- end
-
- should "not have a default username" do
- mware = Rack::GridFS::Endpoint.new(@options.except(:username))
- assert_nil mware.instance_variable_get(:@username)
- end
-
- should "not have a default password" do
- mware = Rack::GridFS::Endpoint.new(@options.except(:password))
- assert_nil mware.instance_variable_get(:@password)
- end
-
- should "connect to the MongoDB server" do
- Rack::GridFS::Endpoint.any_instance.expects(:connect!).returns(true).once
- Rack::GridFS::Endpoint.new(@options).db
- end
-
- end
-
should "delegate requests with a non-matching prefix" do
%w( / /posts /posts/1 /posts/1/comments ).each do |path|
get path
Please sign in to comment.
Something went wrong with that request. Please try again.