public
Fork of defunkt/body_matcher
Description: Simplify your view testing. Forget assert_select.
Homepage: http://ozmm.org/posts/some_ruby_code.html
Clone URL: git://github.com/github/body_matcher.git
body_matcher / README
100644 34 lines (20 sloc) 0.874 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
== BodyMatcher
 
BodyMatcher simplifies your view testing. Forget assert_select.
 
Activate it by including it in your Test::Unit::TestCase class:
 
  class Test::Unit::TestCase
    include BodyMatcher
 
    self.use_transactional_fixtures = true
    self.use_instantiated_fixtures = false
  end
 
Simple assertions:
 
  body['#web_results'].should.match /results from the web/i
 
  body['#categories_dropdown'].should.include "#{topic}[#{count}]"
 
Access the attributes:
 
  body['#name_field'].attributes['value'].should.equal '(your name)'
  body['#name_field']['value'].should.equal '(your name)'
 
You can also use @response.body['blah'].
 
The nice part about this is that test failures will print out only
the HTML you're trying to match.
 
For use with test/spec/rails, which provides the `body' method. Also
requires Hpricot. Enjoy.
 
* Chris Wanstrath [ chris@ozmm.org ]