Skip to content

Instantly share code, notes, and snippets.

@schnittchen
Last active December 15, 2015 00:28
Show Gist options
  • Save schnittchen/5172905 to your computer and use it in GitHub Desktop.
Save schnittchen/5172905 to your computer and use it in GitHub Desktop.
Make view specs fail when image_tag is used for a non-existing asset
config.before(:each) do
if self.class.metadata[:type] == :view
view.singleton_class.send :alias_method, :original_image_tag, :image_tag
view.singleton_class.send :define_method, :image_tag do |path, options = {}|
normalized_path = path_to_image(path.to_s)
asset_paths = Sprockets::Helpers::RailsHelper::AssetPaths.new(nil) # hack: easy access to is_uri?
unless asset_paths.is_uri?(normalized_path)
normalized_path = normalized_path[asset_prefix.length+1..-1]
unless Rails.application.assets.find_asset(normalized_path) or path.respond_to?(:stubbed?)
message = "image_tag called for non-existing asset '#{path}'.\n" \
"Make its first argument respond to :stubbed? if it is a stubbed path"
raise message
end
end
original_image_tag path, options
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment