fixlr-browser_stakeout 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Nathan Fixler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,21 @@
1
+ = browser_stakeout
2
+
3
+ Like RStakeout, but for watching static web content in multiple web browsers.
4
+
5
+ Watch a set of files and open them in Safari and/or Firefox if they change.
6
+ The files should probably be plain HTML files, but I'm not the boss of you.
7
+ Refreshes index.htm or index.html by default (if they exist)
8
+
9
+ Inspired by AutoTest and RStakeout.
10
+ http://nubyonrails.com/articles/automation-with-rstakeout
11
+
12
+ === Example
13
+
14
+ * refresh both (since safari is already enabled by default)
15
+ cd /to/your/project
16
+ browser_stakeout --firefox file.html
17
+
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2009 Nathan Fixler. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "browser_stakeout"
8
+ gem.summary = %Q{Like RStakeout, but for watching static web content in multiple web browsers.}
9
+ gem.email = "nathan@fixler.org"
10
+ gem.homepage = "http://github.com/fixlr/browser_stakeout"
11
+ gem.authors = ["Nathan Fixler"]
12
+
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "browser_stakeout #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 1
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby -w
2
+ # require 'rubygems'
3
+ require 'optparse'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
+ require 'browser_stakeout'
7
+
8
+ BrowserStakeout::Application.run!(*ARGV)
@@ -0,0 +1,61 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{browser_stakeout}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nathan Fixler"]
9
+ s.date = %q{2009-05-13}
10
+ s.default_executable = %q{browser_stakeout}
11
+ s.email = %q{nathan@fixler.org}
12
+ s.executables = ["browser_stakeout"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "bin/browser_stakeout",
25
+ "browser_stakeout.gemspec",
26
+ "lib/browser_stakeout.rb",
27
+ "lib/browser_stakeout/application.rb",
28
+ "lib/browser_stakeout/browsers/firefox.rb",
29
+ "lib/browser_stakeout/browsers/safari.rb",
30
+ "lib/browser_stakeout/options.rb",
31
+ "test/application_test.rb",
32
+ "test/browser_stakeout_test.rb",
33
+ "test/firefox_test.rb",
34
+ "test/options_test.rb",
35
+ "test/safari_test.rb",
36
+ "test/test_helper.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/fixlr/browser_stakeout}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.3}
42
+ s.summary = %q{Like RStakeout, but for watching static web content in multiple web browsers.}
43
+ s.test_files = [
44
+ "test/application_test.rb",
45
+ "test/browser_stakeout_test.rb",
46
+ "test/firefox_test.rb",
47
+ "test/options_test.rb",
48
+ "test/safari_test.rb",
49
+ "test/test_helper.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ else
58
+ end
59
+ else
60
+ end
61
+ end
@@ -0,0 +1,8 @@
1
+ require 'ostruct'
2
+ require 'browser_stakeout/application'
3
+ require 'browser_stakeout/options'
4
+ require 'browser_stakeout/browsers/safari'
5
+ require 'browser_stakeout/browsers/firefox'
6
+
7
+ class BrowserStakeout
8
+ end
@@ -0,0 +1,64 @@
1
+ class BrowserStakeout
2
+ class Application
3
+ class << self
4
+ def run!(*arguments)
5
+ options = BrowserStakeout::Options.new(arguments)
6
+
7
+ if options[:invalid_argument]
8
+ $stderr.puts "Invalid argument: #{options[:invalid_argument]}"
9
+ options[:show_help] = true
10
+ end
11
+
12
+ if options[:show_help]
13
+ $stderr.puts options.opts
14
+ return 1
15
+ end
16
+
17
+ unless options.files.size >= 1
18
+ $stderr.puts "broken"
19
+ $stderr.puts options.opts
20
+ return 1
21
+ end
22
+
23
+ files = build_mtimes_hash(options.files)
24
+
25
+ trap('INT') do
26
+ puts "\nIt's quittin time..."
27
+ exit
28
+ end
29
+
30
+ # Check to see if the file being refreshed is on the files list.
31
+ index_file = options.find_index(files)
32
+
33
+ puts %{#{File.basename($0)} is reporting for duty!
34
+ Currently watching #{files.collect {|k,v| File.basename(k)}.join(', ')}\n\n}
35
+
36
+ loop do
37
+ sleep 1
38
+
39
+ changed_file, last_changed = files.find do |file, last_changed|
40
+ File.mtime(file) > last_changed
41
+ end
42
+
43
+ if changed_file
44
+ files[changed_file] = File.mtime(changed_file)
45
+ puts "#{Time.now} => #{File.basename(changed_file)} changed"
46
+ options.browsers.each do |b|
47
+ system b.refresh(index_file||changed_file)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def build_mtimes_hash(arguments)
54
+ files = {}
55
+ arguments.each do |a|
56
+ Dir[a].each do |file|
57
+ files[file] = File.mtime(file)
58
+ end
59
+ end
60
+ files
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ class BrowserStakeout
2
+ class Browsers
3
+ class Firefox
4
+ class << self
5
+ def refresh(filename)
6
+ "open -g -a Firefox.app #{filename}"
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class BrowserStakeout
2
+ class Browsers
3
+ class Safari
4
+ class << self
5
+ def refresh(filename)
6
+ "open -g -a Safari.app #{filename}"
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,54 @@
1
+ class BrowserStakeout
2
+ class Options < Hash
3
+ attr_reader :opts, :orig_args, :browsers, :files
4
+
5
+ def initialize(args)
6
+ super()
7
+
8
+ @orig_args = args.clone
9
+ self[:safari] = true
10
+ self[:firefox] = false
11
+ self[:index] = "index\.htm[l]?"
12
+
13
+ @opts = OptionParser.new do |o|
14
+ o.banner = "Usage: #{File.basename($0)} [options] files-to-watch"
15
+
16
+ o.on("-i", "--[no-]index FILENAME",
17
+ "Specify the file to refresh whenever changes are found") do |i|
18
+ self[:index] = i
19
+ end
20
+
21
+ o.on("-s", "--[no-]safari", "Reload the page(s) in Safari") do |s|
22
+ self[:safari] = s
23
+ end
24
+
25
+ o.on("-f", "--[no-]firefox", "Reload the page(s) in Firefox") do |f|
26
+ self[:firefox] = f
27
+ end
28
+
29
+ o.on_tail("-h", "--help", "Show this message") do
30
+ self[:show_help] = true
31
+ end
32
+ end
33
+
34
+ begin
35
+ @opts.parse!(args)
36
+ @files = args
37
+ rescue OptionParser::InvalidOption => e
38
+ self[:invalid_argument] = e.message
39
+ end
40
+
41
+
42
+ # Decide which browsers need to be refreshed.
43
+ # TODO: How can this be extended to include other browsers easily?
44
+ @browsers = []
45
+ @browsers << BrowserStakeout::Browsers::Safari if self[:safari]
46
+ @browsers << BrowserStakeout::Browsers::Firefox if self[:firefox]
47
+ raise "Zero browsers? Come on. Is that really what you want to do?" if @browsers.length == 0
48
+ end
49
+
50
+ def find_index(files)
51
+ files.keys.find {|f| f =~ /#{self[:index]}/}
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ class TestOptions < Test::Unit::TestCase
4
+ def run_application(*arguments)
5
+ original_stdout = $stdout
6
+ original_stderr = $stderr
7
+
8
+ fake_stdout = StringIO.new
9
+ fake_stderr = StringIO.new
10
+
11
+ $stdout = fake_stdout
12
+ $stderr = fake_stderr
13
+
14
+ result = nil
15
+ begin
16
+ result = BrowserStakeout::Application.run!(*arguments)
17
+ ensure
18
+ $stdout = original_stdout
19
+ $stderr = original_stderr
20
+ end
21
+
22
+ @stdout = fake_stdout.string
23
+ @stderr = fake_stderr.string
24
+
25
+ result
26
+ end
27
+
28
+ def self.should_exit_with_code(code)
29
+ should "exit with code #{code}" do
30
+ assert_equal code, @result
31
+ end
32
+ end
33
+
34
+ context "called without any args" do
35
+ setup { @result = run_application }
36
+
37
+ should_exit_with_code 1
38
+
39
+ should 'display usage on stderr' do
40
+ assert_match 'Usage:', @stderr
41
+ end
42
+
43
+ should 'not display anything on stdout' do
44
+ assert_equal '', @stdout.squeeze.strip
45
+ end
46
+ end
47
+
48
+ context "called with -h" do
49
+ setup { @result = run_application }
50
+
51
+ should_exit_with_code 1
52
+
53
+ should 'display usage on stderr' do
54
+ assert_match 'Usage:', @stderr
55
+ end
56
+
57
+ should 'not display anything on stdout' do
58
+ assert_equal '', @stdout.squeeze.strip
59
+ end
60
+ end
61
+
62
+ context "called with --invalid-argument" do
63
+ setup do
64
+ assert_nothing_raised do
65
+ @result = run_application("--invalid-argument")
66
+ end
67
+ end
68
+
69
+ should_exit_with_code 1
70
+
71
+ should 'display invalid argument' do
72
+ assert_match '--invalid-argument', @stderr
73
+ end
74
+
75
+ should 'display usage on stderr' do
76
+ assert_match 'Usage:', @stderr
77
+ end
78
+
79
+ should 'not display anything on stdout' do
80
+ assert_equal '', @stdout.squeeze.strip
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TestOptions < Test::Unit::TestCase
4
+ should "the BrowserStakeout class doesn't really do anything yet" do
5
+ true
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class TestFirefoxBrowser < Test::Unit::TestCase
4
+
5
+ context "foo.txt" do
6
+ setup do
7
+ @browser = BrowserStakeout::Browsers::Firefox
8
+ end
9
+
10
+ should "refresh foo.txt" do
11
+ assert_equal "open -g -a Firefox.app foo.txt", @browser.refresh("foo.txt")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,90 @@
1
+ require 'test_helper'
2
+
3
+ class TestOptions < Test::Unit::TestCase
4
+
5
+ def setup_options(*arguments)
6
+ @options = BrowserStakeout::Options.new(arguments)
7
+ end
8
+
9
+ def self.for_options(*options)
10
+ context options.join(' ') do
11
+ setup { setup_options *options }
12
+ yield
13
+ end
14
+ end
15
+
16
+ context "default options" do
17
+ setup { setup_options }
18
+
19
+ should 'refresh Safari' do
20
+ assert @options[:safari]
21
+ end
22
+
23
+ should 'not refresh Firefox' do
24
+ assert !@options[:firefox]
25
+ end
26
+
27
+ should 'try to refresh index.htm[l]? by default' do
28
+ assert_equal "index\.htm[l]?", @options[:index]
29
+ end
30
+
31
+ should 'refresh using the osx open command by default' do
32
+ assert_equal 'open -g', @options[:command]
33
+ end
34
+ end
35
+
36
+ context "default options with file list" do
37
+ setup { setup_options("index.html", "news.html") }
38
+
39
+ should "not be invalid" do
40
+ assert_nil @options[:invalid_argument]
41
+ end
42
+
43
+ should "not show help" do
44
+ assert_nil @options[:show_help]
45
+ end
46
+
47
+ should "still have two unused options" do
48
+ assert_equal 2, @options.files.length
49
+ assert_equal ['index.html', 'news.html'], @options.files
50
+ end
51
+ end
52
+
53
+ for_options '--firefox' do
54
+ should 'refresh Firefox' do
55
+ assert @options[:firefox]
56
+ end
57
+ end
58
+
59
+ for_options '--help' do
60
+ should 'show help' do
61
+ assert @options[:show_help]
62
+ end
63
+ end
64
+
65
+ for_options '-h' do
66
+ should 'show help' do
67
+ assert @options[:show_help]
68
+ end
69
+ end
70
+
71
+ for_options '--invalid' do
72
+ should 'be an invalid argument' do
73
+ assert @options[:invalid_argument]
74
+ end
75
+ end
76
+
77
+ new_index = 'foo.html'
78
+ for_options "--index", new_index do
79
+ should "try to refresh #{new_index}" do
80
+ assert_equal new_index, @options[:index]
81
+ end
82
+ end
83
+
84
+ new_index = 'foo.html'
85
+ for_options "-i", new_index do
86
+ should "try to refresh #{new_index}" do
87
+ assert_equal new_index, @options[:index]
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class TestSafariBrowser < Test::Unit::TestCase
4
+
5
+ context "foo.txt" do
6
+ setup do
7
+ @browser = BrowserStakeout::Browsers::Safari
8
+ end
9
+
10
+ should "refresh foo.txt" do
11
+ assert_equal "open -g -a Safari.app foo.txt", @browser.refresh("foo.txt")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'browser_stakeout'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixlr-browser_stakeout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Fixler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-13 00:00:00 -07:00
13
+ default_executable: browser_stakeout
14
+ dependencies: []
15
+
16
+ description:
17
+ email: nathan@fixler.org
18
+ executables:
19
+ - browser_stakeout
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION.yml
32
+ - bin/browser_stakeout
33
+ - browser_stakeout.gemspec
34
+ - lib/browser_stakeout.rb
35
+ - lib/browser_stakeout/application.rb
36
+ - lib/browser_stakeout/browsers/firefox.rb
37
+ - lib/browser_stakeout/browsers/safari.rb
38
+ - lib/browser_stakeout/options.rb
39
+ - test/application_test.rb
40
+ - test/browser_stakeout_test.rb
41
+ - test/firefox_test.rb
42
+ - test/options_test.rb
43
+ - test/safari_test.rb
44
+ - test/test_helper.rb
45
+ has_rdoc: false
46
+ homepage: http://github.com/fixlr/browser_stakeout
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Like RStakeout, but for watching static web content in multiple web browsers.
71
+ test_files:
72
+ - test/application_test.rb
73
+ - test/browser_stakeout_test.rb
74
+ - test/firefox_test.rb
75
+ - test/options_test.rb
76
+ - test/safari_test.rb
77
+ - test/test_helper.rb