spec/unit/unit_spec_helper.rb in screw-unit-server-0.3.0 vs spec/unit/unit_spec_helper.rb in screw-unit-server-0.5.3
- old
+ new
@@ -1,120 +1,51 @@
require "rubygems"
require "spec"
-dir = File.dirname(__FILE__)
+require "spec/autorun"
+require "rack/test"
+ARGV.push("-b")
-$LOAD_PATH.unshift "#{dir}/../../lib"
+dir = File.dirname(__FILE__)
+LIBRARY_ROOT_DIR = File.expand_path("#{dir}/../..")
+$LOAD_PATH.unshift File.expand_path("#{LIBRARY_ROOT_DIR}/lib")
require "screw_unit"
-require "hpricot"
+require "nokogiri"
require "guid"
+require "#{LIBRARY_ROOT_DIR}/vendor/js-test-core/spec/spec_helpers/be_http"
+require "#{LIBRARY_ROOT_DIR}/vendor/js-test-core/spec/spec_helpers/show_test_exceptions"
Spec::Runner.configure do |config|
config.mock_with :rr
end
-module Spec
- module Matchers
- class Exist
- def matches?(actual)
- @actual = actual
- !@actual.nil?
- end
- end
- end
-end
+Sinatra::Application.use ShowTestExceptions
+Sinatra::Application.set :raise_errors, true
+Sinatra::Application.set :show_exceptions, false
+JsTestCore::App.set :raise_errors, true
+JsTestCore::App.set :show_exceptions, false
-class Spec::Example::ExampleGroup
- class << self
- def thin_logging
- @thin_logging = true if @thin_logging.nil?
- @thin_logging
- end
+Sinatra::Application.use(ScrewUnit::App)
- attr_writer :thin_logging
- end
-end
-
-module Spec::Example::ExampleMethods
- attr_reader :spec_root_path, :implementation_root_path, :public_path, :server, :connection
+class Spec::ExampleGroup
+ include Rack::Test::Methods
+ include BeHttp
+
+ attr_reader :spec_root_path, :public_path, :server, :connection
before(:all) do
dir = File.dirname(__FILE__)
@spec_root_path = File.expand_path("#{dir}/../example_specs")
- @implementation_root_path = File.expand_path("#{dir}/../example_public/javascripts")
@public_path = File.expand_path("#{dir}/../example_public")
end
before(:each) do
- JsTestCore::Server.instance = JsTestCore::Server.new(spec_root_path, implementation_root_path, public_path)
- stub(EventMachine).run do
- raise "You need to mock calls to EventMachine.run or the process will hang"
- end
- stub(EventMachine).start_server do
- raise "You need to mock calls to EventMachine.start_server or the process will hang"
- end
- stub(EventMachine).send_data do
- raise "Calls to EventMachine.send_data must be mocked or stubbed"
- end
- @connection = Thin::JsTestCoreConnection.new(Guid.new)
- stub(EventMachine).send_data {raise "EventMachine.send_data must be handled"}
- stub(EventMachine).close_connection {raise "EventMachine.close_connection must be handled"}
- @server = JsTestCore::Server.instance
- Thin::Logging.silent = !self.class.thin_logging
- Thin::Logging.debug = self.class.thin_logging
+ JsTestCore::Configuration.instance.spec_root_path = spec_root_path
+ JsTestCore::Configuration.instance.public_path = public_path
end
- after(:each) do
- Thin::Logging.silent = true
- Thin::Logging.debug = false
+ def app
+ Sinatra::Application
end
- def get(url, params={})
- request(:get, url, params)
- end
-
- def post(url, params={})
- request(:post, url, params)
- end
-
- def put(url, params={})
- request(:put, url, params)
- end
-
- def delete(url, params={})
- request(:delete, url, params)
- end
-
- def env_for(method, url, params)
- Rack::MockRequest.env_for(url, params.merge({:method => method.to_s.upcase, 'js_test_core.connection' => connection}))
- end
-
- def create_request(method, url, params={})
- env = env_for(method, url, params)
- server.call(env)[2]
- end
- alias_method :request, :create_request
-
def core_path
JsTestCore::Server.core_path
- end
-
- def spec_file(relative_path)
- absolute_path = spec_root_path + relative_path
- JsTestCore::Resources::File.new(absolute_path, "/specs#{relative_path}")
- end
-
- def spec_dir(relative_path="")
- absolute_path = spec_root_path + relative_path
- JsTestCore::Resources::SpecDir.new(absolute_path, "/specs#{relative_path}")
- end
-
- def contain_spec_file_with_correct_paths(path_relative_to_spec_root)
- expected_absolute_path = spec_root_path + path_relative_to_spec_root
- expected_relative_path = "/specs" + path_relative_to_spec_root
-
- ::Spec::Matchers::SimpleMatcher.new(expected_relative_path) do |globbed_files|
- file = globbed_files.find do |file|
- file.absolute_path == expected_absolute_path
- end
- file && file.relative_path == expected_relative_path
- end
end
end