Last active
December 15, 2015 00:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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