adeptware-lindo 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +16 -0
- data/README +81 -0
- data/Rakefile +22 -0
- data/lib/lindo.rb +45 -0
- data/lib/lindo/browser.rb +47 -0
- data/lindo.gemspec +26 -0
- data/test/lindo/browser_test.rb +104 -0
- data/test/lindo_test.rb +48 -0
- metadata +62 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Copyright (c) 2007-2009 Adeptware, Inc. (http://adeptware.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
4
|
+
and associated documentation files (the "Software"), to deal in the Software without
|
5
|
+
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
6
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
Software is furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
10
|
+
substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
13
|
+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
14
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
15
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
= lindo
|
2
|
+
|
3
|
+
Enables rendering of the body of an HTTP response from inside controller and
|
4
|
+
integration tests. This makes it easy to diagnose problems when building
|
5
|
+
assert_select statements or just sanity check the output of the test.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Install the gem directly:
|
10
|
+
|
11
|
+
sudo gem install adeptware-lindo --source=http://gems.github.com
|
12
|
+
|
13
|
+
Or install the gem in your Rails project:
|
14
|
+
|
15
|
+
script/plugin install git://github.com/adeptware/lindo.git
|
16
|
+
|
17
|
+
Then require lindo in your test_helper.rb or spec_helper.rb file:
|
18
|
+
|
19
|
+
require 'lindo'
|
20
|
+
|
21
|
+
You may also have to extend the Lindo module from your test or spec
|
22
|
+
helper if you use sessions in your integration tests:
|
23
|
+
|
24
|
+
session.extend Lindo
|
25
|
+
|
26
|
+
== Usage
|
27
|
+
|
28
|
+
Insert the vr method in your functional test immediately after an HTTP
|
29
|
+
request has been sent:
|
30
|
+
|
31
|
+
def test_new
|
32
|
+
post :new
|
33
|
+
vr
|
34
|
+
assert_select "div[id=header]"
|
35
|
+
end
|
36
|
+
|
37
|
+
vr attempts to open the response body in the default web browser. If you want
|
38
|
+
to open the raw HTML in the default text editor instead, simply pass the :html
|
39
|
+
symbol to the method:
|
40
|
+
|
41
|
+
def test_new
|
42
|
+
post :new
|
43
|
+
vr(:html)
|
44
|
+
...
|
45
|
+
end
|
46
|
+
|
47
|
+
By default, vr looks for an instance variable named @response and calls the #body
|
48
|
+
method on it. If your page body is stored in a different variable, such as when
|
49
|
+
testing a mailer, you can pass the raw HTML directly to vr and it will do the
|
50
|
+
right thing:
|
51
|
+
|
52
|
+
def test_mailer
|
53
|
+
mail = Mailer.create_notification
|
54
|
+
vr(mail.body)
|
55
|
+
...
|
56
|
+
end
|
57
|
+
|
58
|
+
Note that to use the default web view, your Rails application must be running
|
59
|
+
locally on port 3000. This will ensure that the page renders correctly with the
|
60
|
+
appropriate images and stylesheets. The server doesn't need to be running if
|
61
|
+
you use the HTML-only view.
|
62
|
+
|
63
|
+
== Compatibility
|
64
|
+
|
65
|
+
lindo requires OS X. Support for Windows is planned.
|
66
|
+
|
67
|
+
test/spec and test/unit work fine with lindo. RSpec, however, tests views
|
68
|
+
independently of controllers, so lindo won't work with it.
|
69
|
+
|
70
|
+
== Running Unit Tests
|
71
|
+
|
72
|
+
Use the rake command to run the unit tests for the plugin. The tests require
|
73
|
+
that the Mocha gem be installed locally:
|
74
|
+
|
75
|
+
sudo gem install mocha
|
76
|
+
|
77
|
+
== Resources
|
78
|
+
|
79
|
+
Repository: http://github.com/adeptware/lindo/
|
80
|
+
Blog: http://adeptware.com/blog
|
81
|
+
Author: Adeptware, Inc.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the lindo plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the lindo plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'Lindo'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/lib/lindo.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'lindo/browser'
|
3
|
+
|
4
|
+
module Lindo
|
5
|
+
TMP = File.join(RAILS_ROOT, "tmp", "lindo")
|
6
|
+
RESPONSE_TXT = File.join(TMP, "response.txt")
|
7
|
+
RESPONSE_HTML = File.join(TMP, "response.html")
|
8
|
+
ASSETS = %w(images stylesheets javascripts)
|
9
|
+
|
10
|
+
def vr(format=:web)
|
11
|
+
create_tmp_dir
|
12
|
+
copy_assets
|
13
|
+
if format.is_a?(Symbol)
|
14
|
+
case format
|
15
|
+
when :web then open_from_file(@response.body, RESPONSE_HTML)
|
16
|
+
when :html then open_from_file(@response.body, RESPONSE_TXT)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
open_from_file(format, RESPONSE_HTML)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_tmp_dir
|
24
|
+
FileUtils.mkdir_p(TMP) unless File.exists?(TMP)
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_assets
|
28
|
+
ASSETS.each do |e|
|
29
|
+
dir = File.join(RAILS_ROOT, "public", e)
|
30
|
+
FileUtils.cp_r(dir, TMP) if File.exists?(dir)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def open_from_file(data, file)
|
35
|
+
scrub(data)
|
36
|
+
File.open(file, File::CREAT|File::TRUNC|File::WRONLY) { |f| f << data }
|
37
|
+
Browser.open(file)
|
38
|
+
end
|
39
|
+
|
40
|
+
def scrub(data)
|
41
|
+
ASSETS.each { |e| data.gsub!("=\"/#{e}/", "=\"#{e}/") }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Test::Unit::TestCase.send(:include, Lindo)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Lindo
|
2
|
+
class Browser
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def open(url)
|
6
|
+
if macos?
|
7
|
+
`/usr/bin/open #{url}`
|
8
|
+
elsif windows?
|
9
|
+
`'C:\Program Files\Internet Explorer\IEXPLORE.EXE' #{url}`
|
10
|
+
elsif gnome?
|
11
|
+
`gnome-open #{url}`
|
12
|
+
elsif kde?
|
13
|
+
`kfmclient openURL #{url}`
|
14
|
+
elsif linux?
|
15
|
+
`firefox #{url}` #not the default browser.
|
16
|
+
else
|
17
|
+
raise "Unrecognized OS. Browser can't be found."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def host
|
22
|
+
require 'rbconfig'
|
23
|
+
Config::CONFIG['host']
|
24
|
+
end
|
25
|
+
|
26
|
+
def macos?
|
27
|
+
host.include?('darwin')
|
28
|
+
end
|
29
|
+
|
30
|
+
def windows?
|
31
|
+
host.include?('mswin')
|
32
|
+
end
|
33
|
+
|
34
|
+
def gnome?
|
35
|
+
Kernel.system("which gnome-open")
|
36
|
+
end
|
37
|
+
|
38
|
+
def kde?
|
39
|
+
Kernel.system("which kfmclient")
|
40
|
+
end
|
41
|
+
|
42
|
+
def linux?
|
43
|
+
host.include?('linux')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lindo.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "lindo"
|
3
|
+
s.version = "0.6"
|
4
|
+
s.date = "2009-06-30"
|
5
|
+
s.summary = "Enables rendering of the body of an HTTP response from inside a functional test."
|
6
|
+
s.email = "contact@adeptware.com"
|
7
|
+
s.homepage = "http://github.com/adeptware/lindo"
|
8
|
+
s.description = "Enables rendering of the body of an HTTP response from inside a functional test. " <<
|
9
|
+
"This makes it easy to diagnose problems when building assert_select statements " <<
|
10
|
+
"or just sanity check the output of the test."
|
11
|
+
s.has_rdoc = true
|
12
|
+
s.authors = ["Adeptware"]
|
13
|
+
s.files = [
|
14
|
+
"CHANGELOG",
|
15
|
+
"MIT-LICENSE",
|
16
|
+
"Rakefile",
|
17
|
+
"README",
|
18
|
+
"lindo.gemspec",
|
19
|
+
"lib/lindo.rb",
|
20
|
+
"lib/lindo/browser.rb",
|
21
|
+
"test/lindo_test.rb",
|
22
|
+
"test/lindo/browser_test.rb"
|
23
|
+
]
|
24
|
+
s.rdoc_options = ["--main", "README"]
|
25
|
+
s.extra_rdoc_files = ["README"]
|
26
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'mocha'
|
4
|
+
|
5
|
+
RAILS_ROOT = '.'
|
6
|
+
require 'lindo'
|
7
|
+
|
8
|
+
class BrowserTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def z_test_open_on_macos # TODO
|
11
|
+
Browser.expects(:gnome?).returns(false)
|
12
|
+
Browser.expects(:kde?).returns(false)
|
13
|
+
Browser.expects(:macos?).returns(true)
|
14
|
+
Browser.expects(:system).with("open foo")
|
15
|
+
Browser.open("foo")
|
16
|
+
end
|
17
|
+
|
18
|
+
def z_test_open_on_windows # TODO
|
19
|
+
Browser.expects(:gnome?).returns(false)
|
20
|
+
Browser.expects(:kde?).returns(false)
|
21
|
+
Browser.expects(:macos?).returns(false)
|
22
|
+
Browser.expects(:windows?).returns(true)
|
23
|
+
Browser.expects(:system).with("'C:\Program Files\Internet Explorer\IEXPLORE.EXE' foo")
|
24
|
+
Browser.open("foo")
|
25
|
+
end
|
26
|
+
|
27
|
+
def z_test_open_on_kde # TODO
|
28
|
+
Browser.expects(:gnome?).returns(false)
|
29
|
+
Browser.expects(:kde?).returns(true)
|
30
|
+
Browser.expects(:macos?).returns(false)
|
31
|
+
Browser.expects(:windows?).returns(false)
|
32
|
+
Browser.expects(:linux?).returns(false)
|
33
|
+
Browser.expects(:system).with("kfmclient openURL foo")
|
34
|
+
Browser.open("foo")
|
35
|
+
end
|
36
|
+
|
37
|
+
def z_test_open_on_gnome # TODO
|
38
|
+
Browser.expects(:gnome?).returns(true)
|
39
|
+
Browser.expects(:kde?).returns(false)
|
40
|
+
Browser.expects(:macos?).returns(false)
|
41
|
+
Browser.expects(:windows?).returns(false)
|
42
|
+
Browser.expects(:linux?).returns(false)
|
43
|
+
Browser.expects(:system).with("gnome-open foo")
|
44
|
+
Browser.open("foo")
|
45
|
+
end
|
46
|
+
|
47
|
+
def z_test_open_on_gnome # TODO
|
48
|
+
Browser.expects(:gnome?).returns(false)
|
49
|
+
Browser.expects(:kde?).returns(false)
|
50
|
+
Browser.expects(:macos?).returns(false)
|
51
|
+
Browser.expects(:windows?).returns(false)
|
52
|
+
Browser.expects(:linux?).returns(true)
|
53
|
+
Browser.expects(:system).with("firefox foo")
|
54
|
+
Browser.open("foo")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_open_with_unrecognized_os
|
58
|
+
Browser.expects(:gnome?).returns(false)
|
59
|
+
Browser.expects(:kde?).returns(false)
|
60
|
+
Browser.expects(:macos?).returns(false)
|
61
|
+
Browser.expects(:windows?).returns(false)
|
62
|
+
Browser.expects(:linux?).returns(false)
|
63
|
+
Browser.open("foo")
|
64
|
+
flunk "Exception should have been thrown"
|
65
|
+
rescue Exception => e
|
66
|
+
assert_equal "Unrecognized OS. Browser can't be found.", e.message
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_host
|
70
|
+
Config::CONFIG.expects(:[]).with("host").returns("foo")
|
71
|
+
assert_equal "foo", Browser.host
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_macos?
|
75
|
+
Browser.expects(:host).returns("darwin")
|
76
|
+
assert Browser.macos?
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_not_macos?
|
80
|
+
Browser.expects(:host).returns("bogus")
|
81
|
+
assert !Browser.macos?
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_windows?
|
85
|
+
Browser.expects(:host).returns("mswin")
|
86
|
+
assert Browser.windows?
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_not_windows?
|
90
|
+
Browser.expects(:host).returns("bogus")
|
91
|
+
assert !Browser.windows?
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_linux?
|
95
|
+
Browser.expects(:host).returns("linux")
|
96
|
+
assert Browser.linux?
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_not_linux?
|
100
|
+
Browser.expects(:host).returns("bogus")
|
101
|
+
assert !Browser.linux?
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
data/test/lindo_test.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'mocha'
|
5
|
+
require 'lindo'
|
6
|
+
|
7
|
+
class LindoTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
# class Response
|
10
|
+
# attr_accessor :body
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def test_foo
|
14
|
+
# response = Response.new
|
15
|
+
# response.body = "<html>FOO</html>"
|
16
|
+
# @response = response
|
17
|
+
# vr(:html)
|
18
|
+
# end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@response = stub(:body => "<html></html>")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_vr
|
25
|
+
File.expects(:open).with(RESPONSE_HTML, File::CREAT|File::TRUNC|File::WRONLY)
|
26
|
+
Browser.expects(:open).with("./tmp/lindo/response.html")
|
27
|
+
vr
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_vr_in_web
|
31
|
+
File.expects(:open).with(RESPONSE_HTML, File::CREAT|File::TRUNC|File::WRONLY)
|
32
|
+
Browser.expects(:open).with("./tmp/lindo/response.html")
|
33
|
+
vr(:web)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_vr_in_html
|
37
|
+
File.expects(:open).with(RESPONSE_TXT, File::CREAT|File::TRUNC|File::WRONLY)
|
38
|
+
Browser.expects(:open).with("./tmp/lindo/response.txt")
|
39
|
+
vr(:html)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_vr_with_raw_html
|
43
|
+
File.expects(:open).with(RESPONSE_HTML, File::CREAT|File::TRUNC|File::WRONLY)
|
44
|
+
Browser.expects(:open).with("./tmp/lindo/response.html")
|
45
|
+
vr("<html></html>")
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adeptware-lindo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.6"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adeptware
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-30 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Enables rendering of the body of an HTTP response from inside a functional test. This makes it easy to diagnose problems when building assert_select statements or just sanity check the output of the test.
|
17
|
+
email: contact@adeptware.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- CHANGELOG
|
26
|
+
- MIT-LICENSE
|
27
|
+
- Rakefile
|
28
|
+
- README
|
29
|
+
- lindo.gemspec
|
30
|
+
- lib/lindo.rb
|
31
|
+
- lib/lindo/browser.rb
|
32
|
+
- test/lindo_test.rb
|
33
|
+
- test/lindo/browser_test.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/adeptware/lindo
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --main
|
39
|
+
- README
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.2.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: Enables rendering of the body of an HTTP response from inside a functional test.
|
61
|
+
test_files: []
|
62
|
+
|