diff --git a/carrierwave-data-uri.gemspec b/carrierwave-data-uri.gemspec index 5aeb0e3..6caa6b4 100644 --- a/carrierwave-data-uri.gemspec +++ b/carrierwave-data-uri.gemspec @@ -22,4 +22,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '~> 1.7' spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'rspec' + spec.add_development_dependency 'activerecord' end diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb new file mode 100644 index 0000000..9c53f20 --- /dev/null +++ b/spec/parser_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +RSpec.describe CarrierWave::DataUri::Parser do + let(:data_uri) do + 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==' + end + + describe 'initialization' do + it 'should raise error when data is invalid' do + expect { CarrierWave::DataUri::Parser.new 'invadli_data' }.to raise_error + end + + it 'should parse data on init' do + parsed = CarrierWave::DataUri::Parser.new data_uri + + expect(parsed.extension).to eql 'gif' + end + end + + describe '#to_file' do + it 'should generate temp file based on data' do + parsed = CarrierWave::DataUri::Parser.new data_uri + file = parsed.to_file + + expect(file).to be_a_kind_of Tempfile + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..3482948 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'bundler/setup' +Bundler.setup + +require 'carrierwave-data-uri'