spec/spec_helper.rb in cloudinary-1.9.1 vs spec/spec_helper.rb in cloudinary-1.10.0
- old
+ new
@@ -1,13 +1,15 @@
require 'rspec'
require 'rexml/parsers/ultralightparser'
+require 'nokogiri'
require 'rspec/version'
require 'rest_client'
require 'cloudinary'
Cloudinary.config.enhance_image_tag = true
+DUMMY_CLOUD = "test123"
TEST_IMAGE_URL = "http://cloudinary.com/images/old_logo.png"
TEST_IMG = "spec/logo.png"
TEST_IMG_W = 241
TEST_IMG_H = 51
SUFFIX = ENV['TRAVIS_JOB_ID'] || rand(999999999).to_s
@@ -15,12 +17,19 @@
TIMESTAMP_TAG = "#{TEST_TAG}_#{SUFFIX}_#{RUBY_VERSION}_#{ defined? Rails::version ? Rails::version : 'no_rails'}"
# Auth token
KEY = "00112233FF99"
ALT_KEY = "CCBB2233FF00"
+CACHE_KEY = "some_key" + SUFFIX
+module ResponsiveTest
+ TRANSFORMATION = {:angle => 45, :crop => "scale"}
+ FORMAT = "png"
+ IMAGE_BP_VALUES = [206, 50]
+ BREAKPOINTS = [100, 200, 300, 399]
+end
Dir[File.join(File.dirname(__FILE__), '/support/**/*.rb')].each {|f| require f}
module RSpec
def self.project_root
File.join(File.dirname(__FILE__), '..')
@@ -39,11 +48,17 @@
RSpec.shared_context "cleanup" do |tag|
tag ||= TEST_TAG
after :all do
Cloudinary::Api.delete_resources_by_tag(tag) unless Cloudinary.config.keep_test_products
end
+end
+module Cloudinary
+ def self.reset_config
+ @@config = nil
+ end
+
end
CALLS_SERVER_WITH_PARAMETERS = "calls server with parameters"
RSpec.shared_examples CALLS_SERVER_WITH_PARAMETERS do |expected|
@@ -55,42 +70,48 @@
/<#{tag}([\s]+([-[:word:]]+)[\s]*\=\s*\"([^\"]*)\")*\s*>.*<\s*\/#{tag}\s*>/
end
# Represents an HTML tag
class TestTag
- attr_accessor :name, :attributes, :children, :text, :html_string
+ attr_accessor :element
# Creates a new +TestTag+ from a given +element+ string
def initialize(element)
@html_string = element
- element = valid_tag(element) unless element.is_a? Array
- case element[0]
- when :start_element
- @name = element[2]
- @attributes = element[3]
- @children = (Array(element[4..-1]) || []).map {|c | TestTag.new c}
- when :text
- @text = element[1]
- @name = "text"
- @attributes = []
- @children = []
- end
+ @element = valid_tag(element) unless element.is_a? Array
end
+ def name
+ @element.name
+ end
+
+ def attributes
+ @element.attributes
+ end
+
+ def children
+ @element.children
+ end
# Parses a given +tag+ in string format
def valid_tag(tag)
- parser = REXML::Parsers::UltraLightParser.new( tag)
- parser.parse[0]
+ parser = Nokogiri::HTML::Document.parse( tag)
+ # Parsed code will be strctured as either html>body>tag or html>head>tag
+ parser.children[1].children[0].children[0]
end
# Returns attribute named +symbol_or_string+
def [](symbol_or_string)
- attributes[symbol_or_string.to_s]
+ begin
+ attributes[symbol_or_string.to_s].value
+ rescue
+ nil
+ end
end
def method_missing(symbol, *args)
if (m = /children_by_(\w+)/.match(symbol.to_s)) and !args.empty?
- @children.select{ |c| c[m[1]] == args[0]}
+ return unless children
+ children.select{ |c| c[m[1]] == args[0]}
else
super
end
end
\ No newline at end of file