Skip to content

Commit

Permalink
Replace Test::Unit with RSpec
Browse files Browse the repository at this point in the history
Existing tests have been rewritten using RSpec.
  • Loading branch information
fohara committed May 18, 2013
1 parent 87a1609 commit f372cec
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source :rubygems
source 'https://rubygems.org'

gemspec
10 changes: 4 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'rake/testtask'
require 'rspec/core/rake_task'

Rake::TestTask.new do |t|
t.test_files = Dir.glob("test/**/test_*.rb")
end
RSpec::Core::RakeTask.new(:spec)

desc "Run tests"
task :default => :test
desc 'Run specs'
task :default => :spec
1 change: 1 addition & 0 deletions red-glass.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Gem::Specification.new do |s|
s.add_dependency 'json'
s.add_dependency 'uuid'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'rspec'
end
55 changes: 55 additions & 0 deletions spec/red_glass_app_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'spec_helper'
require_relative '../lib/red-glass/red-glass-app'

describe 'RedGlass App' do

def app
RedGlassApp
end

let(:event_json) { {"id"=>"", "url"=>"/", "testID"=>"ef100740-4860-012f-0d6d-00254bac7e96", "time"=>1330890507501,
"type"=>"click", "pageX"=>592, "pageY"=>516,
"target"=>"html > body > div#main > div#inner.gainlayout > div.form_controls > a"}}
let(:event_keys) { %w(url testID time type target) }

describe 'status' do
describe 'GET' do
it 'returns a ready message' do
get '/status'
last_response.body.should eq 'ready'
end
end
end

describe 'events' do
describe 'GET' do
context 'when no events are available' do
it 'returns an empty array' do
get '/events'
last_response.body.should eq '[]'
end
end
end

describe 'POST' do
it 'returns multiple events' do
2.times do
post '/', 'event_json' => event_json.to_json
end
get '/events'
JSON.parse(last_response.body).size.should eq 2
end
it 'returns a success response code' do
post '/', 'event_json' => event_json.to_json
last_response.ok?.should be_true
end
it 'returns correctly structured JSON' do
post '/', 'event_json' => event_json.to_json
get '/events'
event_keys.each do |key|
JSON.parse(last_response.body).first[key].should eq event_json[key]
end
end
end
end
end
14 changes: 5 additions & 9 deletions test/test_red_glass.rb → spec/red_glass_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
require 'spec_helper'
require_relative '../lib/red-glass/red_glass'
require "test/unit"
require "selenium-webdriver"
require "json"

class TestRedGlass < Test::Unit::TestCase
PROJ_ROOT = File.dirname(__FILE__).to_s
describe 'RedGlass' do

def test_events_captured_in_browser_and_sent_to_red_glass_app_server
it 'captures browser events and sends them to the RedGlass app server' do
driver = Selenium::WebDriver.for :firefox
red_glass = RedGlass.new driver

Expand All @@ -17,10 +14,9 @@ def test_events_captured_in_browser_and_sent_to_red_glass_app_server
driver.quit
uri = URI.parse("http://localhost:4567/events")
event = JSON.parse(Net::HTTP.get_response(uri).body.to_s)[0]
['url', 'testID', 'time', 'type', 'target'].each do |property|
assert !event[property].nil?
%w(url testID time type target).each do |property|
event[property].nil?.should be_false
end
red_glass.stop
end

end
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rspec'
require 'selenium-webdriver'
require 'json'
require 'rack/test'

RSpec.configure do |conf|
conf.include Rack::Test::Methods
end
50 changes: 0 additions & 50 deletions test/test_red_glass_app.rb

This file was deleted.

0 comments on commit f372cec

Please # to comment.