Skip to content
This repository has been archived by the owner on Oct 12, 2019. It is now read-only.

Commit

Permalink
Fix some rspec deprecations
Browse files Browse the repository at this point in the history
* Replace stub! with stub in specs
* Replace mock with double
* Update pending to skip
  • Loading branch information
jkelleyj committed Jan 11, 2015
1 parent 82b1558 commit 4f03b3d
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 171 deletions.
6 changes: 3 additions & 3 deletions spec/builder/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
# it 'should render a label with localized text and not apply the label_str_method' do
# with_config :label_str_method, :reverse do
# @localized_label_text = 'Localized title'
# @new_post.stub!(:meta_description)
# @new_post.stub(:meta_description)
# ::I18n.backend.store_translations :en,
# :formtastic => {
# :labels => {
Expand Down Expand Up @@ -132,7 +132,7 @@
#
# describe 'and object is given' do
# it 'should delegate the label logic to class human attribute name and pass it down to the label tag' do
# @new_post.stub!(:meta_description) # a two word method name
# @new_post.stub(:meta_description) # a two word method name
# @new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return('meta_description'.humanize)
#
# concat(semantic_form_for(@new_post) do |builder|
Expand All @@ -145,7 +145,7 @@
# describe 'and object is given with label_str_method set to :capitalize' do
# it 'should capitalize method name, passing it down to the label tag' do
# with_config :label_str_method, :capitalize do
# @new_post.stub!(:meta_description)
# @new_post.stub(:meta_description)
#
# concat(semantic_form_for(@new_post) do |builder|
# concat(builder.input(:meta_description))
Expand Down
10 changes: 5 additions & 5 deletions spec/builder/semantic_fields_for_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
before do
@output_buffer = ''
mock_everything
@new_post.stub!(:author).and_return(::Author.new)
@new_post.stub(:author).and_return(::Author.new)

Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
end
Expand Down Expand Up @@ -78,7 +78,7 @@
end

it 'should sanitize html id for li tag' do
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
@bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
concat(semantic_form_for(@new_post) do |builder|
concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
concat(nested_builder.inputs(:login))
Expand All @@ -91,7 +91,7 @@
end

it 'should use namespace provided in nested fields' do
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
@bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
concat(nested_builder.inputs(:login))
Expand All @@ -107,8 +107,8 @@
output_buffer.replace ''

@fred.posts.size.should == 1
@fred.posts.first.stub!(:persisted?).and_return(true)
@fred.stub!(:posts_attributes=)
@fred.posts.first.stub(:persisted?).and_return(true)
@fred.stub(:posts_attributes=)

concat(semantic_form_for(@fred) do |builder|
concat(builder.semantic_fields_for(:posts) do |nested_builder|
Expand Down
64 changes: 32 additions & 32 deletions spec/helpers/inputs_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
describe 'when a :for option is provided' do

before do
@new_post.stub!(:respond_to?).and_return(true, true)
@new_post.stub!(:author).and_return(@bob)
@new_post.stub(:respond_to?).and_return(true, true)
@new_post.stub(:author).and_return(@bob)
end

it 'should render nested inputs' do
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
@bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))

concat(semantic_form_for(@new_post) do |builder|
inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
Expand All @@ -74,7 +74,7 @@
end

it 'should concat rendered nested inputs to the template' do
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
@bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))

concat(semantic_form_for(@new_post) do |builder|
builder.inputs :for => [:author, @bob] do |bob_builder|
Expand Down Expand Up @@ -103,8 +103,8 @@

describe "as a symbol representing a has_many association name" do
before do
@new_post.stub!(:authors).and_return([@bob, @fred])
@new_post.stub!(:authors_attributes=)
@new_post.stub(:authors).and_return([@bob, @fred])
@new_post.stub(:authors_attributes=)
end

it 'should nest the inputs with a fieldset, legend and :name input for each item' do
Expand Down Expand Up @@ -176,7 +176,7 @@
end

it 'should pass options down to semantic_fields_for' do
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
@bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))

