a little cleanup, add cucumber, add support for ignoring particular browsers
This commit is contained in:
parent
67d07df724
commit
e223e1ddbf
@ -1,7 +1,7 @@
|
|||||||
# A sample Guardfile
|
# A sample Guardfile
|
||||||
# More info at https://github.com/guard/guard#readme
|
# More info at https://github.com/guard/guard#readme
|
||||||
|
|
||||||
guard 'rspec', :version => 2 do
|
guard 'rspec', :version => 2, :cli => '-c' do
|
||||||
watch(%r{^spec/.+_spec\.rb$})
|
watch(%r{^spec/.+_spec\.rb$})
|
||||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||||
watch('spec/spec_helper.rb') { "spec" }
|
watch('spec/spec_helper.rb') { "spec" }
|
||||||
@ -10,3 +10,8 @@ end
|
|||||||
guard 'livereload' do
|
guard 'livereload' do
|
||||||
watch('index.html')
|
watch('index.html')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guard 'cucumber' do
|
||||||
|
watch(%r{^features/.+\.feature$})
|
||||||
|
watch(%r{^features/support/.+$}) { 'features' }
|
||||||
|
end
|
||||||
|
6
Rakefile
6
Rakefile
@ -24,5 +24,9 @@ require 'rspec/core/rake_task'
|
|||||||
|
|
||||||
RSpec::Core::RakeTask.new(:spec)
|
RSpec::Core::RakeTask.new(:spec)
|
||||||
|
|
||||||
task :default => :spec
|
require 'cucumber/rake/task'
|
||||||
|
|
||||||
|
Cucumber::Rake::Task.new(:cucumber)
|
||||||
|
|
||||||
|
task :default => [ :spec, :cucumber ]
|
||||||
|
|
||||||
|
11
features/skip_certain_browsers.feature
Normal file
11
features/skip_certain_browsers.feature
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
Feature: Skip Certain Browsers
|
||||||
|
Scenario Outline:
|
||||||
|
Given I have a Rack app with Rack::LiveReload
|
||||||
|
When I make a request to "/" with the following headers:
|
||||||
|
| HTTP_USER_AGENT | <user agent> |
|
||||||
|
Then I should not have any Rack::LiveReload code
|
||||||
|
|
||||||
|
Scenarios: Browsers to check for
|
||||||
|
| user agent |
|
||||||
|
| MSIE |
|
||||||
|
|
@ -0,0 +1,7 @@
|
|||||||
|
Given /^I have a Rack app with Rack::LiveReload$/ do
|
||||||
|
@app = Rack::Builder.new do
|
||||||
|
use Rack::LiveReload
|
||||||
|
|
||||||
|
run lambda { |env| [ 200, { 'Content-Type' => 'text/html' }, [ "<html><head></head><body></body></html>" ] ] }
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,4 @@
|
|||||||
|
Then /^I should not have any Rack::LiveReload code$/ do
|
||||||
|
@response.body.should_not include("rack/livereload.js")
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,6 @@
|
|||||||
|
When /^I make a request to "([^"]*)" with the following headers:$/ do |uri, table|
|
||||||
|
@request = Rack::MockRequest.new(@app)
|
||||||
|
|
||||||
|
@response = @request.get(uri, table.rows_hash)
|
||||||
|
end
|
||||||
|
|
3
features/support/env.rb
Normal file
3
features/support/env.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
require 'rack'
|
||||||
|
require 'rack-livereload'
|
||||||
|
|
@ -1,2 +1,2 @@
|
|||||||
<html>
|
<html>
|
||||||
<head><title>Hi</title></head><body>Lats</body></html>
|
<head><title>Hi</title></head><body>Rats</body></html>
|
||||||
|
@ -5,11 +5,12 @@ module Rack
|
|||||||
LIVERELOAD_JS_PATH = '/__rack/livereload.js'
|
LIVERELOAD_JS_PATH = '/__rack/livereload.js'
|
||||||
LIVERELOAD_LOCAL_URI = 'http://localhost:35729/livereload.js'
|
LIVERELOAD_LOCAL_URI = 'http://localhost:35729/livereload.js'
|
||||||
|
|
||||||
|
BAD_USER_AGENTS = [ %r{MSIE} ]
|
||||||
|
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
|
|
||||||
def initialize(app, options = {})
|
def initialize(app, options = {})
|
||||||
@app = app
|
@app, @options = app, options
|
||||||
@options = options
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def use_vendored?
|
def use_vendored?
|
||||||
@ -48,9 +49,8 @@ module Rack
|
|||||||
else
|
else
|
||||||
status, headers, body = @app.call(env)
|
status, headers, body = @app.call(env)
|
||||||
|
|
||||||
if !@options[:ignore] || !@options[:ignore].any? { |filter| env['PATH_INFO'][filter] }
|
if !ignored?(env['PATH_INFO']) && !bad_browser?(env['HTTP_USER_AGENT'])
|
||||||
case headers['Content-Type']
|
if headers['Content-Type'][%r{text/html}]
|
||||||
when %r{text/html}
|
|
||||||
content_length = 0
|
content_length = 0
|
||||||
|
|
||||||
body.each do |line|
|
body.each do |line|
|
||||||
@ -85,6 +85,14 @@ module Rack
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ignored?(path_info)
|
||||||
|
@options[:ignore] and @options[:ignore].any? { |filter| path_info[filter] }
|
||||||
|
end
|
||||||
|
|
||||||
|
def bad_browser?(user_agent)
|
||||||
|
BAD_USER_AGENTS.any? { |pattern| (user_agent || '')[pattern] }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def deliver_file(file)
|
def deliver_file(file)
|
||||||
type = case ::File.extname(file)
|
type = case ::File.extname(file)
|
||||||
|
@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|||||||
|
|
||||||
# specify any dependencies here; for example:
|
# specify any dependencies here; for example:
|
||||||
s.add_development_dependency "rspec"
|
s.add_development_dependency "rspec"
|
||||||
|
s.add_development_dependency "cucumber"
|
||||||
s.add_development_dependency "httparty"
|
s.add_development_dependency "httparty"
|
||||||
s.add_development_dependency "sinatra"
|
s.add_development_dependency "sinatra"
|
||||||
s.add_development_dependency "shotgun"
|
s.add_development_dependency "shotgun"
|
||||||
@ -28,6 +29,7 @@ Gem::Specification.new do |s|
|
|||||||
s.add_development_dependency "mocha"
|
s.add_development_dependency "mocha"
|
||||||
s.add_development_dependency "guard"
|
s.add_development_dependency "guard"
|
||||||
s.add_development_dependency "guard-rspec"
|
s.add_development_dependency "guard-rspec"
|
||||||
|
s.add_development_dependency "guard-cucumber"
|
||||||
s.add_development_dependency "guard-livereload"
|
s.add_development_dependency "guard-livereload"
|
||||||
s.add_development_dependency "webmock"
|
s.add_development_dependency "webmock"
|
||||||
|
|
||||||
|
@ -165,5 +165,25 @@ describe Rack::LiveReload do
|
|||||||
middleware.call(env).should be_true
|
middleware.call(env).should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#ignored?' do
|
||||||
|
let(:path_info) { 'path info' }
|
||||||
|
|
||||||
|
context 'no ignore set' do
|
||||||
|
it { should_not be_ignored(path_info) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'ignore set' do
|
||||||
|
let(:options) { { :ignore => [ %r{#{path_info}} ] } }
|
||||||
|
|
||||||
|
it { should be_ignored(path_info) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#bad_browser?' do
|
||||||
|
let(:user_agent) { described_class::BAD_USER_AGENTS.first.source }
|
||||||
|
|
||||||
|
it { should be_bad_browser(user_agent) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user