Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove UploadableIO shared example

  • Loading branch information...
commit 0787ba413e4ae72fd35e30cbbd8633077e9bf99b 1 parent 9475e53
@arsduo authored
View
71 spec/lib/uploadable_io_spec.rb
@@ -25,6 +25,77 @@ def sinatra_mocks
{:type => "type", :tempfile => "Tempfile", :filename => "foo.bar"}
end
+ shared_examples_for "MIME::Types can't return results" do
+ {
+ "jpg" => "image/jpeg",
+ "jpeg" => "image/jpeg",
+ "png" => "image/png",
+ "gif" => "image/gif"
+ }.each_pair do |extension, mime_type|
+ it "should properly get content types for #{extension} using basic analysis" do
+ path = "filename.#{extension}"
+ if @koala_io_params[0].is_a?(File)
+ @koala_io_params[0].stub!(:path).and_return(path)
+ else
+ @koala_io_params[0] = path
+ end
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should == mime_type
+ end
+
+ it "should get content types for #{extension} using basic analysis with file names with more than one dot" do
+ path = "file.name.#{extension}"
+ if @koala_io_params[0].is_a?(File)
+ @koala_io_params[0].stub!(:path).and_return(path)
+ else
+ @koala_io_params[0] = path
+ end
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should == mime_type
+ end
+ end
+
+ describe "if the MIME type can't be determined" do
+ before :each do
+ path = "badfile.badextension"
+ if @koala_io_params[0].is_a?(File)
+ @koala_io_params[0].stub!(:path).and_return(path)
+ else
+ @koala_io_params[0] = path
+ end
+ end
+
+ it "should throw an exception" do
+ lambda { Koala::UploadableIO.new(*@koala_io_params) }.should raise_exception(Koala::KoalaError)
+ end
+ end
+ end
+
+ shared_examples_for "determining a mime type" do
+ describe "if MIME::Types is available" do
+ it "should return an UploadIO with MIME::Types-determined type if the type exists" do
+ type_result = ["type"]
+ Koala::MIME::Types.stub(:type_for).and_return(type_result)
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should == type_result.first
+ end
+ end
+
+ describe "if MIME::Types is unavailable" do
+ before :each do
+ # fake that MIME::Types doesn't exist
+ Koala::MIME::Types.stub(:type_for).and_raise(NameError)
+ end
+ it_should_behave_like "MIME::Types can't return results"
+ end
+
+ describe "if MIME::Types can't find the result" do
+ before :each do
+ # fake that MIME::Types doesn't exist
+ Koala::MIME::Types.stub(:type_for).and_return([])
+ end
+
+ it_should_behave_like "MIME::Types can't return results"
+ end
+ end
+
describe "the constructor" do
describe "when given a file path" do
before(:each) do
View
1  spec/spec_helper.rb
@@ -40,6 +40,5 @@
# load supporting files for our tests
require 'support/rest_api_shared_examples'
-require 'support/uploadable_io_shared_examples'
BEACH_BALL_PATH = File.join(File.dirname(__FILE__), "fixtures", "beach.jpg")
View
70 spec/support/uploadable_io_shared_examples.rb
@@ -1,70 +0,0 @@
-shared_examples_for "MIME::Types can't return results" do
- {
- "jpg" => "image/jpeg",
- "jpeg" => "image/jpeg",
- "png" => "image/png",
- "gif" => "image/gif"
- }.each_pair do |extension, mime_type|
- it "should properly get content types for #{extension} using basic analysis" do
- path = "filename.#{extension}"
- if @koala_io_params[0].is_a?(File)
- @koala_io_params[0].stub!(:path).and_return(path)
- else
- @koala_io_params[0] = path
- end
- Koala::UploadableIO.new(*@koala_io_params).content_type.should == mime_type
- end
-
- it "should get content types for #{extension} using basic analysis with file names with more than one dot" do
- path = "file.name.#{extension}"
- if @koala_io_params[0].is_a?(File)
- @koala_io_params[0].stub!(:path).and_return(path)
- else
- @koala_io_params[0] = path
- end
- Koala::UploadableIO.new(*@koala_io_params).content_type.should == mime_type
- end
- end
-
- describe "if the MIME type can't be determined" do
- before :each do
- path = "badfile.badextension"
- if @koala_io_params[0].is_a?(File)
- @koala_io_params[0].stub!(:path).and_return(path)
- else
- @koala_io_params[0] = path
- end
- end
-
- it "should throw an exception" do
- lambda { Koala::UploadableIO.new(*@koala_io_params) }.should raise_exception(Koala::KoalaError)
- end
- end
-end
-
-shared_examples_for "determining a mime type" do
- describe "if MIME::Types is available" do
- it "should return an UploadIO with MIME::Types-determined type if the type exists" do
- type_result = ["type"]
- Koala::MIME::Types.stub(:type_for).and_return(type_result)
- Koala::UploadableIO.new(*@koala_io_params).content_type.should == type_result.first
- end
- end
-
- describe "if MIME::Types is unavailable" do
- before :each do
- # fake that MIME::Types doesn't exist
- Koala::MIME::Types.stub(:type_for).and_raise(NameError)
- end
- it_should_behave_like "MIME::Types can't return results"
- end
-
- describe "if MIME::Types can't find the result" do
- before :each do
- # fake that MIME::Types doesn't exist
- Koala::MIME::Types.stub(:type_for).and_return([])
- end
-
- it_should_behave_like "MIME::Types can't return results"
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.