Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active August 29, 2015 14:22
Show Gist options
  • Save henrik/39a7d1e0cf4694d6b5ad to your computer and use it in GitHub Desktop.
Save henrik/39a7d1e0cf4694d6b5ad to your computer and use it in GitHub Desktop.
describe MyPresenter, "#my_method" do
let(:view) { helper_instance }
it "works" do
actual = MyPresenter.new("whatever").my_method(view)
expect(actual).to include "whatever"
end
end
module MiscHelpers
def helper_instance(helper_module = nil)
Class.new {
include helper_module if helper_module
include FakeHelpers
}.new
end
module FakeHelpers
def capture
@concatenated = []
yielded = yield
@concatenated << yielded if yielded.is_a?(String)
@concatenated.join
end
def concat(something)
@concatenated << something
end
def tag(name)
"<#{name}>"
end
def content_tag(name, value_or_attributes, opts={}, &block)
if block_given?
attributes = value_or_attributes.map { |n, v| %{#{n}="#{v}"} }.join(" ")
attributes = attributes.present? ? " #{attributes}" : ""
value = yield
else
attributes = nil
value = value_or_attributes
end
"<#{name}#{attributes}>#{value}</#{name}>"
end
def link_to(name, url, html_opts = nil)
"<a href='#{url}'>#{name}</a>"
end
def mail_to(email)
"<a href='mailto:#{email}'>#{email}</a>"
end
def asset_path(file)
"/assets/#{file}"
end
def simple_format(text)
"<p>%s</p>" % text.gsub("\n", "<br>")
end
def truncate(text, opts = {})
text
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment