suhyo 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -14,16 +14,24 @@ module Suhyo
14
14
  compacted = @element.gsub(/\s+/, ' ')
15
15
  if index = compacted.index(@content)
16
16
  if @options.has_key?(:before)
17
- @other_content_index = compacted.index(options[:before])
18
- index < @other_content_index
17
+ @other_content_index = compacted.index(@options[:before])
18
+ if @other_content_index.nil?
19
+ return false
20
+ else
21
+ return index < @other_content_index
22
+ end
19
23
  elsif @options.has_key?(:after)
20
- @other_content_index = compacted.index(options[:after])
21
- index > @other_content_index
24
+ @other_content_index = compacted.index(@options[:after])
25
+ if @other_content_index.nil?
26
+ return false
27
+ else
28
+ return index > @other_content_index
29
+ end
22
30
  else
23
- true
31
+ return true
24
32
  end
25
33
  else
26
- nil
34
+ return nil
27
35
  end
28
36
  end
29
37
 
@@ -37,14 +45,14 @@ module Suhyo
37
45
 
38
46
  def order_message
39
47
  if @options.has_key?(:before)
40
- str = "before #{options[:before]}"
48
+ str = "before #{@options[:before]}"
41
49
  if @other_content_index.nil?
42
- str << " but #{options[:before]} was not foudn"
50
+ str << " but #{@options[:before]} was not foudn"
43
51
  end
44
52
  elsif @options.has_key?(:after)
45
- str = "after #{options[:after]}"
53
+ str = "after #{@options[:after]}"
46
54
  if @other_content_index.nil?
47
- str << " but #{options[:after]} was not foudn"
55
+ str << " but #{@options[:after]} was not foudn"
48
56
  end
49
57
  else
50
58
  nil
@@ -53,7 +61,10 @@ module Suhyo
53
61
  end
54
62
 
55
63
  # Like Webrat's +contain+ matcher, except it checks that one bit of text comes before or after another.
56
- # Useful for testing sort order, for example.
64
+ # Can be used to test sort order in an integration test. Usage:
65
+ #
66
+ # response.should contain_in_order('ABC', :before => 'DEF')
67
+ # response.should contain_in_order('DEF', :after => 'ABC')
57
68
  def contain_in_order(content, options = {})
58
69
  HaveOrderedContent.new(content, options)
59
70
  end
@@ -37,6 +37,44 @@ describe Suhyo::ViewMatchers do
37
37
  end
38
38
  end
39
39
 
40
+ describe '#contain_in_order' do
41
+ context 'matching before' do
42
+ it 'matches when the content is in the right order' do
43
+ '<p>Foo</p><p>Bar</p>'.should contain_in_order('Foo', :before => 'Bar')
44
+ end
45
+
46
+ it 'does not match when the content is in the reverse order' do
47
+ '<p>Bar</p><p>Foo</p>'.should_not contain_in_order('Foo', :before => 'Bar')
48
+ end
49
+
50
+ it 'does not match when the first content is missing' do
51
+ '<p>...</p><p>Bar</p>'.should_not contain_in_order('Foo', :before => 'Bar')
52
+ end
53
+
54
+ it 'does not match when the second content is missing' do
55
+ '<p>Foo</p><p>...</p>'.should_not contain_in_order('Foo', :before => 'Bar')
56
+ end
57
+ end
58
+
59
+ context 'matching after' do
60
+ it 'matches when the content is in the right order' do
61
+ '<p>Foo</p><p>Bar</p>'.should contain_in_order('Bar', :after => 'Foo')
62
+ end
63
+
64
+ it 'does not match when the content is in the reverse order' do
65
+ '<p>Bar</p><p>Foo</p>'.should_not contain_in_order('Bar', :after => 'Foo')
66
+ end
67
+
68
+ it 'does not match when the first content is missing' do
69
+ '<p>Foo</p><p>...</p>'.should_not contain_in_order('Bar', :after => 'Foo')
70
+ end
71
+
72
+ it 'does not match when the second content is missing' do
73
+ '<p>...</p><p>Bar</p>'.should_not contain_in_order('Bar', :after => 'Foo')
74
+ end
75
+ end
76
+ end
77
+
40
78
  describe '#have_restful_form' do
41
79
  def restful_form(method)
42
80
  case method
data/suhyo.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{suhyo}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jarrett"]
12
- s.date = %q{2010-03-11}
12
+ s.date = %q{2010-03-12}
13
13
  s.description = %q{Matchers built on Webrat to address some common needs in web app testing}
14
14
  s.email = %q{jarrett@uchicago.edu}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suhyo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jarrett
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-11 00:00:00 -06:00
12
+ date: 2010-03-12 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency