lindo 0.6.0

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.
@@ -0,0 +1,2 @@
1
+ pkg
2
+ test/tmp
@@ -0,0 +1,3 @@
1
+ 6/29/09 - Added scrubbing of relative asset paths [Matthew Bass]
2
+
3
+ 5/20/09 - Forked from vizres [Matthew Bass]
@@ -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 lindo
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.
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the lindo plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the lindo plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'Lindo'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |gemspec|
28
+ gemspec.name = "lindo"
29
+ gemspec.summary = "Enables rendering of the body of an HTTP response from inside a functional test."
30
+ gemspec.description = "Enables rendering of the body of an HTTP response from inside a functional test."
31
+ gemspec.email = "contact@adeptware.com"
32
+ gemspec.homepage = "http://github.com/adeptware/lindo"
33
+ gemspec.authors = ["Adeptware"]
34
+ end
35
+ rescue LoadError
36
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
37
+ end
38
+
39
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.0
@@ -0,0 +1,46 @@
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.rm_r(TMP) if File.exists?(TMP)
25
+ FileUtils.mkdir_p(TMP)
26
+ end
27
+
28
+ def copy_assets
29
+ ASSETS.each do |e|
30
+ dir = File.join(RAILS_ROOT, "public", e)
31
+ FileUtils.cp_r(dir, TMP) if File.exists?(dir)
32
+ end
33
+ end
34
+
35
+ def open_from_file(data, file)
36
+ scrub(data)
37
+ File.open(file, File::CREAT|File::TRUNC|File::WRONLY) { |f| f << data }
38
+ Browser.open(file)
39
+ end
40
+
41
+ def scrub(data)
42
+ ASSETS.each { |e| data.gsub!("=\"/#{e}/", "=\"#{e}/") }
43
+ end
44
+ end
45
+
46
+ 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
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lindo}
8
+ s.version = "0.6.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Adeptware"]
12
+ s.date = %q{2009-12-03}
13
+ s.description = %q{Enables rendering of the body of an HTTP response from inside a functional test.}
14
+ s.email = %q{contact@adeptware.com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "CHANGELOG",
21
+ "MIT-LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/lindo.rb",
26
+ "lib/lindo/browser.rb",
27
+ "lindo.gemspec",
28
+ "test/lindo/browser_test.rb",
29
+ "test/lindo_test.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/adeptware/lindo}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Enables rendering of the body of an HTTP response from inside a functional test.}
36
+ s.test_files = [
37
+ "test/lindo/browser_test.rb",
38
+ "test/lindo_test.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ end
51
+
@@ -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
@@ -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,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lindo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Adeptware
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-03 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Enables rendering of the body of an HTTP response from inside a functional test.
17
+ email: contact@adeptware.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - .gitignore
26
+ - CHANGELOG
27
+ - MIT-LICENSE
28
+ - README
29
+ - Rakefile
30
+ - VERSION
31
+ - lib/lindo.rb
32
+ - lib/lindo/browser.rb
33
+ - lindo.gemspec
34
+ - test/lindo/browser_test.rb
35
+ - test/lindo_test.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/adeptware/lindo
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Enables rendering of the body of an HTTP response from inside a functional test.
64
+ test_files:
65
+ - test/lindo/browser_test.rb
66
+ - test/lindo_test.rb