Skip to content
Browse files

split up the tests

  • Loading branch information...
1 parent 54a4193 commit 865418dda84eb7a36ef0f4ced10fef21e98a54e2 @janxious janxious committed Mar 14, 2012
View
13 Rakefile
@@ -0,0 +1,13 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+require "rake/testtask"
+
+desc "Default: run unit tests."
+task :default => :test
+
+desc "Test the eb-patches gem"
+Rake::TestTask.new(:test) do |t|
+ t.libs << "test"
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
View
9 test/Gemfile
@@ -1,9 +0,0 @@
-source :rubygems
-
-group :development, :test do
- gem 'httparty', '>=0.4.3'
- gem 'minitest'
- gem 'ruby-debug', :platforms => 'ruby_18'
- gem 'ruby-debug19', :require => 'ruby-debug', :platforms => 'ruby_19'
- gem 'webmock'
-end
View
43 test/Gemfile.lock
@@ -1,43 +0,0 @@
-GEM
- remote: http://rubygems.org/
- specs:
- addressable (2.2.6)
- archive-tar-minitar (0.5.2)
- columnize (0.3.4)
- crack (0.1.8)
- httparty (0.7.8)
- crack (= 0.1.8)
- linecache (0.46)
- rbx-require-relative (> 0.0.4)
- linecache19 (0.5.12)
- ruby_core_source (>= 0.1.4)
- minitest (2.5.1)
- rbx-require-relative (0.0.5)
- ruby-debug (0.10.4)
- columnize (>= 0.1)
- ruby-debug-base (~> 0.10.4.0)
- ruby-debug-base (0.10.4)
- linecache (>= 0.3)
- ruby-debug-base19 (0.11.25)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby_core_source (>= 0.1.4)
- ruby-debug19 (0.11.6)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby-debug-base19 (>= 0.11.19)
- ruby_core_source (0.1.5)
- archive-tar-minitar (>= 0.5.2)
- webmock (1.7.5)
- addressable (~> 2.2, > 2.2.5)
- crack (>= 0.1.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- httparty (>= 0.4.3)
- minitest
- ruby-debug
- ruby-debug19
- webmock
View
50 test/api_key_test.rb
@@ -0,0 +1,50 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class ApiKeyTest < MiniTest::Unit::TestCase
+ describe "test API keys" do
+ before do
+ DocRaptor.default_options.delete :api_key
+ ENV.delete "DOCRAPTOR_API_KEY"
+ @test_key = "Test Key!"
+ end
+
+ it "should throw an error if no api key is provided via a key, set in the environment, or already set on the DocRaptor class object" do
+ assert_raises(DocRaptorError::NoApiKeyProvidedError) {DocRaptor.api_key}
+ end
+
+ it "should read the api key from the ENV" do
+ ENV["DOCRAPTOR_API_KEY"] = @test_key
+ assert_equal @test_key, DocRaptor.api_key
+ end
+
+ it "changes to the ENV variable shouldn't be implicitly picked up" do
+ ENV["DOCRAPTOR_API_KEY"] = @test_key
+ DocRaptor.api_key
+
+ ENV["DOCRAPTOR_API_KEY"] = "some other key"
+ assert_equal @test_key, DocRaptor.api_key
+ end
+
+ it "should use the passed in key" do
+ assert_equal @test_key, DocRaptor.api_key(@test_key)
+ end
+
+ it "should persist the passed in key on subsequent calls" do
+ DocRaptor.api_key(@test_key)
+ assert_equal @test_key, DocRaptor.api_key
+ end
+
+ it "should override keys when passed in explicitly" do
+ other_key = "some other key"
+ DocRaptor.api_key(@test_key)
+ assert_equal other_key, DocRaptor.api_key(other_key)
+ end
+
+ it "should persist overridden keys" do
+ other_key = "some other key"
+ DocRaptor.api_key(@test_key)
+ DocRaptor.api_key(other_key)
+ assert_equal other_key, DocRaptor.api_key
+ end
+ end
+end
View
48 test/create_bang_test.rb
@@ -0,0 +1,48 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class CreateBangTest < MiniTest::Unit::TestCase
+ describe "calling create!" do
+ before do
+ DocRaptor.api_key "something something"
+ end
+
+ describe "with bogus arguments" do
+ it "should raise an error if something other than an options hash is passed in" do
+ assert_raises(ArgumentError) {DocRaptor.create!(true)}
+ assert_raises(ArgumentError) {DocRaptor.create!(nil)}
+ end
+
+ it "should raise an error if document_content and document_url are both unset" do
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!}
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!({:herped => :the_derp})}
+ end
+
+ it "should raise an error if document_content is passed by is blank" do
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_content => nil)}
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_content => "")}
+ end
+
+ it "should raise an error if document_url is passed by is blank" do
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_url => nil)}
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_url => "")}
+ end
+ end
+
+ describe "with document_content" do
+ before do
+ @html_content = "<html><body>Hey</body></html>"
+ end
+
+ it "should give me some error message if pass some invalid content" do
+ invalid_html = "<herp"
+ stub_http_response_with("invalid_pdf", :post, 422)
+ assert_raises(DocRaptorException::DocumentCreationFailure) {DocRaptor.create!(:document_content => invalid_html)}
+ end
+
+ it "should give me a valid response if I pass some valid content" do
+ stub_http_response_with("simple_pdf", :post)
+ assert_equal file_fixture("simple_pdf"), DocRaptor.create!(:document_content => @html_content).body
+ end
+ end
+ end
+end
View
50 test/create_test.rb
@@ -0,0 +1,50 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class CreateTest < MiniTest::Unit::TestCase
+ describe "calling create" do
+ before do
+ DocRaptor.api_key "something something"
+ end
+
+ describe "with bogus arguments" do
+ it "should raise an error if something other than an options hash is passed in" do
+ assert_raises(ArgumentError) {DocRaptor.create(true)}
+ assert_raises(ArgumentError) {DocRaptor.create(nil)}
+ end
+
+ it "should raise an error if document_content and document_url are both unset" do
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create}
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create({:herped => :the_derp})}
+ end
+
+ it "should raise an error if document_content is passed by is blank" do
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_content => nil)}
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_content => "")}
+ end
+
+ it "should raise an error if document_url is passed by is blank" do
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_url => nil)}
+ assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_url => "")}
+ end
+ end
+
+ describe "with document_content" do
+ before do
+ @html_content = "<html><body>Hey</body></html>"
+ end
+
+ it "should give me some error message if pass some invalid content" do
+ invalid_html = "<herp"
+ stub_http_response_with("invalid_pdf", :post, 422)
+ response = DocRaptor.create(:document_content => invalid_html)
+ assert_equal file_fixture("invalid_pdf"), response.body
+ assert_equal 422, response.code
+ end
+
+ it "should give me a valid response if I pass some valid content" do
+ stub_http_response_with("simple_pdf", :post)
+ assert_equal file_fixture("simple_pdf"), DocRaptor.create(:document_content => @html_content).body
+ end
+ end
+ end
+end
View
263 test/doc_raptor_test.rb
@@ -1,257 +1,22 @@
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
-# pull in the docraptor code
-require File.expand_path(File.dirname(__FILE__) + "/../lib/doc_raptor")
-
class DocRaptorTest < MiniTest::Unit::TestCase
-
- describe "test API keys" do
- before do
- DocRaptor.default_options.delete :api_key
- ENV.delete "DOCRAPTOR_API_KEY"
- @test_key = "Test Key!"
- end
-
- it "should throw an error if no api key is provided via a key, set in the environment, or already set on the DocRaptor class object" do
- assert_raises(DocRaptorError::NoApiKeyProvidedError) {DocRaptor.api_key}
- end
-
- it "should read the api key from the ENV" do
- ENV["DOCRAPTOR_API_KEY"] = @test_key
- assert_equal @test_key, DocRaptor.api_key
- end
-
- it "changes to the ENV variable shouldn't be implicitly picked up" do
- ENV["DOCRAPTOR_API_KEY"] = @test_key
- DocRaptor.api_key
-
- ENV["DOCRAPTOR_API_KEY"] = "some other key"
- assert_equal @test_key, DocRaptor.api_key
- end
-
- it "should use the passed in key" do
- assert_equal @test_key, DocRaptor.api_key(@test_key)
- end
-
- it "should persist the passed in key on subsequent calls" do
- DocRaptor.api_key(@test_key)
- assert_equal @test_key, DocRaptor.api_key
- end
-
- it "should override keys when passed in explicitly" do
- other_key = "some other key"
- DocRaptor.api_key(@test_key)
- assert_equal other_key, DocRaptor.api_key(other_key)
- end
-
- it "should persist overridden keys" do
- other_key = "some other key"
- DocRaptor.api_key(@test_key)
- DocRaptor.api_key(other_key)
- assert_equal other_key, DocRaptor.api_key
- end
- end
-
- describe "calling create" do
- before do
- DocRaptor.api_key "something something"
- end
-
- describe "with bogus arguments" do
- it "should raise an error if something other than an options hash is passed in" do
- assert_raises(ArgumentError) {DocRaptor.create(true)}
- assert_raises(ArgumentError) {DocRaptor.create(nil)}
- end
-
- it "should raise an error if document_content and document_url are both unset" do
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create}
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create({:herped => :the_derp})}
- end
-
- it "should raise an error if document_content is passed by is blank" do
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_content => nil)}
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_content => "")}
- end
-
- it "should raise an error if document_url is passed by is blank" do
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_url => nil)}
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create(:document_url => "")}
- end
- end
-
- describe "with document_content" do
- before do
- @html_content = "<html><body>Hey</body></html>"
- end
-
- it "should give me some error message if pass some invalid content" do
- invalid_html = "<herp"
- stub_http_response_with("invalid_pdf", :post, 422)
- response = DocRaptor.create(:document_content => invalid_html)
- assert_equal file_fixture("invalid_pdf"), response.body
- assert_equal 422, response.code
- end
-
- it "should give me a valid response if I pass some valid content" do
- stub_http_response_with("simple_pdf", :post)
- assert_equal file_fixture("simple_pdf"), DocRaptor.create(:document_content => @html_content).body
+ describe "the public interface" do
+ methods = [:api_key,
+ :create,
+ :create!,
+ :list_docs,
+ :list_docs!,
+ :status,
+ :status!,
+ :download,
+ :download!].each do |method_name|
+ it "should respond to #{method_name}" do
+ assert DocRaptor.respond_to?(method_name)
end
end
end
- describe "calling create!" do
- before do
- DocRaptor.api_key "something something"
- end
-
- describe "with bogus arguments" do
- it "should raise an error if something other than an options hash is passed in" do
- assert_raises(ArgumentError) {DocRaptor.create!(true)}
- assert_raises(ArgumentError) {DocRaptor.create!(nil)}
- end
-
- it "should raise an error if document_content and document_url are both unset" do
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!}
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!({:herped => :the_derp})}
- end
-
- it "should raise an error if document_content is passed by is blank" do
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_content => nil)}
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_content => "")}
- end
-
- it "should raise an error if document_url is passed by is blank" do
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_url => nil)}
- assert_raises(DocRaptorError::NoContentError) {DocRaptor.create!(:document_url => "")}
- end
- end
-
- describe "with document_content" do
- before do
- @html_content = "<html><body>Hey</body></html>"
- end
-
- it "should give me some error message if pass some invalid content" do
- invalid_html = "<herp"
- stub_http_response_with("invalid_pdf", :post, 422)
- assert_raises(DocRaptorException::DocumentCreationFailure) {DocRaptor.create!(:document_content => invalid_html)}
- end
-
- it "should give me a valid response if I pass some valid content" do
- stub_http_response_with("simple_pdf", :post)
- assert_equal file_fixture("simple_pdf"), DocRaptor.create!(:document_content => @html_content).body
- end
- end
- end
-
- describe "list_docs" do
- before do
- DocRaptor.api_key "something something"
- end
-
- describe "with bogus arguments" do
- it "should raise an error if something other than an options hash is passed in" do
- assert_raises(ArgumentError) {DocRaptor.list_docs(true)}
- assert_raises(ArgumentError) {DocRaptor.list_docs(nil)}
- end
- end
-
- describe "with good arguments" do
- it "should give me a valid response" do
- stub_http_response_with("simple_list_docs", :get)
- assert_equal file_fixture("simple_list_docs"), DocRaptor.list_docs.body
- end
- end
- end
-
- describe "list_docs!" do
- before do
- DocRaptor.api_key "something something"
- end
-
- describe "with bogus arguments" do
- it "should raise an error if something other than an options hash is passed in" do
- assert_raises(ArgumentError) {DocRaptor.list_docs!(true)}
- assert_raises(ArgumentError) {DocRaptor.list_docs!(nil)}
- end
- end
-
- describe "with good arguments" do
- it "should give me a valid response" do
- stub_http_response_with("simple_list_docs", :get)
- assert_equal file_fixture("simple_list_docs"), DocRaptor.list_docs!.body
- end
-
- it "raise an exception when the list get fails" do
- stub_http_response_with("invalid_list_docs", :get, 422)
- assert_raises(DocRaptorException::DocumentListingFailure) {DocRaptor.list_docs!}
- end
- end
- end
-
- describe "status" do
- before do
- DocRaptor.api_key "something something"
- end
-
- describe "with good arguments" do
- it "should give me a valid response" do
- stub_http_response_with("simple_status", :get)
- DocRaptor.status("test-id")
- end
- end
- end
-
- describe "status!" do
- before do
- DocRaptor.api_key "something something"
- end
-
- describe "with good arguments" do
- it "should give me a valid response" do
- stub_http_response_with("simple_status", :get)
- DocRaptor.status!("test-id")
- end
- end
-
- describe "with invalid arguments" do
- it "should raise an exception" do
- stub_http_response_with("invalid_status", :get, 403)
- assert_raises(DocRaptorException::DocumentStatusFailure) {DocRaptor.status!("test-id")}
- end
- end
- end
-
- describe "download" do
- before do
- DocRaptor.api_key "something something"
- end
-
- describe "with good arguments" do
- it "should give me a valid response" do
- stub_http_response_with("simple_download", :get)
- DocRaptor.download("test-id")
- end
- end
- end
-
- describe "download!" do
- before do
- DocRaptor.api_key "something something"
- end
-
- describe "with good arguments" do
- it "should give me a valid response" do
- stub_http_response_with("simple_download", :get)
- DocRaptor.download!("test-id")
- end
- end
-
- describe "with invalid arguments" do
- it "should raise an exception" do
- stub_http_response_with("invalid_download", :get, 400)
- assert_raises(DocRaptorException::DocumentDownloadFailure) {DocRaptor.download!("test-id")}
- end
- end
- end
+ # TODO basic tests of the various exception/error classes beyond
+ # what is used in the gem functionality tests
end
View
23 test/download_bang_test.rb
@@ -0,0 +1,23 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class DownloadBangTest < MiniTest::Unit::TestCase
+ describe "download!" do
+ before do
+ DocRaptor.api_key "something something"
+ end
+
+ describe "with good arguments" do
+ it "should give me a valid response" do
+ stub_http_response_with("simple_download", :get)
+ DocRaptor.download!("test-id")
+ end
+ end
+
+ describe "with invalid arguments" do
+ it "should raise an exception" do
+ stub_http_response_with("invalid_download", :get, 400)
+ assert_raises(DocRaptorException::DocumentDownloadFailure) {DocRaptor.download!("test-id")}
+ end
+ end
+ end
+end
View
16 test/download_test.rb
@@ -0,0 +1,16 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class DownloadTest < MiniTest::Unit::TestCase
+ describe "download" do
+ before do
+ DocRaptor.api_key "something something"
+ end
+
+ describe "with good arguments" do
+ it "should give me a valid response" do
+ stub_http_response_with("simple_download", :get)
+ DocRaptor.download("test-id")
+ end
+ end
+ end
+end
View
28 test/list_docs_bang_test.rb
@@ -0,0 +1,28 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class ListDocsBangTest < MiniTest::Unit::TestCase
+describe "list_docs!" do
+ before do
+ DocRaptor.api_key "something something"
+ end
+
+ describe "with bogus arguments" do
+ it "should raise an error if something other than an options hash is passed in" do
+ assert_raises(ArgumentError) {DocRaptor.list_docs!(true)}
+ assert_raises(ArgumentError) {DocRaptor.list_docs!(nil)}
+ end
+ end
+
+ describe "with good arguments" do
+ it "should give me a valid response" do
+ stub_http_response_with("simple_list_docs", :get)
+ assert_equal file_fixture("simple_list_docs"), DocRaptor.list_docs!.body
+ end
+
+ it "raise an exception when the list get fails" do
+ stub_http_response_with("invalid_list_docs", :get, 422)
+ assert_raises(DocRaptorException::DocumentListingFailure) {DocRaptor.list_docs!}
+ end
+ end
+ end
+end
View
23 test/list_docs_test.rb
@@ -0,0 +1,23 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class ListDocsTest < MiniTest::Unit::TestCase
+ describe "list_docs" do
+ before do
+ DocRaptor.api_key "something something"
+ end
+
+ describe "with bogus arguments" do
+ it "should raise an error if something other than an options hash is passed in" do
+ assert_raises(ArgumentError) {DocRaptor.list_docs(true)}
+ assert_raises(ArgumentError) {DocRaptor.list_docs(nil)}
+ end
+ end
+
+ describe "with good arguments" do
+ it "should give me a valid response" do
+ stub_http_response_with("simple_list_docs", :get)
+ assert_equal file_fixture("simple_list_docs"), DocRaptor.list_docs.body
+ end
+ end
+ end
+end
View
23 test/status_bang_test.rb
@@ -0,0 +1,23 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class StatusBangTest < MiniTest::Unit::TestCase
+ describe "status!" do
+ before do
+ DocRaptor.api_key "something something"
+ end
+
+ describe "with good arguments" do
+ it "should give me a valid response" do
+ stub_http_response_with("simple_status", :get)
+ DocRaptor.status!("test-id")
+ end
+ end
+
+ describe "with invalid arguments" do
+ it "should raise an exception" do
+ stub_http_response_with("invalid_status", :get, 403)
+ assert_raises(DocRaptorException::DocumentStatusFailure) {DocRaptor.status!("test-id")}
+ end
+ end
+ end
+end
View
16 test/status_test.rb
@@ -0,0 +1,16 @@
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
+
+class StatusTest < MiniTest::Unit::TestCase
+ describe "status" do
+ before do
+ DocRaptor.api_key "something something"
+ end
+
+ describe "with good arguments" do
+ it "should give me a valid response" do
+ stub_http_response_with("simple_status", :get)
+ DocRaptor.status("test-id")
+ end
+ end
+ end
+end
View
3 test/test_helper.rb
@@ -7,6 +7,9 @@
require 'minitest/mock'
require 'webmock/minitest'
+# pull in the docraptor code
+require File.expand_path(File.dirname(__FILE__) + "/../lib/doc_raptor")
+
class MiniTest::Unit::TestCase
def stub_http_response_with(filename, method = :any, status = 200)
format = filename.split('.').last.intern

0 comments on commit 865418d

Please sign in to comment.
Something went wrong with that request. Please try again.