Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sinatra support added

  • Loading branch information...
commit 802adf5f4342c0e28ed84b78c8a4e8d70e92c5f0 1 parent 450810b
Robert Pankowecki (Gavdi) authored
View
2  .gitignore
@@ -9,4 +9,6 @@ test/dummy/log/*.log
test/dummy/tmp/
test/dummy/test/acceptance/*
test/dummy/spec/acceptance/*
+test/dope/test/acceptance/*
+test/dope/spec/acceptance/*
nbproject/
View
2  Rakefile
@@ -22,7 +22,7 @@ require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
+ t.pattern = 'test/unit/*_test.rb' # Don't load test/dummy/test && test/dope/test etc. because we run them from our tests with proper commands setup.
t.verbose = false
end
View
2  bbq.gemspec
@@ -28,4 +28,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "devise", "~> 1.4.0"
s.add_development_dependency "rspec-rails", "~> 2.6.0"
+ s.add_development_dependency "sinatra", "~> 1.2.6"
+
end
View
8 lib/bbq.rb
@@ -1,7 +1,13 @@
-require 'bbq/railtie' if defined?(Rails)
+require 'pathname'
module Bbq
def self.root
@root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..')))
end
+
+ def self.rails?
+ defined?(::Rails)
+ end
end
+
+require 'bbq/railtie' if Bbq.rails?
View
1  lib/bbq/test.rb
@@ -1,3 +1,4 @@
+require 'bbq'
require 'active_support'
require 'test/unit'
require 'bbq/test_user'
View
10 lib/bbq/test_user.rb
@@ -1,4 +1,4 @@
-require 'capybara/rails'
+require 'capybara/rails' if Bbq.rails?
require 'capybara/dsl'
require 'securerandom'
require 'bbq/util'
@@ -7,9 +7,11 @@
module Bbq
class TestUser
- include ActionDispatch::Routing::UrlFor
- include Rails.application.routes.url_helpers
- include ActionDispatch::Routing::RouteSet::MountedHelpers unless Rails.version < "3.1"
+ if Bbq.rails?
+ include ActionDispatch::Routing::UrlFor
+ include Rails.application.routes.url_helpers
+ include ActionDispatch::Routing::RouteSet::MountedHelpers unless Rails.version < "3.1"
+ end
include Capybara::DSL
include Bbq::TestUser::Eyes
include Bbq::TestUser::Within
View
19 test/dope/app.rb
@@ -0,0 +1,19 @@
+require 'rubygems'
+gemfile = File.expand_path('../../../Gemfile', __FILE__)
+
+raise 'could not find gemfile' unless File.exist?(gemfile)
+ENV['BUNDLE_GEMFILE'] = gemfile
+require 'bundler'
+Bundler.setup
+
+$:.unshift File.expand_path('../../../../lib', __FILE__)
+
+require 'sinatra'
+
+module Dope
+ class App < ::Sinatra::Base
+ get "/" do
+ "BBQ supports sinatra"
+ end
+ end
+end
View
30 test/unit/bbq_test_unit_test.rb
@@ -3,6 +3,36 @@
class BbqTestUnitTest < Test::Unit::TestCase
include CommandHelper
+ def test_sinatra
+ create_file 'test/dope/test/acceptance/root_path_test.rb', <<-TESTCASE
+ require 'app'
+ require 'bbq/test'
+
+ class DopeAppRootTest < Bbq::TestCase
+ FAILED_ASSERTION = RUBY_VERSION < "1.9" ? Test::Unit::AssertionFailedError : MiniTest::Assertion
+
+ background do
+ Capybara.app = ::Dope::App
+ end
+
+ scenario "user see '/' page" do
+ user = Bbq::TestUser.new
+ user.visit "/"
+ user.see!("BBQ supports sinatra")
+ assert user.see?("BBQ supports sinatra")
+
+ assert_raises(FAILED_ASSERTION) { user.see!("blah") }
+ assert_raises(FAILED_ASSERTION) { user.not_see!("BBQ supports sinatra") }
+
+ assert_equal 3, user.instance_variable_get(:@_assertions)
+ end
+ end
+ TESTCASE
+
+ run_cmd 'ruby -Itest/dope -Itest/dope/test test/dope/test/acceptance/root_path_test.rb'
+ assert_match /1 tests, 4 assertions, 0 failures, 0 errors/, output
+ end
+
def test_dsl
create_file 'test/dummy/test/acceptance/dsl_test.rb', <<-TESTCASE
require 'test_helper'
Please sign in to comment.
Something went wrong with that request. Please try again.