concat(semantic_form_for(@new_post) do |builder|
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
Expand Down Expand Up @@ -342,18 +342,18 @@
describe 'without a block' do

before do
::Post.stub!(:reflections).and_return({:author => mock('reflection', :options => {}, :macro => :belongs_to),
:comments => mock('reflection', :options => {}, :macro => :has_many) })
::Author.stub!(:find).and_return([@fred, @bob])

@new_post.stub!(:title)
@new_post.stub!(:body)
@new_post.stub!(:author_id)

@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 255))
@new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
@new_post.stub!(:column_for_attribute).with(:created_at).and_return(mock('column', :type => :datetime))
@new_post.stub!(:column_for_attribute).with(:author).and_return(nil)
::Post.stub(:reflections).and_return({:author => double('reflection', :options => {}, :macro => :belongs_to),
:comments => double('reflection', :options => {}, :macro => :has_many) })
::Author.stub(:find).and_return([@fred, @bob])

@new_post.stub(:title)
@new_post.stub(:body)
@new_post.stub(:author_id)

@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
@new_post.stub(:column_for_attribute).with(:body).and_return(double('column', :type => :text))
@new_post.stub(:column_for_attribute).with(:created_at).and_return(double('column', :type => :datetime))
@new_post.stub(:column_for_attribute).with(:author).and_return(nil)
end

describe 'with no args (quick forms syntax)' do
Expand Down Expand Up @@ -404,12 +404,12 @@
context "with a polymorphic association" do

