Class: MiniTest::Spec

Inherits:
Object
  • Object
show all
Includes:
Padrino::Helpers::AssetTagHelpers, Padrino::Helpers::OutputHelpers, Padrino::Helpers::TagHelpers, Rack::Test::Methods, Webrat::Matchers, Webrat::Methods
Defined in:
lib/vendored-middleman-deps/padrino-core-0.11.2/test/mini_shoulda.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/test/helper.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/test/helper.rb

Constant Summary

Constants included from Padrino::Helpers::AssetTagHelpers

Padrino::Helpers::AssetTagHelpers::ABSOLUTE_URL_PATTERN, Padrino::Helpers::AssetTagHelpers::APPEND_ASSET_EXTENSIONS, Padrino::Helpers::AssetTagHelpers::FRAGMENT_HASH

Constants included from Padrino::Helpers::TagHelpers

Padrino::Helpers::TagHelpers::BOOLEAN_ATTRIBUTES, Padrino::Helpers::TagHelpers::DATA_ATTRIBUTES, Padrino::Helpers::TagHelpers::ESCAPE_REGEXP, Padrino::Helpers::TagHelpers::ESCAPE_VALUES, Padrino::Helpers::TagHelpers::NEWLINE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Padrino::Helpers::AssetTagHelpers

#asset_path, #favicon_tag, #feed_tag, #flash_tag, #image_path, #image_tag, #javascript_include_tag, #link_to, #mail_to, #meta_tag, #stylesheet_link_tag

Methods included from Padrino::Helpers::TagHelpers

#content_tag, #input_tag, #safe_content_tag, #tag

Methods included from Padrino::Helpers::OutputHelpers

#block_is_template?, #capture_html, #concat_content, #concat_safe_content, #content_for, #content_for?, handlers, included, register, #yield_content

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Delegate other missing methods to response.



41
42
43
44
45
46
47
48
49
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/test/helper.rb', line 41

def method_missing(name, *args, &block)
  if response && response.respond_to?(name)
    response.send(name, *args, &block)
  else
    super(name, *args, &block)
  end
rescue Rack::Test::Error # no response yet
  super(name, *args, &block)
end

Class Method Details

.should_eventually(desc) ⇒ Object



16
17
18
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/test/mini_shoulda.rb', line 16

def should_eventually(desc)
  it("should eventually #{desc}") { skip("Should eventually #{desc}") }
end

Instance Method Details

#appObject



30
31
32
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/test/helper.rb', line 30

def app
  Rack::Lint.new(@app)
end

#assert_has_no_tag(name, attributes = {}, &block) ⇒ Object

assert_has_no_tag, tag(:h1, :content => “yellow”) { “<h1>green</h1>” } In this case, block is the html to evaluate



38
39
40
41
42
43
44
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/test/helper.rb', line 38

def assert_has_no_tag(name, attributes = {}, &block)
  html = block && block.call
  attributes.merge!(:count => 0)
  matcher = HaveSelector.new(name, attributes)
  raise "Please specify a block!" if html.blank?
  assert matcher.matches?(html), matcher.failure_message
end

#assert_has_tag(name, attributes = {}, &block) ⇒ Object

assert_has_tag(:h1, :content => “yellow”) { “<h1>yellow</h1>” } In this case, block is the html to evaluate



28
29
30
31
32
33
34
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/test/helper.rb', line 28

def assert_has_tag(name, attributes = {}, &block)
  html = block && block.call
  assert html.html_safe?, 'html_safe? failed'
  matcher = HaveSelector.new(name, attributes)
  raise "Please specify a block!" if html.blank?
  assert matcher.matches?(html), matcher.failure_message
end

#assert_match_in_file(pattern, file) ⇒ Object

Asserts that a file matches the pattern



47
48
49
50
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/test/helper.rb', line 47

def assert_match_in_file(pattern, file)
  assert File.exist?(file), "File '#{file}' does not exist!"
  assert_match pattern, File.read(file)
end

#create_template(name, content, options = {}) ⇒ Object Also known as: create_view, create_layout



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/test/helper.rb', line 53

def create_template(name, content, options={})
  FileUtils.mkdir_p(File.dirname(__FILE__) + "/views")
  FileUtils.mkdir_p(File.dirname(__FILE__) + "/views/layouts")
  path  = "/views/#{name}"
  path += ".#{options.delete(:locale)}" if options[:locale].present?
  path += ".#{options[:format]}" if options[:format].present?
  path += ".erb" unless options[:format].to_s =~ /haml|rss|atom/
  path += ".builder" if options[:format].to_s =~ /rss|atom/
  file  = File.dirname(__FILE__) + path
  File.open(file, 'w') { |io| io.write content }
  file
end

#mock_app(base = Padrino::Application, &block) ⇒ Object

Sets up a Sinatra::Base subclass defined with the block given. Used in setup or individual spec methods to establish the application.



26
27
28
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/test/helper.rb', line 26

def mock_app(base=Padrino::Application, &block)
  @app = Sinatra.new(base, &block)
end

#mock_model(klazz, options = {}) ⇒ Object

mock_model(“Business”, :new_record? => true) => <Business>



53
54
55
56
57
58
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/test/helper.rb', line 53

def mock_model(klazz, options={})
  options.reverse_merge!(:class => klazz, :new_record? => false, :id => 20, :errors => {})
  record = stub(options)
  record.stubs(:to_ary => [record])
  record
end

#remove_viewsObject



68
69
70
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/test/helper.rb', line 68

def remove_views
  FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
end

#stop_time_for_testObject



20
21
22
23
24
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/test/helper.rb', line 20

def stop_time_for_test
  time = Time.now
  Time.stubs(:now).returns(time)
  return time
end

#with_template(name, content, options = {}) ⇒ Object Also known as: with_view, with_layout



72
73
74
75
76
77
78
79
80
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/test/helper.rb', line 72

def with_template(name, content, options={})
  # Build a temp layout
  template = create_template(name, content, options)
  yield
ensure
  # Remove temp layout
  File.unlink(template) rescue nil
  remove_views
end