Permalink
Browse files

Sort out some testing environment stuff. Should work on RCR once the …

…gem gets installed
  • Loading branch information...
darkhelmet committed Jan 3, 2010
1 parent ed6d67b commit ffd8eb57e65f2efa18de211dcec6415580b0cf30
Showing with 48 additions and 11 deletions.
  1. +32 −7 Rakefile
  2. +12 −0 lib/blog_helper.rb
  3. +2 −4 spec/application/index_spec.rb
  4. +2 −0 spec/spec_helper.rb
View
@@ -1,17 +1,25 @@
-require 'darkblog'
require 'yard'
require 'spec/rake/spectask'
+def runcoderun?
+ ENV['RUN_CODE_RUN']
+end
+
+desc 'Setup environment'
+task :env do
+ require 'darkblog'
+end
+
namespace :db do
desc 'Run database migrations'
- task :migrate do
+ task :migrate => [:env] do
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate('db/migrate')
end
desc 'Reset the database'
- task :reset do
+ task :reset => [:env] do
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.down('db/migrate')
@@ -20,7 +28,7 @@ namespace :db do
namespace :schema do
desc 'Dump the schema'
- task :dump do
+ task :dump => [:env] do
File.open('db/schema.rb', 'w') do |f|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, f)
end
@@ -30,7 +38,7 @@ end
namespace :cache do
desc 'Purge cache items'
- task :purge do
+ task :purge => [:env] do
Cache.purge(nil)
end
end
@@ -42,7 +50,7 @@ namespace :texticle do
end
desc 'Destroy full text search indexes'
- task :destroy_indexes do
+ task :destroy_indexes => [:env] do
Post.full_text_indexes.each { |fti| fti.destroy }
end
end
@@ -63,4 +71,21 @@ Spec::Rake::SpecTask.new('spec') do |t|
t.spec_opts = ['--colour', '--format', 'nested', '--debugger', '--backtrace']
end
-task :default => [:spec]
+desc 'Setup task for runcoderun'
+task :runcoderun do
+ db = 'darkhelmet_darkblog_test'
+ user = 'build'
+ %w(drop create).each { |action| %x(#{action}db -U #{user} #{db}) }
+end
+
+desc 'Local test setup'
+task :local do
+ ENV['RACK_ENV'] = 'test'
+end
+
+if runcoderun?
+ ENV['RACK_ENV'] = 'test'
+ task :default => %w(env runcoderun db:migrate spec)
+else
+ task :default => %w(local db:migrate spec)
+end
View
@@ -331,6 +331,18 @@ def no_cache
headers['Cache-Control'] = 'no-cache'
end
end
+
+ module Test
+ def good_get(*args)
+ get(*args)
+ last_response.should be_ok
+ end
+
+ def bad_get(*args)
+ get(*args)
+ last_response.should_not be_ok
+ end
+ end
end
STATIC_PATHS = %w(image javascripts stylesheets favicon.ico sitemap.xsl swf).map { |p| "^/#{p}" }
@@ -12,14 +12,12 @@ def app
it 'should 404 when there are no posts' do
Post.destroy_all
- get('/')
- last_response.should_not be_ok
+ bad_get('/')
last_response.status.should == 404
end
it 'should include Delicious bookmarks' do
- get('/')
- last_response.should be_ok
+ good_get('/')
end
end
end
View
@@ -8,6 +8,7 @@
# Include the Rack::Test helpers
Spec::Runner.configure do |conf|
conf.include Rack::Test::Methods
+ conf.include BlogHelper::Test
end
set(:environment, :test)
@@ -19,4 +20,5 @@
FakeWeb.register_uri(:get, 'http://github.com/api/v1/json/darkhelmet', :body => File.read('spec/github.json'), :content_type => 'application/json; charset=utf-8')
FakeWeb.register_uri(:get, 'http://search.twitter.com/search.json?q=from%3Adarkhelmetlive', :body => File.read('spec/twitter.json'), :content_type => 'application/json; charset=utf-8')
FakeWeb.register_uri(:get, 'https://darkhelmetlive:secret@api.del.icio.us/v1/posts/recent?count=8', :body => File.read('spec/delicious.xml'), :content_type => 'text/xml; charset=utf-8')
+
FakeWeb.allow_net_connect = false

0 comments on commit ffd8eb5

Please sign in to comment.