before do
@new_post.stub!(:commentable)
@new_post.class.stub!(:reflections).and_return({
:commentable => mock('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
@new_post.stub(:commentable)
@new_post.class.stub(:reflections).and_return({
:commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
})
@new_post.stub!(:column_for_attribute).with(:commentable).and_return(
mock('column', :type => :integer)
@new_post.stub(:column_for_attribute).with(:commentable).and_return(
double('column', :type => :integer)
)
end

Expand Down Expand Up @@ -454,15 +454,15 @@
context "with a polymorphic association" do

it 'should raise an error for polymorphic associations (the collection class cannot be guessed)' do
@new_post.stub!(:commentable)
@new_post.class.stub!(:reflections).and_return({
:commentable => mock('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
@new_post.stub(:commentable)
@new_post.class.stub(:reflections).and_return({
:commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
})
@new_post.stub!(:column_for_attribute).with(:commentable).and_return(
mock('column', :type => :integer)
@new_post.stub(:column_for_attribute).with(:commentable).and_return(
double('column', :type => :integer)
)
@new_post.class.stub!(:reflect_on_association).with(:commentable).and_return(
mock('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
@new_post.class.stub(:reflect_on_association).with(:commentable).and_return(
double('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
)

expect {
Expand All @@ -479,7 +479,7 @@
describe 'when a :for option is provided' do
describe 'and an object is given' do
it 'should render nested inputs' do
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
@bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
concat(semantic_form_for(@new_post) do |builder|
concat(builder.inputs(:login, :for => @bob))
end)
Expand Down
24 changes: 12 additions & 12 deletions spec/helpers/semantic_errors_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
@title_errors = ['must not be blank', 'must be awesome']
@base_errors = ['base error message', 'nasty error']
@base_error = 'one base error'
@errors = mock('errors')
@new_post.stub!(:errors).and_return(@errors)
@errors = double('errors')
@new_post.stub(:errors).and_return(@errors)
end

describe 'when there is only one error on base' do
before do
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
@errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_error)
end

it 'should render an alert with an unordered list' do
Expand All @@ -29,7 +29,7 @@

describe 'when there is more than one error on base' do
before do
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_errors)
@errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_errors)
end

it 'should render an unordered list' do
Expand All @@ -44,8 +44,8 @@

describe 'when there are errors on title' do
before do
@errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
@errors.stub!(:[]).with(errors_matcher(:base)).and_return([])
@errors.stub(:[]).with(errors_matcher(:title)).and_return(@title_errors)
@errors.stub(:[]).with(errors_matcher(:base)).and_return([])
end

it 'should render an unordered list' do
Expand All @@ -58,8 +58,8 @@

describe 'when there are errors on title and base' do
before do
@errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
@errors.stub(:[]).with(errors_matcher(:title)).and_return(@title_errors)
@errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_error)
end

it 'should render an unordered list' do
Expand All @@ -73,8 +73,8 @@

describe 'when there are no errors' do
before do
@errors.stub!(:[]).with(errors_matcher(:title)).and_return(nil)
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(nil)
@errors.stub(:[]).with(errors_matcher(:title)).and_return(nil)
@errors.stub(:[]).with(errors_matcher(:base)).and_return(nil)
end

it 'should return nil' do
Expand All @@ -86,7 +86,7 @@

describe 'when there is one error on base and options with class is passed' do
before do
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
@errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_error)
end

it 'should render an unordered list with given class' do
Expand All @@ -98,7 +98,7 @@

describe 'when :base is passed in as an argument' do
before do
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
@errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_error)
end

it 'should ignore :base and only render base errors once' do
Expand Down
8 changes: 4 additions & 4 deletions spec/inputs/boolean_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
end

it 'should generate a checked input if object.method returns checked value' do
@new_post.stub!(:allow_comments).and_return('yes')
@new_post.stub(:allow_comments).and_return('yes')

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
Expand All @@ -111,7 +111,7 @@
end

it 'should not generate a checked input if object.method returns unchecked value' do
@new_post.stub!(:allow_comments).and_return('no')
@new_post.stub(:allow_comments).and_return('no')

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
Expand All @@ -121,7 +121,7 @@
end

it 'should generate a checked input if object.method returns checked value' do
@new_post.stub!(:allow_comments).and_return('yes')
@new_post.stub(:allow_comments).and_return('yes')

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
Expand All @@ -131,7 +131,7 @@
end

it 'should not generate a checked input if object.method returns unchecked value' do
@new_post.stub!(:allow_comments).and_return('no')
@new_post.stub(:allow_comments).and_return('no')

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
Expand Down
18 changes: 9 additions & 9 deletions spec/inputs/check_boxes_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@

describe "no disabled items" do
before do
@new_post.stub!(:author_ids).and_return(nil)
@new_post.stub(:author_ids).and_return(nil)

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
Expand All @@ -214,7 +214,7 @@

describe "single disabled item" do
before do
@new_post.stub!(:author_ids).and_return(nil)
@new_post.stub(:author_ids).and_return(nil)

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
Expand All @@ -230,7 +230,7 @@

describe "multiple disabled items" do
before do
@new_post.stub!(:author_ids).and_return(nil)
@new_post.stub(:author_ids).and_return(nil)

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
Expand All @@ -253,7 +253,7 @@
before do
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
with_config :i18n_lookups_by_default, true do
@new_post.stub!(:author_ids).and_return(nil)
@new_post.stub(:author_ids).and_return(nil)
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes))
end)
Expand All @@ -272,7 +272,7 @@

describe "when :label option is set" do
before do
@new_post.stub!(:author_ids).and_return(nil)
@new_post.stub(:author_ids).and_return(nil)
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :label => 'The authors'))
end)
Expand All @@ -286,7 +286,7 @@
describe "when :label option is false" do
before do
@output_buffer = ''
@new_post.stub!(:author_ids).and_return(nil)
@new_post.stub(:author_ids).and_return(nil)
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :label => false))
end)
Expand All @@ -304,7 +304,7 @@

describe "when :required option is true" do
before do
@new_post.stub!(:author_ids).and_return(nil)
@new_post.stub(:author_ids).and_return(nil)
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:authors, :as => :check_boxes, :required => true))
end)
Expand Down Expand Up @@ -350,9 +350,9 @@
end

it 'to set the right input value' do
item = mock('item')
item = double('item')
item.should_not_receive(:id)
item.stub!(:custom_value).and_return('custom_value')
item.stub(:custom_value).and_return('custom_value')
item.should_receive(:custom_value).exactly(3).times
@new_post.author.should_receive(:custom_value).exactly(1).times
concat(semantic_form_for(@new_post) do |builder|
Expand Down
4 changes: 2 additions & 2 deletions spec/inputs/color_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def input_field_for_method_should_have_maxlength(method, maxlength)
let(:default_maxlength) { 50 }

before do
@new_post.stub!(:class).and_return(::PostModel)
@new_post.stub(:class).and_return(::PostModel)
end

after do
@new_post.stub!(:class).and_return(::Post)
@new_post.stub(:class).and_return(::Post)
end

describe 'and validates_length_of was called for the method' do
Expand Down
Loading

0 comments on commit 4f03b3d

Please sign in to comment.