Skip to content

Commit

Permalink
Don't use spork server for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgdavey committed Oct 24, 2010
1 parent cc362ba commit bb3c42a
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 129 deletions.
1 change: 0 additions & 1 deletion .rspec
@@ -1,2 +1 @@
--color --color
--drb
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -2,7 +2,6 @@ source :rubygems


group :test do group :test do
gem 'nokogiri', '~> 1.4.3' gem 'nokogiri', '~> 1.4.3'
gem 'spork'
gem 'rspec', '~> 2.0.1' gem 'rspec', '~> 2.0.1'
gem 'diff-lcs' gem 'diff-lcs'
gem 'rspec_tag_matchers' gem 'rspec_tag_matchers'
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -77,7 +77,6 @@ GEM
rspec_tag_matchers (1.0.0) rspec_tag_matchers (1.0.0)
nokogiri (>= 1.4.0) nokogiri (>= 1.4.0)
rspec-rails (>= 1.2.6) rspec-rails (>= 1.2.6)
spork (0.8.4)
thor (0.14.3) thor (0.14.3)
treetop (1.4.8) treetop (1.4.8)
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
Expand All @@ -93,4 +92,3 @@ DEPENDENCIES
rails (~> 3.0.1) rails (~> 3.0.1)
rspec (~> 2.0.1) rspec (~> 2.0.1)
rspec_tag_matchers rspec_tag_matchers
spork
242 changes: 117 additions & 125 deletions spec/spec_helper.rb
@@ -1,141 +1,133 @@
require 'rubygems' ## Use bundler to exec the specs
require 'spork' $LOAD_PATH.unshift(File.dirname(__FILE__))

require 'bundler'
Spork.prefork do Bundler.setup
## Use bundler to exec the specs require 'rspec'
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'bundler' require 'rspec_tag_matchers'
Bundler.setup require 'active_record'
require 'rspec' require 'action_controller'


require 'rspec_tag_matchers' require 'action_view/base'
require 'active_record' require 'action_view/template'
require 'action_controller' require 'action_view/helpers'


require 'action_view/base' RSpec.configure do |config|
require 'action_view/template' config.include(RspecTagMatchers)
require 'action_view/helpers' end

RSpec.configure do |config|
config.include(RspecTagMatchers)
end

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

module TabletasticSpecHelper
include ActiveSupport
include ActionView
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::ActiveModelHelper
include ActionView::Helpers::RecordTagHelper
include ActionView::Helpers::CaptureHelper
include ActionView::Helpers::RawOutputHelper
include ActionDispatch::Routing::PolymorphicRoutes

def self.included(base)
base.class_eval do
attr_accessor :output_buffer
end
end


def reset_output_buffer! $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@output_buffer = ActionView::OutputBuffer.new
module TabletasticSpecHelper
include ActiveSupport
include ActionView
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::ActiveModelHelper
include ActionView::Helpers::RecordTagHelper
include ActionView::Helpers::CaptureHelper
include ActionView::Helpers::RawOutputHelper
include ActionDispatch::Routing::PolymorphicRoutes

def self.included(base)
base.class_eval do
attr_accessor :output_buffer
end end
end


module ::RspecTagMatchers def reset_output_buffer!
class HaveTag @output_buffer = ActionView::OutputBuffer.new
def description end
description = "have tag <#@selector>"
description << " with inner text '#@inner_text'" if @inner_text
description
end
end
def have_table_with_tag(selector, inner_text_or_options = nil, options = {}, &block)
HaveTag.new("table", nil, {}) &&
HaveTag.new(selector, inner_text_or_options, options, &block)
end
end


class ::Post module ::RspecTagMatchers
def id class HaveTag
def description
description = "have tag <#@selector>"
description << " with inner text '#@inner_text'" if @inner_text
description
end end
end end
class ::Author def have_table_with_tag(selector, inner_text_or_options = nil, options = {}, &block)
HaveTag.new("table", nil, {}) &&
HaveTag.new(selector, inner_text_or_options, options, &block)
end end
class ::Profile end

class ::Post
def id
end end
end
class ::Author
end
class ::Profile
end


def mock_everything def mock_everything
def post_path(post); "/posts/#{post.id}"; end def post_path(post); "/posts/#{post.id}"; end
def admin_post_path(post); "/admin/posts/#{post.id}"; end def admin_post_path(post); "/admin/posts/#{post.id}"; end
def edit_post_path(post); "/posts/#{post.id}/edit"; end def edit_post_path(post); "/posts/#{post.id}/edit"; end
def edit_admin_post_path(post); "/admin/posts/#{post.id}/edit"; end def edit_admin_post_path(post); "/admin/posts/#{post.id}/edit"; end


# Sometimes we need a mock @post object and some Authors for belongs_to # Sometimes we need a mock @post object and some Authors for belongs_to
@post = mock('post') @post = mock('post')
@post.stub!(:class).and_return(::Post) @post.stub!(:class).and_return(::Post)
@post.stub!(:id).and_return(nil) @post.stub!(:id).and_return(nil)
@post.stub!(:author) @post.stub!(:author)
@post.stub!(:to_key).and_return([2]) @post.stub!(:to_key).and_return([2])
::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize } ::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
::Post.stub!(:model_name).and_return(ActiveModel::Name.new(::Post)) ::Post.stub!(:model_name).and_return(ActiveModel::Name.new(::Post))


@fred = mock('author', :to_key => nil) @fred = mock('author', :to_key => nil)
@fred.stub!(:class).and_return(::Author) @fred.stub!(:class).and_return(::Author)
@fred.stub!(:name).and_return('Fred Smith') @fred.stub!(:name).and_return('Fred Smith')
@fred.stub!(:id).and_return(37) @fred.stub!(:id).and_return(37)


@profile = mock('profile') @profile = mock('profile')
@profile.stub!(:author).and_return(@fred) @profile.stub!(:author).and_return(@fred)
@profile.stub!(:bio).and_return("This is my bio") @profile.stub!(:bio).and_return("This is my bio")
@fred.stub!(:profile).and_return(@profile) @fred.stub!(:profile).and_return(@profile)


::Author.stub!(:content_columns).and_return([mock('column', :name => "name")]) ::Author.stub!(:content_columns).and_return([mock('column', :name => "name")])


::Author.stub!(:find).and_return([@fred]) ::Author.stub!(:find).and_return([@fred])
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize } ::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
::Author.stub!(:human_name).and_return('Author') ::Author.stub!(:human_name).and_return('Author')
::Author.stub!(:model_name).and_return(ActiveModel::Name.new(::Author)) ::Author.stub!(:model_name).and_return(ActiveModel::Name.new(::Author))


@freds_post = mock('post') @freds_post = mock('post')
@freds_post.stub!(:class).and_return(::Post) @freds_post.stub!(:class).and_return(::Post)
@freds_post.stub!(:title).and_return('Fred\'s Post') @freds_post.stub!(:title).and_return('Fred\'s Post')
@freds_post.stub!(:body) @freds_post.stub!(:body)
@freds_post.stub!(:id).and_return(19) @freds_post.stub!(:id).and_return(19)
@freds_post.stub!(:to_key).and_return([19]) @freds_post.stub!(:to_key).and_return([19])
@freds_post.stub!(:author).and_return(@fred) @freds_post.stub!(:author).and_return(@fred)
@freds_post.stub!(:author_id).and_return(@fred.id) @freds_post.stub!(:author_id).and_return(@fred.id)
@fred.stub!(:posts).and_return([@freds_post]) @fred.stub!(:posts).and_return([@freds_post])
@fred.stub!(:post_ids).and_return([@freds_post.id]) @fred.stub!(:post_ids).and_return([@freds_post.id])


@mock_reflection_belongs_to_author = mock('reflection1', :options => {}, :name => :author, :macro => :belongs_to, :collection => false) @mock_reflection_belongs_to_author = mock('reflection1', :options => {}, :name => :author, :macro => :belongs_to, :collection => false)


@mock_reflection_has_one_profile = mock('reflection2', :options => {}, :name => :profile, :macro => :has_one, :collection => false) @mock_reflection_has_one_profile = mock('reflection2', :options => {}, :name => :profile, :macro => :has_one, :collection => false)


::Post.stub!(:reflect_on_association).and_return do |column_name| ::Post.stub!(:reflect_on_association).and_return do |column_name|
@mock_reflection_belongs_to_author if column_name == :author @mock_reflection_belongs_to_author if column_name == :author
end end


::Author.stub!(:reflect_on_association).and_return do |column_name| ::Author.stub!(:reflect_on_association).and_return do |column_name|
mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts
@mock_reflection_has_one_profile if column_name == :profile @mock_reflection_has_one_profile if column_name == :profile
end end




::Post.stub!(:reflect_on_all_associations).and_return([]) ::Post.stub!(:reflect_on_all_associations).and_return([])
::Author.stub!(:reflect_on_all_associations).and_return([]) ::Author.stub!(:reflect_on_all_associations).and_return([])
end
end end

end end


Spork.each_run do
# This code will be run each time you run your specs.
require 'tabletastic'


include TabletasticSpecHelper require 'tabletastic'
include Tabletastic
include Tabletastic::Helper include TabletasticSpecHelper
end include Tabletastic
include Tabletastic::Helper

0 comments on commit bb3c42a

Please sign in to comment.