diff --git a/lib/miro/dominant_colors.rb b/lib/miro/dominant_colors.rb index a665ec8..028beb5 100644 --- a/lib/miro/dominant_colors.rb +++ b/lib/miro/dominant_colors.rb @@ -24,7 +24,7 @@ def to_rgba sorted_pixels.collect { |pixel| ChunkyPNG::Color.to_truecolor_alpha_bytes(pixel) } end - def to_hsl + def to_hsl histogram.map { |item| item[1].to_hsl.to_a } if Miro.histogram? end @@ -48,14 +48,15 @@ def sorted_pixels end def histogram - @histogram ||= downsample_and_histogram.sort_by { |item| item[0] }.reverse + @histogram ||= downsample_and_histogram.sort_by { |item| item[0] }.reverse end + private def downsample_and_histogram @source_image = open_source_image - hstring = Terrapin::CommandLine.new(Miro.options[:image_magick_path], image_magick_params). - run(:in => Shellwords.escape(File.expand_path(@source_image.path)), + hstring = Terrapin::CommandLine.new(Miro.options[:image_magick_path], image_magick_params) + .run(:in => Shellwords.escape(File.expand_path(@source_image.path)), :resolution => Miro.options[:resolution], :colors => Miro.options[:color_count].to_s, :quantize => Miro.options[:quantize]) @@ -94,7 +95,7 @@ def open_source_image original_extension = @image_type || URI.parse(@src_image_path).path.split('.').last tempfile = Tempfile.open(["source", ".#{original_extension}"]) - remote_file_data = open(@src_image_path).read + remote_file_data = URI.parse(@src_image_path).read tempfile.write(should_force_encoding? ? remote_file_data.force_encoding("UTF-8") : remote_file_data) tempfile.close diff --git a/miro.gemspec b/miro.gemspec index 0effb34..3caf3db 100644 --- a/miro.gemspec +++ b/miro.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |gem| gem.add_dependency "oily_png" if RUBY_ENGINE != "jruby" gem.add_development_dependency "rspec" - gem.add_development_dependency "fakeweb" + gem.add_development_dependency "webmock" gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.files = `git ls-files`.split("\n") diff --git a/spec/miro/dominant_colors_spec.rb b/spec/miro/dominant_colors_spec.rb index 4497cd5..27e6a26 100644 --- a/spec/miro/dominant_colors_spec.rb +++ b/spec/miro/dominant_colors_spec.rb @@ -102,6 +102,7 @@ before do subject.stub(:open_downsampled_image).and_return(mock_downsampled_image) Tempfile.stub(:open).and_return(mock_source_image) + WebMock.stub_request(:get, 'http://domain.com/to/image.jpg').to_return(status: 200, body: 'image data') end it "opens for the file resource" do @@ -202,7 +203,7 @@ it "should be #00FF02 at the first element" do subject.to_hex.first.should == hex_colors.first end - it "should be #8F0074 at the first element" do + it "should be #8F0074 at the last element" do subject.to_hex.last.should == hex_colors.last end it "should have the right values" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 02339da..8c98a17 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,12 +6,10 @@ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration # require 'miro' -require 'fakeweb' +require 'webmock/rspec' RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true config.filter_run :focus end - -FakeWeb.register_uri(:get, "http://domain.com/to/image.jpg", :body => "image data")