Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,2 +1 @@ | |||
--color | --color | ||
--drb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |