Skip to content

Instantly share code, notes, and snippets.

@jkarmel
Created July 17, 2014 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkarmel/ca7ed14a34f33b28ce69 to your computer and use it in GitHub Desktop.
Save jkarmel/ca7ed14a34f33b28ce69 to your computer and use it in GitHub Desktop.
# A sample Gemfile
source "https://rubygems.org"
# gem "rails"
gem 'haml'
require 'haml'
class Scope
attr_accessor :locals
def initialize
self.locals = {}
end
def method_missing name, *args, &block
puts block.nil?
self.locals[name] = block.call
end
end
def render template, &block
engine = Haml::Engine.new template
scope = Scope.new
scope.instance_eval &block
engine.render Object.new, scope.locals
end
require 'minitest/autorun'
# Load in your class to be tested
#require 'things'
require './poc'
class TKTest < Minitest::Test
@object_html = "<img src='http://placehold.it/100' />"
@body_html = "<p>Pellentesque habitant morbi tristique<p>"
def setup
# Set up some test conditions here
# This will be invoked before each test
end
#def test_scope
#scope = Scope.new
#scope.instance_eval do
#object do
#object_html
#end
#body do
#body_html
#end
#end
#assert_equal scope.locals[:object], object_html
#assert_equal scope.locals[:body], body_html
#end
def test_render
template = """
.media.media--list
.media__object
= object
.media__body
= body
"""
html = render template do
object do
"<img src='http://placehold.it/100' />"
end
body do
"<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.<p>"
end
end
puts html
end
def teardown
# This will be invoked after each test
# Use to close connections, etc.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment