haikuwebdev (owner)

Revisions

gist: 52976 Download_button fork
public
Public Clone URL: git://gist.github.com/52976.git
Embed All Files: show embed
my_helper_test.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require 'test_helper'
 
class MyHelperTest < ActionView::TestCase
  test "title" do
    assert_select_in '<h1>My Awesome App</h1>', 'h1'
  end
  
  test "nav" do
    html = '<div id="nav"><a href="/">Home</a></div>'
    assert_select_in html, 'div' do
      assert_select 'a', /home/i
    end
  end
end
 
# A more flexible and elegant solution can be found here:
# http://github.com/vigetlabs/helper_me_test/tree/master
test_helper.rb #
1
2
3
4
5
6
7
8
9
10
11
# Add this to the bottom of your test_helper.rb
 
module HelpersSelectorAsssertions
  def assert_select_in(html, *args, &block)
    node = HTML::Document.new(html).root
    assert_select(*args.unshift(node), &block)
  end
end
 
ActionView::TestCase.send(:include, HelpersSelectorAsssertions)