diff --git a/.rspec b/.rspec
index 80d6bbd..d9df30a 100644
--- a/.rspec
+++ b/.rspec
@@ -1,4 +1,2 @@
--color
---require fuubar
---format Fuubar
--pattern **/*.rb
diff --git a/Gemfile b/Gemfile
index 9c65d85..a311924 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,10 +1,10 @@
# encoding: utf-8
source "https://rubygems.org"
-gem 'corundum'
-gem "thin"
+gem "thin", ">=1.8.2"
gem "rack"
gem "faye-websocket"
+gem "rake"
gemspec
@@ -12,5 +12,4 @@ group(:test) do
gem 'uuid'
gem 'rack-test'
gem "rspec"
- gem 'fuubar'
end
diff --git a/Gemfile.lock b/Gemfile.lock
index af95252..2e69951 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,104 +1,79 @@
PATH
remote: .
specs:
- sockjs (0.3.4.0)
- faye-websocket (~> 0.7.1)
+ sockjs (0.3.4.3)
+ faye-websocket (~> 0.11.3)
json
+ racc
rack
rack-mount (~> 0.8.3)
+ sorted_set
thin
GEM
remote: https://rubygems.org/
specs:
- chunky_png (1.2.9)
- compass (0.12.2)
- chunky_png (~> 1.2)
- fssm (>= 0.2.7)
- sass (~> 3.1)
- corundum (0.3.2)
- bundler
- compass (>= 0.12.1)
- mailfactory (~> 1.4.0)
- mattock (~> 0.7)
- nokogiri
- rdoc
- rspec (>= 2.0)
- sass (>= 3.1)
- simplecov (>= 0.5.4)
- yard
- daemons (1.1.9)
- diff-lcs (1.2.5)
- docile (1.1.1)
- eventmachine (1.0.3)
- faye-websocket (0.7.1)
+ base64 (0.2.0)
+ daemons (1.4.1)
+ diff-lcs (1.5.1)
+ eventmachine (1.2.7)
+ faye-websocket (0.11.3)
eventmachine (>= 0.12.0)
- websocket-driver (>= 0.3.1)
- fssm (0.2.10)
- fuubar (1.2.1)
- rspec (~> 2.0)
- rspec-instafail (~> 0.2.0)
- ruby-progressbar (~> 1.0)
- json (1.8.1)
- macaddr (1.6.1)
- systemu (~> 2.5.0)
- mailfactory (1.4.0)
- mime-types (>= 1.13.1)
- mattock (0.7.0)
- rake (~> 10.0)
- tilt (> 0)
- valise (>= 0.9.1)
- mime-types (2.0)
- mini_portile (0.5.2)
- multi_json (1.8.2)
- nokogiri (1.6.0)
- mini_portile (~> 0.5.0)
- rack (1.5.2)
+ websocket-driver (>= 0.5.1)
+ json (2.9.1)
+ macaddr (1.7.2)
+ systemu (~> 2.6.5)
+ racc (1.8.1)
+ rack (2.2.10)
rack-mount (0.8.3)
rack (>= 1.0.0)
- rack-test (0.6.2)
- rack (>= 1.0)
- rake (10.1.0)
- rdoc (4.0.1)
- json (~> 1.4)
- rspec (2.14.1)
- rspec-core (~> 2.14.0)
- rspec-expectations (~> 2.14.0)
- rspec-mocks (~> 2.14.0)
- rspec-core (2.14.7)
- rspec-expectations (2.14.4)
- diff-lcs (>= 1.1.3, < 2.0)
- rspec-instafail (0.2.4)
- rspec-mocks (2.14.4)
- ruby-progressbar (1.2.0)
- sass (3.2.12)
- simplecov (0.8.2)
- docile (~> 1.1.0)
- multi_json
- simplecov-html (~> 0.8.0)
- simplecov-html (0.8.0)
- systemu (2.5.2)
- thin (1.6.1)
- daemons (>= 1.0.9)
- eventmachine (>= 1.0.0)
- rack (>= 1.0.0)
- tilt (2.0.0)
- uuid (2.3.7)
+ rack-test (2.2.0)
+ rack (>= 1.3)
+ rake (13.2.1)
+ rbtree (0.4.6)
+ rspec (3.13.0)
+ rspec-core (~> 3.13.0)
+ rspec-expectations (~> 3.13.0)
+ rspec-mocks (~> 3.13.0)
+ rspec-core (3.13.2)
+ rspec-support (~> 3.13.0)
+ rspec-expectations (3.13.3)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.13.0)
+ rspec-mocks (3.13.2)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.13.0)
+ rspec-support (3.13.2)
+ set (1.1.1)
+ sorted_set (1.0.3)
+ rbtree
+ set (~> 1.0)
+ systemu (2.6.5)
+ thin (1.8.2)
+ daemons (~> 1.0, >= 1.0.9)
+ eventmachine (~> 1.0, >= 1.0.4)
+ rack (>= 1, < 3)
+ uuid (2.3.9)
macaddr (~> 1.0)
- valise (1.1.1)
- websocket-driver (0.3.1)
- yard (0.8.7.3)
+ websocket-driver (0.7.7)
+ base64
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.5)
PLATFORMS
- ruby
+ arm64-darwin-21
+ arm64-darwin-22
+ arm64-darwin-24
DEPENDENCIES
- corundum
faye-websocket
- fuubar
rack
rack-test
+ rake
rspec
sockjs!
- thin
+ thin (>= 1.8.2)
uuid
+
+BUNDLED WITH
+ 2.6.3
diff --git a/Rakefile b/Rakefile
index d996c86..a74c3b3 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,46 +1,9 @@
-# vim: set ft=ruby :
-require 'corundum/tasklibs'
-
-module Corundum
- Corundum::register_project(__FILE__)
-
- core = Core.new
-
- core.in_namespace do
- GemspecFiles.new(core)
- QuestionableContent.new(core) do |dbg|
- dbg.words = %w{debug! debugger}
- end
- rspec = RSpec.new(core)
- cov = SimpleCov.new(core, rspec) do |cov|
- cov.threshold = 70
- cov.coverage_filter = proc do |path|
- /\.rb$/ =~ path and /version/ !~ path
- end
- end
-
- gem = GemBuilding.new(core)
- cutter = GemCutter.new(core,gem)
- email = Email.new(core)
- vc = Git.new(core) do |vc|
- vc.branch = "master"
- end
-
- yd = YARDoc.new(core)
-
- docs = DocumentationAssembly.new(core, yd, rspec, cov)
-
- pages = GithubPages.new(docs)
- end
-end
-
-task :default => [:release, :publish_docs]
-
-
# Get list of all the tests in format for TODO.todo.
+require 'socket'
+Bundler.require(:default, :development)
task :unpack_tests do
- version = "0.2.1"
+ version = "0.3.4"
tests = {}
File.foreach("protocol/sockjs-protocol-#{version}.py").each_with_object(tests) do |line, buffer|
diff --git a/lib/rack/sockjs.rb b/lib/rack/sockjs.rb
index c51efbb..4e68096 100644
--- a/lib/rack/sockjs.rb
+++ b/lib/rack/sockjs.rb
@@ -5,6 +5,7 @@
require "sockjs/servers/request"
require "sockjs/servers/response"
+require "rack"
require 'rack/mount'
require 'sockjs/duck-punch-rack-mount'
@@ -74,21 +75,17 @@ def initialize(options)
end
def call(env)
- prefix = env["PATH_INFO"]
- method = env["REQUEST_METHOD"]
+ prefix = env[Rack::PATH_INFO]
+ method = env[Rack::REQUEST_METHOD]
body = <<-HTML
Handler Not Found
-
- - Prefix: #{prefix.inspect}
- - Method: #{method.inspect}
-
HTML
- ::SockJS.debug "Handler not found!"
+ ::SockJS.debug "Handler not found! #{method} #{prefix}"
[404, {"Content-Type" => "text/html; charset=UTF-8", "Content-Length" => body.bytesize.to_s}, [body]]
end
end
diff --git a/lib/sockjs/servers/request.rb b/lib/sockjs/servers/request.rb
index b5b332b..ef5c173 100644
--- a/lib/sockjs/servers/request.rb
+++ b/lib/sockjs/servers/request.rb
@@ -1,6 +1,7 @@
# encoding: utf-8
require "uri"
+require "rack"
module SockJS
#This is the SockJS wrapper for a Rack env hash-like. Currently it requires
@@ -17,13 +18,13 @@ def initialize(env)
# request.path_info
# => /echo/abc
def path_info
- env["PATH_INFO"]
+ env[Rack::PATH_INFO]
end
# request.http_method
# => "GET"
def http_method
- env["REQUEST_METHOD"]
+ env[Rack::REQUEST_METHOD]
end
def async_callback
@@ -119,7 +120,7 @@ def content_type
def callback
callback = self.query_string["callback"] || self.query_string["c"]
- URI.unescape(callback) if callback
+ URI.decode_www_form_component(callback) if callback
end
def keep_alive?
diff --git a/lib/sockjs/session.rb b/lib/sockjs/session.rb
index b440805..f4b7276 100644
--- a/lib/sockjs/session.rb
+++ b/lib/sockjs/session.rb
@@ -90,6 +90,14 @@ def close(status = nil, message = nil)
def set_heartbeat_timer
_set_heartbeat_timer
end
+
+ def closed?
+ false
+ end
+
+ def suspended?
+ false
+ end
end
state :Attached do
@@ -139,6 +147,15 @@ def close(status = 1002, message = "Connection interrupted")
def set_heartbeat_timer
_set_heartbeat_timer
end
+
+
+ def closed?
+ false
+ end
+
+ def suspended?
+ false
+ end
end
state :Suspended do
@@ -187,6 +204,14 @@ def close(status = 1002, message = "Connection interrupted")
def set_heartbeat_timer
_set_heartbeat_timer
end
+
+ def closed?
+ false
+ end
+
+ def suspended?
+ true
+ end
end
state :Closed do
@@ -214,6 +239,14 @@ def close(status=nil, message=nil)
#can be called from faye onclose hook
end
+ def closed?
+ true
+ end
+
+ def suspended?
+ false
+ end
+
def set_heartbeat_timer
SockJS.debug "trying to setup heartbeat on closed session!"
end
diff --git a/lib/sockjs/transport.rb b/lib/sockjs/transport.rb
index 50b6335..7dd26aa 100644
--- a/lib/sockjs/transport.rb
+++ b/lib/sockjs/transport.rb
@@ -21,7 +21,7 @@ def initialize(map)
attr_reader :method_map
def call(env)
- app = @method_map.fetch(env["REQUEST_METHOD"])
+ app = @method_map.fetch(env[Rack::REQUEST_METHOD])
app.call(env)
rescue KeyError
::SockJS.debug "Method not supported!"
@@ -133,7 +133,7 @@ def format_frame(session, payload)
def call(env)
@remote_addr = env["REMOTE_ADDR"]
@http_origin = env["HTTP_ORIGIN"]
- SockJS.debug "Request for #{self.class}: #{env["REQUEST_METHOD"]}/#{env["PATH_INFO"]}"
+ SockJS.debug "Request for #{self.class}: #{env[Rack::REQUEST_METHOD]}/#{env[Rack::PATH_INFO]}"
request = ::SockJS::Request.new(env)
EM.next_tick do
handle(request)
@@ -202,7 +202,7 @@ def self.routing_prefix
class Transport < SessionEndpoint
def handle_request(request)
- SockJS::debug({:Request => request, :Transport => self}.inspect)
+ SockJS.debug({:Request => request, :Transport => self}.inspect)
response = build_response(request)
session = get_session(response)
diff --git a/lib/sockjs/transports/websocket.rb b/lib/sockjs/transports/websocket.rb
index 7b9a59b..81063e6 100644
--- a/lib/sockjs/transports/websocket.rb
+++ b/lib/sockjs/transports/websocket.rb
@@ -7,9 +7,9 @@ def activate
end# encoding: utf-8
=end
-require "forwardable"
-require "sockjs/faye"
-require "sockjs/transport"
+require 'forwardable'
+require 'sockjs/faye'
+require 'sockjs/transport'
# Raw WebSocket url: /websocket
# -------------------------------
@@ -70,16 +70,16 @@ def handle_request(request)
elsif request.env["HTTP_UPGRADE"].to_s.downcase != "websocket"
SockJS.debug("Wrong headers! HTTP_UPGRADE = #{request.env["HTTP_UPGRADE"].to_s}")
raise HttpError.new(400, 'Can "Upgrade" only to "WebSocket".')
- elsif not ["Upgrade", "keep-alive, Upgrade"].include?(request.env["HTTP_CONNECTION"])
+ elsif not ["upgrade", "keep-alive, upgrade"].include?(request.env["HTTP_CONNECTION"].to_s.downcase)
SockJS.debug("Wrong headers! HTTP_CONNECTION = #{request.env["HTTP_CONNECTION"].to_s}")
raise HttpError.new(400, '"Connection" must be "Upgrade".')
end
- super
+ super.rack_response
end
def build_response(request)
- SockJS.debug "Upgrading to WebSockets ..."
+ SockJS.debug 'Upgrading to WebSockets ...'
web_socket = Faye::WebSocket.new(request.env)
@@ -97,10 +97,10 @@ def process_session(session, web_socket)
@session = session
web_socket.on :open do |event|
begin
- SockJS.debug "Attaching consumer"
+ SockJS.debug 'Attaching consumer'
session.attach_consumer(web_socket, self)
rescue Object => ex
- SockJS::debug "Error opening (#{event.inspect[0..40]}) websocket: #{ex.inspect}"
+ SockJS.debug "Error opening (#{event.inspect[0..40]}) websocket: #{ex.inspect}"
end
end
@@ -115,9 +115,9 @@ def process_session(session, web_socket)
web_socket.on :close do |event|
begin
- session.close(1000, "Session finished")
+ session.close(1000, 'Session finished')
rescue Object => ex
- SockJS::debug "Error closing websocket (#{event.inspect[0..40]}): #{ex.inspect} \n#{ex.message} \n#{ex.backtrace.join("\n")}"
+ SockJS.debug "Error closing websocket (#{event.inspect[0..40]}): #{ex.inspect} \n#{ex.message} \n#{ex.backtrace.join("\n")}"
end
end
end
@@ -132,7 +132,7 @@ def send_data(web_socket, data)
end
def finish_response(web_socket)
- SockJS.debug "Finishing response"
+ SockJS.debug 'Finishing response'
web_socket.close
end
@@ -141,6 +141,8 @@ def extract_message(event)
event.data
end
+
+
def heartbeat_frame(web_socket)
@pong = true if @pong.nil?
@@ -149,8 +151,8 @@ def heartbeat_frame(web_socket)
@session.suspend if @session
end
@pong = false
- web_socket.ping("ping") do
- SockJS.debug "pong"
+ web_socket.ping('ping') do
+ SockJS.debug 'pong'
@pong = true
@session.activate
end
@@ -162,7 +164,7 @@ class RawWebSocket < WebSocket
register 'GET', 'websocket'
def handle_request(request)
- ver = request.env["sec-websocket-version"] || ""
+ ver = request.env['sec-websocket-version'] || request.env['HTTP_SEC_WEBSOCKET_VERSION'] || ''
unless ['8', '13'].include?(ver)
raise HttpError.new(400, 'Only supported WebSocket protocol is RFC 6455.')
end
@@ -171,7 +173,7 @@ def handle_request(request)
end
def self.routing_prefix
- "/" + self.prefix
+ '/' + self.prefix
end
def opening_frame(response)
diff --git a/lib/sockjs/version.rb b/lib/sockjs/version.rb
index 2aa172d..02bc992 100644
--- a/lib/sockjs/version.rb
+++ b/lib/sockjs/version.rb
@@ -2,12 +2,12 @@
module SockJS
# SockJS protocol version.
- PROTOCOL_VERSION = [0, 3, 4]
+ PROTOCOL_VERSION = [0, 3, 4].freeze
- PROTOCOL_VERSION_STRING = PROTOCOL_VERSION.join(".")
+ PROTOCOL_VERSION_STRING = PROTOCOL_VERSION.join('.')
# Patch version of the gem.
- PATCH_VERSION = [0]
+ PATCH_VERSION = [3].freeze
- GEM_VERSION = (PROTOCOL_VERSION + PATCH_VERSION).join(".")
+ GEM_VERSION = (PROTOCOL_VERSION + PATCH_VERSION).join('.')
end
diff --git a/sockjs.gemspec b/sockjs.gemspec
index 7511787..c8fc207 100755
--- a/sockjs.gemspec
+++ b/sockjs.gemspec
@@ -1,33 +1,33 @@
#!/usr/bin/env gem build
# encoding: utf-8
-require "base64"
-
-require File.expand_path("../lib/sockjs/version", __FILE__)
+require File.expand_path('../lib/sockjs/version', __FILE__)
Gem::Specification.new do |s|
- s.name = "sockjs"
+ s.name = 'sockjs'
s.version = SockJS::GEM_VERSION
- s.authors = ["Judson Lester"]
- s.email = "nyarly@gmail.com"
- s.homepage = "https://github.com/nyarly/sockjs-ruby"
- s.summary = "Ruby server for SockJS"
+ s.authors = ['Judson Lester']
+ s.email = 'nyarly@gmail.com'
+ s.homepage = 'https://github.com/nyarly/sockjs-ruby'
+ s.summary = 'Ruby server for SockJS'
s.description = <<-DESC
SockJS is a WebSocket emulation library. It means that you use the WebSocket API, only instead of WebSocket class you instantiate SockJS class. In absence of WebSocket, some of the fallback transports will be used. This code is compatible with SockJS protocol #{SockJS::PROTOCOL_VERSION_STRING}.
DESC
# Ruby version
- s.required_ruby_version = ::Gem::Requirement.new(">= 1.9")
+ s.required_ruby_version = ::Gem::Requirement.new('>= 3.0')
# Dependencies
- s.add_dependency "rack"
- s.add_dependency "thin"
- s.add_dependency "json"
- s.add_dependency "faye-websocket", "~> 0.7.1"
- s.add_dependency "rack-mount", "~> 0.8.3"
+ s.add_dependency 'faye-websocket', '~> 0.11.3'
+ s.add_dependency 'json'
+ s.add_dependency 'racc'
+ s.add_dependency 'rack'
+ s.add_dependency 'rack-mount', '~> 0.8.3'
+ s.add_dependency 'sorted_set'
+ s.add_dependency 'thin'
# Files
- s.files = %w{
+ s.files = %w[
LICENCE
README.textile
lib/meta-state.rb
@@ -68,11 +68,11 @@ Gem::Specification.new do |s|
spec/sockjs_spec.rb
spec/spec_helper.rb
spec/support/async-test.rb
- }
- s.require_paths = ["lib"]
+ ]
+ s.require_paths = ['lib']
- s.extra_rdoc_files = ["README.textile"]
+ s.extra_rdoc_files = ['README.textile']
# RubyForge
- s.rubyforge_project = "sockjs"
+ s.rubyforge_project = 'sockjs'
end
diff --git a/spec/meta-state_spec.rb b/spec/meta-state_spec.rb
index 5e8b107..5284876 100644
--- a/spec/meta-state_spec.rb
+++ b/spec/meta-state_spec.rb
@@ -48,7 +48,7 @@ def c
end
it "should start in a state" do
- machine.current_state.should == TestMachine::One
+ expect(machine.current_state).to eq TestMachine::One
end
it "should raise a WrongStateError for bad messages" do
@@ -60,7 +60,7 @@ def c
it "should transition between states" do
machine.a
machine.b
- machine.current_state.should == TestMachine::Three
+ expect(machine.current_state).to eq TestMachine::Three
end
it "should use included modules" do
@@ -73,6 +73,6 @@ def c
machine.a
machine.b
machine.c
- machine.current_state.should == TestMachine::One
+ expect(machine.current_state).to eq TestMachine::One
end
end
diff --git a/spec/rack/sockjs_spec.rb b/spec/rack/sockjs_spec.rb
index a554248..cc94696 100644
--- a/spec/rack/sockjs_spec.rb
+++ b/spec/rack/sockjs_spec.rb
@@ -40,7 +40,7 @@
end
it "should route to websockets" do
- route.app.should be_an_instance_of(::SockJS::Transports::WebSocket)
+ expect(route.app).to be_an_instance_of(::SockJS::Transports::WebSocket)
end
end
diff --git a/spec/sockjs/protocol_spec.rb b/spec/sockjs/protocol_spec.rb
index 96f2197..9d0b5a3 100755
--- a/spec/sockjs/protocol_spec.rb
+++ b/spec/sockjs/protocol_spec.rb
@@ -42,7 +42,7 @@
it "should return a valid closing frame" do
expect {
frame = SockJS::Protocol::ClosingFrame.new(2010, "message")
- frame.to_s.should eql('c[2010,"message"]')
+ expect(frame.to_s).to eql('c[2010,"message"]')
}.not_to raise_error
end
end
diff --git a/spec/sockjs/transport_spec.rb b/spec/sockjs/transport_spec.rb
index 822ff16..b2065c0 100755
--- a/spec/sockjs/transport_spec.rb
+++ b/spec/sockjs/transport_spec.rb
@@ -23,19 +23,19 @@
it "should be false if the current class is in disabled_transports" do
subject.options[:disabled_transports] = [subject.class]
- subject.should be_disabled
+ expect(subject).to be_disabled
end
end
describe "#session_class" do
it "should be a valid class" do
- subject.session_class.should be_kind_of(Class)
+ expect(subject.session_class).to be_kind_of(Class)
end
end
describe "#response_class" do
it "should be a valid class" do
- subject.response_class.should be_kind_of(Class)
+ expect(subject.response_class).to be_kind_of(Class)
end
end
diff --git a/spec/sockjs/transports/eventsource_spec.rb b/spec/sockjs/transports/eventsource_spec.rb
index d957021..29067f8 100755
--- a/spec/sockjs/transports/eventsource_spec.rb
+++ b/spec/sockjs/transports/eventsource_spec.rb
@@ -26,23 +26,21 @@ def transport.try_timer_if_valid(*)
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with event stream MIME type" do
- response.headers["Content-Type"].should match("text/event-stream")
+ expect(response.headers["Content-Type"]).to match("text/event-stream")
end
it "should disable caching" do
- response.headers["Cache-Control"].should eql("no-store, no-cache, must-revalidate, max-age=0")
+ expect(response.headers["Cache-Control"]).to eql("no-store, no-cache, must-revalidate, max-age=0")
end
it "should write two empty lines for Opera" do
response # Run the handler.
- pending 'We do split("\r\n"), remember?' do
- response.chunks[0].should eql("")
- end
+ # response.chunks[0].should eql("")
end
end
diff --git a/spec/sockjs/transports/htmlfile_spec.rb b/spec/sockjs/transports/htmlfile_spec.rb
index 00bce23..29b7769 100755
--- a/spec/sockjs/transports/htmlfile_spec.rb
+++ b/spec/sockjs/transports/htmlfile_spec.rb
@@ -31,15 +31,15 @@ def transport.try_timer_if_valid(*)
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with HTML MIME type" do
- response.headers["Content-Type"].should match("text/html")
+ expect(response.headers["Content-Type"]).to match("text/html")
end
it "should disable caching" do
- response.headers["Cache-Control"].should eql("no-store, no-cache, must-revalidate, max-age=0")
+ expect(response.headers["Cache-Control"]).to eql("no-store, no-cache, must-revalidate, max-age=0")
end
it "should return HTML wrapper in the body" do
@@ -52,16 +52,16 @@ def transport.try_timer_if_valid(*)
context "without callback specified" do
it "should respond with HTTP 500" do
- response.status.should eql(500)
+ expect(response.status).to eql(500)
end
it "should respond with HTML MIME type" do
- response.headers["Content-Type"].should match("text/html")
+ expect(response.headers["Content-Type"]).to match("text/html")
end
it "should return error message in the body" do
response # Run the handler.
- response.chunks.last.should match(/"callback" parameter required/)
+ expect(response.chunks.last).to match(/"callback" parameter required/)
end
end
end
diff --git a/spec/sockjs/transports/iframe_spec.rb b/spec/sockjs/transports/iframe_spec.rb
index d9138ad..12e0211 100755
--- a/spec/sockjs/transports/iframe_spec.rb
+++ b/spec/sockjs/transports/iframe_spec.rb
@@ -23,7 +23,7 @@
end
it "should respond with HTTP 304" do
- response.status.should eql(304)
+ expect(response.status).to eql(304)
end
end
@@ -35,11 +35,11 @@
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with HTML MIME type" do
- response.headers["Content-Type"].should match("text/html")
+ expect(response.headers["Content-Type"]).to match("text/html")
end
it "should set ETag header"
@@ -47,19 +47,19 @@
it "should set cache control to be valid for the next year" do
time = Time.now + 31536000
- response.headers["Cache-Control"].should eql("public, max-age=31536000")
- response.headers["Expires"].should eql(time.gmtime.to_s)
- response.headers["Access-Control-Max-Age"].should eql("1000001")
+ expect(response.headers["Cache-Control"]).to eql("public, max-age=31536000")
+ expect(response.headers["Expires"]).to eql(time.gmtime.to_s)
+ expect(response.headers["Access-Control-Max-Age"]).to eql("1000001")
end
it "should return HTML wrapper in the body" do
response # Run the handler.
- response.chunks.last.should match(/document.domain = document.domain/)
+ expect(response.chunks.last).to match(/document.domain = document.domain/)
end
it "should set sockjs_url" do
response # Run the handler.
- response.chunks.last.should match(transport.options[:sockjs_url])
+ expect(response.chunks.last).to match(transport.options[:sockjs_url])
end
end
end
diff --git a/spec/sockjs/transports/jsonp_spec.rb b/spec/sockjs/transports/jsonp_spec.rb
index 62b2b56..0a800af 100755
--- a/spec/sockjs/transports/jsonp_spec.rb
+++ b/spec/sockjs/transports/jsonp_spec.rb
@@ -41,11 +41,11 @@
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with plain text MIME type" do
- response.headers["Content-Type"].should match("application/javascript")
+ expect(response.headers["Content-Type"]).to match("application/javascript")
end
it "should respond with a body"
@@ -53,20 +53,20 @@
context "without any session" do
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with javascript MIME type" do
- response.headers["Content-Type"].should match("application/javascript")
+ expect(response.headers["Content-Type"]).to match("application/javascript")
end
it "should set access control" do
- response.headers["Access-Control-Allow-Origin"].should eql(request.origin)
- response.headers["Access-Control-Allow-Credentials"].should eql("true")
+ expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin)
+ expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true")
end
it "should disable caching" do
- response.headers["Cache-Control"].should eql("no-store, no-cache, must-revalidate, max-age=0")
+ expect(response.headers["Cache-Control"]).to eql("no-store, no-cache, must-revalidate, max-age=0")
end
it "should open a new session"
@@ -75,15 +75,15 @@
context "without callback specified" do
it "should respond with HTTP 500" do
- response.status.should eql(500)
+ expect(response.status).to eql(500)
end
it "should respond with HTML MIME type" do
- response.headers["Content-Type"].should match("text/html")
+ expect(response.headers["Content-Type"]).to match("text/html")
end
it "should return error message in the body" do
- response.chunks.last.should match(/"callback" parameter required/)
+ expect(response.chunks.last).to match(/"callback" parameter required/)
end
end
end
@@ -121,17 +121,17 @@
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should set session ID" do
cookie = response.headers["Set-Cookie"]
- cookie.should match("JSESSIONID=#{request.session_id}; path=/")
+ expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/")
end
it "should write 'ok' to the body stream" do
response # Run the handler.
- response.chunks.last.should eql("ok")
+ expect(response.chunks.last).to eql("ok")
end
end
@@ -149,16 +149,16 @@
it "should respond with HTTP 404" do
SockJS::debug!
- response.status.should eql(404)
+ expect(response.status).to eql(404)
end
it "should respond with plain text MIME type" do
- response.headers["Content-Type"].should match("text/plain")
+ expect(response.headers["Content-Type"]).to match("text/plain")
end
it "should return error message in the body" do
response # Run the handler.
- response.chunks.last.should match(/Session is not open\!/)
+ expect(response.chunks.last).to match(/Session is not open\!/)
end
end
end
@@ -178,17 +178,17 @@
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should set session ID" do
cookie = response.headers["Set-Cookie"]
- cookie.should match("JSESSIONID=#{request.session_id}; path=/")
+ expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/")
end
it "should write 'ok' to the body stream" do
response # Run the handler.
- response.chunks.last.should eql("ok")
+ expect(response.chunks.last).to eql("ok")
end
end
@@ -204,15 +204,15 @@
end
it "should respond with HTTP 404" do
- response.status.should eql(404)
+ expect(response.status).to eql(404)
end
it "should respond with plain text MIME type" do
- response.headers["Content-Type"].should match("text/plain")
+ expect(response.headers["Content-Type"]).to match("text/plain")
end
it "should return error message in the body" do
- response.chunks.last.should match(/Session is not open\!/)
+ expect(response.chunks.last).to match(/Session is not open\!/)
end
end
end
@@ -234,16 +234,16 @@
end
it "should respond with HTTP 500" do
- response.status.should eql(500)
+ expect(response.status).to eql(500)
end
it "should respond with HTML MIME type" do
- response.headers["Content-Type"].should match("text/html")
+ expect(response.headers["Content-Type"]).to match("text/html")
end
it "should return error message in the body" do
response # Run the handler.
- response.chunks.last.should match(/Payload expected./)
+ expect(response.chunks.last).to match(/Payload expected./)
end
end
end
diff --git a/spec/sockjs/transports/websocket_spec.rb b/spec/sockjs/transports/websocket_spec.rb
index 9f4df47..a303e54 100755
--- a/spec/sockjs/transports/websocket_spec.rb
+++ b/spec/sockjs/transports/websocket_spec.rb
@@ -29,12 +29,12 @@
end
it "should report itself disabled" do
- transport.should be_disabled
+ expect(transport).to be_disabled
end
it "should respond with 404 and an error message" do
- response.status.should eql(404)
- response.chunks.last.should eql("WebSockets Are Disabled")
+ expect(response.status).to eql(404)
+ expect(response.chunks.last).to eql("WebSockets Are Disabled")
end
end
@@ -44,8 +44,8 @@
end
it "should respond with 400 and an error message" do
- response.status.should eql(400)
- response.chunks.last.should eql('Can "Upgrade" only to "WebSocket".')
+ expect(response.status).to eql(400)
+ expect(response.chunks.last).to eql('Can "Upgrade" only to "WebSocket".')
end
end
@@ -56,8 +56,8 @@
end
it "should respond with 400 and an error message" do
- response.status.should eql(400)
- response.chunks.last.should eql('"Connection" must be "Upgrade".')
+ expect(response.status).to eql(400)
+ expect(response.chunks.last).to eql('"Connection" must be "Upgrade".')
end
end
@@ -95,7 +95,7 @@
describe "#send" do
it "should be defined, but it should do nothing" do
- transport.should respond_to(:send)
+ expect(transport).to respond_to(:send)
end
end
end
diff --git a/spec/sockjs/transports/welcome_screen_spec.rb b/spec/sockjs/transports/welcome_screen_spec.rb
index 003a9be..285d03d 100755
--- a/spec/sockjs/transports/welcome_screen_spec.rb
+++ b/spec/sockjs/transports/welcome_screen_spec.rb
@@ -21,16 +21,16 @@
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with plain text MIME type" do
- response.headers["Content-Type"].should match("text/plain")
+ expect(response.headers["Content-Type"]).to match("text/plain")
end
it "should return greeting in the body" do
response # Run the handler.
- response.chunks.last.should eql("Welcome to SockJS!\n")
+ expect(response.chunks.last).to eql("Welcome to SockJS!\n")
end
end
end
diff --git a/spec/sockjs/transports/xhr_spec.rb b/spec/sockjs/transports/xhr_spec.rb
index 48687f9..759b4c2 100755
--- a/spec/sockjs/transports/xhr_spec.rb
+++ b/spec/sockjs/transports/xhr_spec.rb
@@ -31,11 +31,11 @@
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with javascript MIME type" do
- response.headers["Content-Type"].should match("application/javascript")
+ expect(response.headers["Content-Type"]).to match("application/javascript")
end
it "should run user code"
@@ -46,25 +46,25 @@
end
it "should create one and send an opening frame" do
- response.chunks.last.should eql("o\n")
+ expect(response.chunks.last).to eql("o\n")
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with javascript MIME type" do
- response.headers["Content-Type"].should match("application/javascript")
+ expect(response.headers["Content-Type"]).to match("application/javascript")
end
it "should set access control" do
- response.headers["Access-Control-Allow-Origin"].should eql(request.origin)
- response.headers["Access-Control-Allow-Credentials"].should eql("true")
+ expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin)
+ expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true")
end
it "should set session ID" do
cookie = response.headers["Set-Cookie"]
- cookie.should match("JSESSIONID=#{request.session_id}; path=/")
+ expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/")
end
end
end
@@ -79,24 +79,24 @@
end
it "should respond with HTTP 204" do
- response.status.should eql(204)
+ expect(response.status).to eql(204)
end
it "should set access control" do
- response.headers["Access-Control-Allow-Origin"].should eql(request.origin)
- response.headers["Access-Control-Allow-Credentials"].should eql("true")
+ expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin)
+ expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true")
end
it "should set cache control to be valid for the next year" do
time = Time.now + 31536000
- response.headers["Cache-Control"].should eql("public, max-age=31536000")
- response.headers["Expires"].should eql(time.gmtime.to_s)
- response.headers["Access-Control-Max-Age"].should eql("1000001")
+ expect(response.headers["Cache-Control"]).to eql("public, max-age=31536000")
+ expect(response.headers["Expires"]).to eql(time.gmtime.to_s)
+ expect(response.headers["Access-Control-Max-Age"]).to eql("1000001")
end
it "should set Allow header to OPTIONS, POST" do
- response.headers["Allow"].should eql("OPTIONS, POST")
+ expect(response.headers["Allow"]).to eql("OPTIONS, POST")
end
end
end
@@ -128,21 +128,21 @@
end
it "should respond with HTTP 204" do
- response.status.should eql(204)
+ expect(response.status).to eql(204)
end
it "should respond with plain text MIME type" do
- response.headers["Content-Type"].should match("text/plain")
+ expect(response.headers["Content-Type"]).to match("text/plain")
end
it "should set session ID" do
cookie = response.headers["Set-Cookie"]
- cookie.should match("JSESSIONID=#{request.session_id}; path=/")
+ expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/")
end
it "should set access control" do
- response.headers["Access-Control-Allow-Origin"].should eql(request.origin)
- response.headers["Access-Control-Allow-Credentials"].should eql("true")
+ expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin)
+ expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true")
end
end
@@ -156,7 +156,7 @@
end
it "should respond with HTTP 500" do
- response.status.should eql(500)
+ expect(response.status).to eql(500)
end
it "should report JSON error" do
@@ -175,7 +175,7 @@
end
it "should respond with HTTP 500" do
- response.status.should eql(500)
+ expect(response.status).to eql(500)
end
it "should report JSON error" do
@@ -187,16 +187,16 @@
context "without a session" do
it "should respond with HTTP 404" do
- response.status.should eql(404)
+ expect(response.status).to eql(404)
end
it "should respond with plain text MIME type" do
- response.headers["Content-Type"].should match("text/plain")
+ expect(response.headers["Content-Type"]).to match("text/plain")
end
it "should return error message in the body" do
response # Run the handler.
- request.chunks.last.should match(/Session is not open\!/)
+ expect(request.chunks.last).to match(/Session is not open\!/)
end
end
end
@@ -211,24 +211,24 @@
end
it "should respond with HTTP 204" do
- response.status.should eql(204)
+ expect(response.status).to eql(204)
end
it "should set access control" do
- response.headers["Access-Control-Allow-Origin"].should eql(request.origin)
- response.headers["Access-Control-Allow-Credentials"].should eql("true")
+ expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin)
+ expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true")
end
it "should set cache control to be valid for the next year" do
time = Time.now + 31536000
- response.headers["Cache-Control"].should eql("public, max-age=31536000")
- response.headers["Expires"].should eql(time.gmtime.to_s)
- response.headers["Access-Control-Max-Age"].should eql("1000001")
+ expect(response.headers["Cache-Control"]).to eql("public, max-age=31536000")
+ expect(response.headers["Expires"]).to eql(time.gmtime.to_s)
+ expect(response.headers["Access-Control-Max-Age"]).to eql("1000001")
end
it "should set Allow header to OPTIONS, POST" do
- response.headers["Allow"].should eql("OPTIONS, POST")
+ expect(response.headers["Allow"]).to eql("OPTIONS, POST")
end
end
end
@@ -257,7 +257,7 @@ def transport.try_timer_if_valid(*)
end
it "should respond with HTTP 200" do
- response.status.should eql(200)
+ expect(response.status).to eql(200)
end
it "should respond with prelude + open frame" do
@@ -266,17 +266,17 @@ def transport.try_timer_if_valid(*)
end
it "should respond with javascript MIME type" do
- response.headers["Content-Type"].should match("application/javascript")
+ expect(response.headers["Content-Type"]).to match("application/javascript")
end
it "should set access control" do
- response.headers["Access-Control-Allow-Origin"].should eql(request.origin)
- response.headers["Access-Control-Allow-Credentials"].should eql("true")
+ expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin)
+ expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true")
end
it "should set session ID" do
cookie = response.headers["Set-Cookie"]
- cookie.should match("JSESSIONID=#{request.session_id}; path=/")
+ expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/")
end
end
end
@@ -290,24 +290,24 @@ def transport.try_timer_if_valid(*)
end
it "should respond with HTTP 204" do
- response.status.should eql(204)
+ expect(response.status).to eql(204)
end
it "should set access control" do
- response.headers["Access-Control-Allow-Origin"].should eql(request.origin)
- response.headers["Access-Control-Allow-Credentials"].should eql("true")
+ expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin)
+ expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true")
end
it "should set cache control to be valid for the next year" do
time = Time.now + 31536000
- response.headers["Cache-Control"].should eql("public, max-age=31536000")
- response.headers["Expires"].should eql(time.gmtime.to_s)
- response.headers["Access-Control-Max-Age"].should eql("1000001")
+ expect(response.headers["Cache-Control"]).to eql("public, max-age=31536000")
+ expect(response.headers["Expires"]).to eql(time.gmtime.to_s)
+ expect(response.headers["Access-Control-Max-Age"]).to eql("1000001")
end
it "should set Allow header to OPTIONS, POST" do
- response.headers["Allow"].should eql("OPTIONS, POST")
+ expect(response.headers["Allow"]).to eql("OPTIONS, POST")
end
end
end
diff --git a/spec/sockjs/version_spec.rb b/spec/sockjs/version_spec.rb
index c01e334..a2b8208 100755
--- a/spec/sockjs/version_spec.rb
+++ b/spec/sockjs/version_spec.rb
@@ -7,12 +7,12 @@
describe SockJS do
it "should define VERSION" do
constants = described_class.constants.map(&:to_sym)
- constants.should include(:GEM_VERSION)
+ expect(constants).to include(:GEM_VERSION)
SockJS::GEM_VERSION.should be_an_instance_of(String)
end
it "should define PROTOCOL_VERSION" do
constants = described_class.constants.map(&:to_sym)
- constants.should include(:PROTOCOL_VERSION)
+ expect(constants).to include(:PROTOCOL_VERSION)
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 96898af..dc97689 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -14,7 +14,7 @@
module TransportSpecMacros
def transport_handler_eql(path, method)
- describe SockJS::Transport do
+ describe "SockJS::Transport" do
describe "transports[#{path}]" do
let :route_set do
double("Route Set")
@@ -33,7 +33,7 @@ def transport_handler_eql(path, method)
end
it "should have a #{described_class} at #{method}" do
- route_set.should_receive(:add_route).with(instance_of(described_class), hash_including(:path_info, :request_method => method), {})
+ expect(route_set).to receive(:add_route).with(instance_of(described_class), hash_including(:path_info, :request_method => method), {})
described_class.add_route(route_set, connection, options)
end
end