swiss_knife 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +28 -26
- data/README.rdoc +27 -14
- data/Rakefile +1 -1
- data/lib/swiss_knife/helpers.rb +19 -1
- data/lib/swiss_knife/railtie.rb +4 -2
- data/lib/swiss_knife/rspec/have_tag.rb +4 -0
- data/lib/swiss_knife/rspec/have_text.rb +40 -0
- data/lib/swiss_knife/rspec.rb +1 -0
- data/lib/swiss_knife/version.rb +1 -1
- data/locales/en.yml +4 -0
- data/locales/pt.yml +8 -0
- data/spec/helpers/helpers_spec.rb +31 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/rspec/remote_file_shared.rb +2 -4
- data/spec/swiss_knife/rspec/have_text_spec.rb +19 -0
- data/swiss_knife.gemspec +8 -3
- metadata +8 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,12 +2,12 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
abstract (1.0.0)
|
5
|
-
actionmailer (3.0.
|
6
|
-
actionpack (= 3.0.
|
5
|
+
actionmailer (3.0.1)
|
6
|
+
actionpack (= 3.0.1)
|
7
7
|
mail (~> 2.2.5)
|
8
|
-
actionpack (3.0.
|
9
|
-
activemodel (= 3.0.
|
10
|
-
activesupport (= 3.0.
|
8
|
+
actionpack (3.0.1)
|
9
|
+
activemodel (= 3.0.1)
|
10
|
+
activesupport (= 3.0.1)
|
11
11
|
builder (~> 2.1.2)
|
12
12
|
erubis (~> 2.6.6)
|
13
13
|
i18n (~> 0.4.1)
|
@@ -15,19 +15,19 @@ GEM
|
|
15
15
|
rack-mount (~> 0.6.12)
|
16
16
|
rack-test (~> 0.5.4)
|
17
17
|
tzinfo (~> 0.3.23)
|
18
|
-
activemodel (3.0.
|
19
|
-
activesupport (= 3.0.
|
18
|
+
activemodel (3.0.1)
|
19
|
+
activesupport (= 3.0.1)
|
20
20
|
builder (~> 2.1.2)
|
21
21
|
i18n (~> 0.4.1)
|
22
|
-
activerecord (3.0.
|
23
|
-
activemodel (= 3.0.
|
24
|
-
activesupport (= 3.0.
|
22
|
+
activerecord (3.0.1)
|
23
|
+
activemodel (= 3.0.1)
|
24
|
+
activesupport (= 3.0.1)
|
25
25
|
arel (~> 1.0.0)
|
26
26
|
tzinfo (~> 0.3.23)
|
27
|
-
activeresource (3.0.
|
28
|
-
activemodel (= 3.0.
|
29
|
-
activesupport (= 3.0.
|
30
|
-
activesupport (3.0.
|
27
|
+
activeresource (3.0.1)
|
28
|
+
activemodel (= 3.0.1)
|
29
|
+
activesupport (= 3.0.1)
|
30
|
+
activesupport (3.0.1)
|
31
31
|
archive-tar-minitar (0.5.2)
|
32
32
|
arel (1.0.1)
|
33
33
|
activesupport (~> 3.0.0)
|
@@ -36,10 +36,11 @@ GEM
|
|
36
36
|
diff-lcs (1.1.2)
|
37
37
|
erubis (2.6.6)
|
38
38
|
abstract (>= 1.0.0)
|
39
|
+
fakeweb (1.3.0)
|
39
40
|
i18n (0.4.1)
|
40
41
|
linecache19 (0.5.11)
|
41
42
|
ruby_core_source (>= 0.1.4)
|
42
|
-
mail (2.2.
|
43
|
+
mail (2.2.7)
|
43
44
|
activesupport (>= 2.3.6)
|
44
45
|
mime-types
|
45
46
|
treetop (>= 1.4.5)
|
@@ -51,17 +52,17 @@ GEM
|
|
51
52
|
rack (>= 1.0.0)
|
52
53
|
rack-test (0.5.6)
|
53
54
|
rack (>= 1.0)
|
54
|
-
rails (3.0.
|
55
|
-
actionmailer (= 3.0.
|
56
|
-
actionpack (= 3.0.
|
57
|
-
activerecord (= 3.0.
|
58
|
-
activeresource (= 3.0.
|
59
|
-
activesupport (= 3.0.
|
55
|
+
rails (3.0.1)
|
56
|
+
actionmailer (= 3.0.1)
|
57
|
+
actionpack (= 3.0.1)
|
58
|
+
activerecord (= 3.0.1)
|
59
|
+
activeresource (= 3.0.1)
|
60
|
+
activesupport (= 3.0.1)
|
60
61
|
bundler (~> 1.0.0)
|
61
|
-
railties (= 3.0.
|
62
|
-
railties (3.0.
|
63
|
-
actionpack (= 3.0.
|
64
|
-
activesupport (= 3.0.
|
62
|
+
railties (= 3.0.1)
|
63
|
+
railties (3.0.1)
|
64
|
+
actionpack (= 3.0.1)
|
65
|
+
activesupport (= 3.0.1)
|
65
66
|
rake (>= 0.8.4)
|
66
67
|
thor (~> 0.14.0)
|
67
68
|
rake (0.8.7)
|
@@ -96,7 +97,8 @@ PLATFORMS
|
|
96
97
|
ruby
|
97
98
|
|
98
99
|
DEPENDENCIES
|
100
|
+
fakeweb
|
99
101
|
nokogiri
|
100
|
-
rails (= 3.0.
|
102
|
+
rails (= 3.0.1)
|
101
103
|
rspec-rails (= 2.0.0)
|
102
104
|
ruby-debug19
|
data/README.rdoc
CHANGED
@@ -118,6 +118,30 @@ The are some action aliases:
|
|
118
118
|
update => edit
|
119
119
|
remove => destroy
|
120
120
|
|
121
|
+
=== gravatar_tag
|
122
|
+
|
123
|
+
gravatar_tag user.email
|
124
|
+
gravatar_tag "098f6bcd4621d373cade4e832627b4f6"
|
125
|
+
gravatar_tag user.email, :size => 80
|
126
|
+
gravatar_tag user.email, :rating => :x
|
127
|
+
|
128
|
+
# Predefined default images provided by Gravatar. Can be
|
129
|
+
# :mm, :identicon, :monsterid, :wavatar, :retro, 404
|
130
|
+
gravatar_tag user.email, :default => :mm
|
131
|
+
|
132
|
+
gravatar_tag user.email, :default => "gravatar.png"
|
133
|
+
gravatar_tag user.email, :ssl => true
|
134
|
+
gravatar_tag user.email, :alt => user.name
|
135
|
+
gravatar_tag user.email, :title => user.name
|
136
|
+
|
137
|
+
=== submit_or_cancel
|
138
|
+
|
139
|
+
submit_or_cancel root_path
|
140
|
+
submit_or_cancel root_path :button => "Save"
|
141
|
+
submit_or_cancel root_path :button => :"some.scope.for.save"
|
142
|
+
submit_or_cancel root_path :cancel => "Go back"
|
143
|
+
submit_or_cancel root_path :cancel => :"some.scope.for.go_back"
|
144
|
+
|
121
145
|
=== RSpec
|
122
146
|
|
123
147
|
Swiss Knife includes some RSpec matchers. To use them, add the following like to your <tt>spec_helper.rb</tt> file:
|
@@ -139,21 +163,10 @@ The <tt>have_tag</tt> matcher uses Nokogiri, so you can use any CSS selector acc
|
|
139
163
|
|
140
164
|
If you're inspecting some XML snippet, you can use the <tt>have_node</tt> matcher.
|
141
165
|
|
142
|
-
|
143
|
-
|
144
|
-
gravatar_tag user.email
|
145
|
-
gravatar_tag "098f6bcd4621d373cade4e832627b4f6"
|
146
|
-
gravatar_tag user.email, :size => 80
|
147
|
-
gravatar_tag user.email, :rating => :x
|
148
|
-
|
149
|
-
# Predefined default images provided by Gravatar. Can be
|
150
|
-
# :mm, :identicon, :monsterid, :wavatar, :retro, 404
|
151
|
-
gravatar_tag user.email, :default => :mm
|
166
|
+
==== have_text
|
152
167
|
|
153
|
-
|
154
|
-
|
155
|
-
gravatar_tag user.email, :alt => user.name
|
156
|
-
gravatar_tag user.email, :title => user.name
|
168
|
+
string.should have_text("Lorem ipsum")
|
169
|
+
string.should have_text(/Lorem ipsum/)
|
157
170
|
|
158
171
|
== Maintainer
|
159
172
|
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ begin
|
|
17
17
|
gem.has_rdoc = true
|
18
18
|
gem.add_dependency "rails", ">= 3.0.0"
|
19
19
|
gem.add_development_dependency "rspec", ">= 2.0.0"
|
20
|
-
gem.files = FileList["{Gemfile,Gemfile.lock,Rakefile,README.*,swiss_knife.gemspec}", "{spec,lib}/**/*"]
|
20
|
+
gem.files = FileList["{Gemfile,Gemfile.lock,Rakefile,README.*,swiss_knife.gemspec}", "{spec,lib,locales}/**/*"]
|
21
21
|
end
|
22
22
|
|
23
23
|
Jeweler::GemcutterTasks.new
|
data/lib/swiss_knife/helpers.rb
CHANGED
@@ -57,7 +57,7 @@ module SwissKnife
|
|
57
57
|
flash.discard(name)
|
58
58
|
end
|
59
59
|
|
60
|
-
html
|
60
|
+
html.html_safe
|
61
61
|
end
|
62
62
|
|
63
63
|
def dispatcher_tag
|
@@ -175,5 +175,23 @@ module SwissKnife
|
|
175
175
|
body
|
176
176
|
end
|
177
177
|
end
|
178
|
+
|
179
|
+
# Create a submit button with a cancel link besides.
|
180
|
+
#
|
181
|
+
# submit_or_cancel root_path
|
182
|
+
# submit_or_cancel root_path, :button => "Save"
|
183
|
+
# submit_or_cancel root_path, :button => :"some.scope.for.button"
|
184
|
+
# submit_or_cancel root_path, :cancel => "Go back"
|
185
|
+
# submit_or_cancel root_path, :cancel => :"some.scope.for.link"
|
186
|
+
#
|
187
|
+
def submit_or_cancel(url, options = {})
|
188
|
+
options.reverse_merge!(:button => :"swiss_knife.submit", :cancel => :"swiss_knife.cancel")
|
189
|
+
|
190
|
+
String.new.tap do |html|
|
191
|
+
html << submit_tag(t(options[:button], :default => options[:button]), :class => "button")
|
192
|
+
html << " "
|
193
|
+
html << link_to(t(options[:cancel], :default => options[:cancel]), url, :class => "cancel")
|
194
|
+
end.html_safe
|
195
|
+
end
|
178
196
|
end
|
179
197
|
end
|
data/lib/swiss_knife/railtie.rb
CHANGED
@@ -10,12 +10,14 @@ module SwissKnife
|
|
10
10
|
require "swiss_knife/rake_tasks"
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
initializer "swiss_knife.initialize" do
|
14
|
+
::ActionController::Base.instance_eval do
|
15
15
|
include SwissKnife::ActionController
|
16
16
|
helper SwissKnife::Helpers
|
17
17
|
helper_method :page_title
|
18
18
|
end
|
19
|
+
|
20
|
+
::I18n.load_path += Dir[File.dirname(__FILE__) + "/../../locales/*.yml"]
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -55,6 +55,10 @@ module SwissKnife
|
|
55
55
|
!matches.empty?
|
56
56
|
end
|
57
57
|
|
58
|
+
def description
|
59
|
+
"have tag #{selector.inspect} with #{options.inspect}"
|
60
|
+
end
|
61
|
+
|
58
62
|
def failure_message
|
59
63
|
explanation = actual_count ? "but found #{actual_count}" : "but did not"
|
60
64
|
"expected\n#{doc.to_s}\nto have #{failure_count_phrase} #{failure_selector_phrase}, #{explanation}"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module SwissKnife
|
2
|
+
module RSpec
|
3
|
+
module Matchers
|
4
|
+
def have_text(matcher)
|
5
|
+
HaveText.new(matcher)
|
6
|
+
end
|
7
|
+
|
8
|
+
class HaveText
|
9
|
+
attr_accessor :matcher, :subject, :regex
|
10
|
+
|
11
|
+
def initialize(matcher)
|
12
|
+
@matcher = matcher
|
13
|
+
end
|
14
|
+
|
15
|
+
def matches?(text)
|
16
|
+
@subject = text.to_s
|
17
|
+
|
18
|
+
case matcher
|
19
|
+
when String
|
20
|
+
subject.index(matcher)
|
21
|
+
when Regexp
|
22
|
+
subject.match(matcher)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def description
|
27
|
+
"have text #{matcher.inspect}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def failure_message
|
31
|
+
"expected #{subject.inspect} to include #{matcher.inspect}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def negative_failure_message
|
35
|
+
"expected #{subject.inspect} to exclude #{matcher.inspect}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/swiss_knife/rspec.rb
CHANGED
data/lib/swiss_knife/version.rb
CHANGED
data/locales/en.yml
ADDED
data/locales/pt.yml
ADDED
@@ -299,6 +299,7 @@ describe SwissKnife::Helpers do
|
|
299
299
|
helper.gravatar_tag(@email, :title => "title text").should match(/\btitle="title text"/)
|
300
300
|
end
|
301
301
|
|
302
|
+
private
|
302
303
|
def uri_for(html)
|
303
304
|
html = Nokogiri(html)
|
304
305
|
uri = URI.parse(html.css("img.gravatar").first["src"])
|
@@ -311,4 +312,34 @@ describe SwissKnife::Helpers do
|
|
311
312
|
})
|
312
313
|
end
|
313
314
|
end
|
315
|
+
|
316
|
+
describe "#submit_or_cancel" do
|
317
|
+
it "should use defaults" do
|
318
|
+
html = helper.submit_or_cancel("/some/path")
|
319
|
+
html.should have_tag("a.cancel[href='/some/path']", :text => "Cancel")
|
320
|
+
html.should have_tag("input.button[type=submit][value=Submit]")
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should use custom link text from I18n file" do
|
324
|
+
I18n.backend.stub :translations => {:en => {:go_back => "Go back"}}
|
325
|
+
html = helper.submit_or_cancel("/some/path", :cancel => :go_back)
|
326
|
+
html.should have_tag("a.cancel", :text => "Go back")
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should use custom link text" do
|
330
|
+
html = helper.submit_or_cancel("/some/path", :cancel => "Go back")
|
331
|
+
html.should have_tag("a.cancel", :text => "Go back")
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should use custom button text from I18n file" do
|
335
|
+
I18n.backend.stub :translations => {:en => {:send => "Send"}}
|
336
|
+
html = helper.submit_or_cancel("/some/path", :button => :send)
|
337
|
+
html.should have_tag("input[type=submit][value=Send]")
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should use custom button text" do
|
341
|
+
html = helper.submit_or_cancel("/some/path", :button => "Send")
|
342
|
+
html.should have_tag("input[type=submit][value=Send]")
|
343
|
+
end
|
344
|
+
end
|
314
345
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,8 +3,7 @@ shared_examples_for "remote file" do
|
|
3
3
|
let(:file_path) { directory.join(file) }
|
4
4
|
|
5
5
|
it "should update file" do
|
6
|
-
|
7
|
-
subject.should_receive(:open).with(url).and_return(mock)
|
6
|
+
FakeWeb.register_uri(:get, url, :body => "FILE CONTENT")
|
8
7
|
subject.update
|
9
8
|
|
10
9
|
File.read(file_path).should == "FILE CONTENT"
|
@@ -12,8 +11,7 @@ shared_examples_for "remote file" do
|
|
12
11
|
|
13
12
|
it "should overwrite previous file" do
|
14
13
|
File.open(file_path, "w+") << "OLD CONTENT"
|
15
|
-
|
16
|
-
subject.should_receive(:open).with(url).and_return(mock)
|
14
|
+
FakeWeb.register_uri(:get, url, :body => "UPDATED CONTENT")
|
17
15
|
subject.update
|
18
16
|
|
19
17
|
File.read(file_path).should == "UPDATED CONTENT"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe SwissKnife::RSpec::Matchers::HaveText do
|
4
|
+
it "should match string" do
|
5
|
+
"abc".should have_text("abc")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should match regexp" do
|
9
|
+
"abc".should have_text(/b/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not match string" do
|
13
|
+
"abc".should_not have_text("d")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not match regexp" do
|
17
|
+
"abc".should_not have_text(/d/)
|
18
|
+
end
|
19
|
+
end
|
data/swiss_knife.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{swiss_knife}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nando Vieira"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-14}
|
13
13
|
s.description = %q{Several helpers for Rails 3}
|
14
14
|
s.email = %q{fnando.vieira@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,8 +34,11 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/swiss_knife/rake_tasks.rb",
|
35
35
|
"lib/swiss_knife/rspec.rb",
|
36
36
|
"lib/swiss_knife/rspec/have_tag.rb",
|
37
|
+
"lib/swiss_knife/rspec/have_text.rb",
|
37
38
|
"lib/swiss_knife/support/remote_file.rb",
|
38
39
|
"lib/swiss_knife/version.rb",
|
40
|
+
"locales/en.yml",
|
41
|
+
"locales/pt.yml",
|
39
42
|
"spec/controllers/application_controller_spec.rb",
|
40
43
|
"spec/helpers/helpers_spec.rb",
|
41
44
|
"spec/resources/assets.yml",
|
@@ -62,6 +65,7 @@ Gem::Specification.new do |s|
|
|
62
65
|
"spec/swiss_knife/jquery_spec.rb",
|
63
66
|
"spec/swiss_knife/jquery_ujs_spec.rb",
|
64
67
|
"spec/swiss_knife/modernizr_spec.rb",
|
68
|
+
"spec/swiss_knife/rspec/have_text_spec.rb",
|
65
69
|
"swiss_knife.gemspec"
|
66
70
|
]
|
67
71
|
s.homepage = %q{http://github.com/fnando/swiss_knife}
|
@@ -81,7 +85,8 @@ Gem::Specification.new do |s|
|
|
81
85
|
"spec/swiss_knife/i18n_js_spec.rb",
|
82
86
|
"spec/swiss_knife/jquery_spec.rb",
|
83
87
|
"spec/swiss_knife/jquery_ujs_spec.rb",
|
84
|
-
"spec/swiss_knife/modernizr_spec.rb"
|
88
|
+
"spec/swiss_knife/modernizr_spec.rb",
|
89
|
+
"spec/swiss_knife/rspec/have_text_spec.rb"
|
85
90
|
]
|
86
91
|
|
87
92
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nando Vieira
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-14 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -74,8 +74,11 @@ files:
|
|
74
74
|
- lib/swiss_knife/rake_tasks.rb
|
75
75
|
- lib/swiss_knife/rspec.rb
|
76
76
|
- lib/swiss_knife/rspec/have_tag.rb
|
77
|
+
- lib/swiss_knife/rspec/have_text.rb
|
77
78
|
- lib/swiss_knife/support/remote_file.rb
|
78
79
|
- lib/swiss_knife/version.rb
|
80
|
+
- locales/en.yml
|
81
|
+
- locales/pt.yml
|
79
82
|
- spec/controllers/application_controller_spec.rb
|
80
83
|
- spec/helpers/helpers_spec.rb
|
81
84
|
- spec/resources/assets.yml
|
@@ -102,6 +105,7 @@ files:
|
|
102
105
|
- spec/swiss_knife/jquery_spec.rb
|
103
106
|
- spec/swiss_knife/jquery_ujs_spec.rb
|
104
107
|
- spec/swiss_knife/modernizr_spec.rb
|
108
|
+
- spec/swiss_knife/rspec/have_text_spec.rb
|
105
109
|
- swiss_knife.gemspec
|
106
110
|
has_rdoc: true
|
107
111
|
homepage: http://github.com/fnando/swiss_knife
|
@@ -148,3 +152,4 @@ test_files:
|
|
148
152
|
- spec/swiss_knife/jquery_spec.rb
|
149
153
|
- spec/swiss_knife/jquery_ujs_spec.rb
|
150
154
|
- spec/swiss_knife/modernizr_spec.rb
|
155
|
+
- spec/swiss_knife/rspec/have_text_spec.rb
|