teamon-merb-ext 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/merb-ext/helpers.rb +19 -0
- data/lib/merb-ext/spec_custom_matchers.rb +80 -0
- metadata +4 -3
data/Rakefile
CHANGED
data/lib/merb-ext/helpers.rb
CHANGED
|
@@ -50,5 +50,24 @@ module MerbExt
|
|
|
50
50
|
def gravatar_image_for(email, opts = {})
|
|
51
51
|
image_tag(gravatar_url_for(email, opts), :alt => "")
|
|
52
52
|
end
|
|
53
|
+
|
|
54
|
+
def put_button(*args, &block)
|
|
55
|
+
button(:put, *args, &block)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def post_button(*agrs, &block)
|
|
59
|
+
button(:post, *args, &block)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def delete_button(*args, &block)
|
|
63
|
+
button(:delete, *args, &block)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def button(method, label, url, attrs = {}, &block)
|
|
67
|
+
tag :form, :class => "#{method}-btn btn", :action => url, :method => :post do
|
|
68
|
+
tag(:input, :type => :hidden, :name => "_method", :value => method.to_s) <<
|
|
69
|
+
tag(:input, attrs.merge(:value => label, :type => :submit))
|
|
70
|
+
end
|
|
71
|
+
end
|
|
53
72
|
end
|
|
54
73
|
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module MerbExt
|
|
2
|
+
module SpecCustomMatchers
|
|
3
|
+
def have_message(message, type = :notice)
|
|
4
|
+
::Webrat::Matchers::HaveXpath.new("//*[contains(@class, '#{type}')][@id='message'][. = '#{message}']")
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def have_header(header)
|
|
8
|
+
::Webrat::Matchers::HaveXpath.new("//h2[. = '#{header}']")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def have_table_cell(content)
|
|
12
|
+
::Webrat::Matchers::HaveXpath.new("//table/tr/td[contains(. ,'#{content}')]")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def have_table_header(content)
|
|
16
|
+
::Webrat::Matchers::HaveXpath.new("//table/tr/th[contains(. ,'#{content}')]")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class HaveTable
|
|
20
|
+
def initialize(table)
|
|
21
|
+
@raw = table
|
|
22
|
+
rows = table.split("\n").map {|row| row.split("|").map {|cell| cell.strip} }
|
|
23
|
+
@headers = rows.first
|
|
24
|
+
@rows = rows[1..-1]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def matches?(target)
|
|
28
|
+
@target = target
|
|
29
|
+
@fields = []
|
|
30
|
+
|
|
31
|
+
@headers.each_with_index do |header, index|
|
|
32
|
+
matcher = ::Webrat::Matchers::HaveXpath.new("//table/tr[1]/th[#{index+1}][contains(. ,'#{header}')]")
|
|
33
|
+
@fields << header unless matcher.matches?(target)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
@rows.each_with_index do |row, row_index|
|
|
37
|
+
row.each_with_index do |cell, cell_index|
|
|
38
|
+
matcher = ::Webrat::Matchers::HaveXpath.new("//table/tr[#{row_index+2}]/td[#{cell_index+1}][contains(. ,'#{cell}')]")
|
|
39
|
+
@fields << cell unless matcher.matches?(target)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
@fields.empty?
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def failure_message
|
|
47
|
+
"expected #{@target.body} to look like:\n#{@raw} \n #{@fields.inspect}"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def have_table(table)
|
|
52
|
+
HaveTable.new(table)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class HaveList
|
|
56
|
+
def initialize(list)
|
|
57
|
+
@lsit = list
|
|
58
|
+
@list_items = list.split("\n").map {|e| e.strip}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def matches?(target)
|
|
62
|
+
@target = target
|
|
63
|
+
|
|
64
|
+
@list_items.each_with_index do |item, index|
|
|
65
|
+
matcher = ::Webrat::Matchers::HaveXpath.new("//ul//li[#{index+1}][contains(. ,'#{item}')]")
|
|
66
|
+
return false unless matcher.matches?(target)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def failure_message
|
|
71
|
+
"expected #{@target.body} to look like: #{@list}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def have_list(list)
|
|
76
|
+
HaveList.new(list)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: teamon-merb-ext
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tymon Tobolski
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-09-03 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -40,11 +40,12 @@ files:
|
|
|
40
40
|
- lib/merb-ext
|
|
41
41
|
- lib/merb-ext/helpers.rb
|
|
42
42
|
- lib/merb-ext/other.rb
|
|
43
|
+
- lib/merb-ext/spec_custom_matchers.rb
|
|
43
44
|
- lib/merb-ext.rb
|
|
44
45
|
- spec/merb-ext_spec.rb
|
|
45
46
|
- spec/spec.opts
|
|
46
47
|
- spec/spec_helper.rb
|
|
47
|
-
has_rdoc:
|
|
48
|
+
has_rdoc: false
|
|
48
49
|
homepage: http://teamon.eu/
|
|
49
50
|
post_install_message:
|
|
50
51
|
rdoc_options: []
|