This repository has been archived by the owner on Oct 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
should_select.rb.svn-base
52 lines (46 loc) · 1.76 KB
/
should_select.rb.svn-base
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module Test::Spec::Rails::ShouldSelect
# Wrapper for +assert_select+. Examples:
#
# Test that the previous request has a login form:
# page.should.select "form#login"
#
# Test that a specific form has a field pre-filled (this is specific test/spec/rails):
# page.should.select "form#login" do |form|
# form.should.select "input[name=user_nick]", :text => @user.nick
# end
#
# OR you can use contain
# page.should.contain "form#login"
#
# page.should.contain "form#login" do |form|
# form.should.contain "input[name=user_nick]", :text => @user.nick
# end
#
# See the Rails API documentation for assert_select for more information
def select(selector, equality=true, message=nil, &block)
@@response_stack ||= []
if @object.is_a?(Test::Unit::TestCase)
@@response_stack.push(Test::Spec::Rails::DummyResponse.new(@object))
elsif @object.is_a?(Array) && @object.first.is_a?(HTML::Tag)
@@response_stack.push(Test::Spec::Rails::DummyResponse.new(
@object.first.to_s, @@response_stack.last.headers
))
else
@@response_stack.push(Test::Spec::Rails::DummyResponse.new(@object.to_s,
(@@response_stack.last.headers rescue 'Content-Type: text/html; charset=utf8')
))
end
@@response_stack.last.assert_select(selector, equality, message, &block)
@@response_stack.pop
end
# because contain sounds better imo
alias :contain :select
end
module Test::Spec::Rails::ShouldNotSelect
include Test::Spec::Rails::ShouldSelect
def select(selector, message=nil, &block)
super(selector, false, message, &block)
end
end
Test::Spec::Should.send(:include, Test::Spec::Rails::ShouldSelect)
Test::Spec::ShouldNot.send(:include, Test::Spec::Rails::ShouldNotSelect)