Jan Limpens
2010-Oct-04 03:32 UTC
[rspec-users] undefined method `mock'' for #<RSpec::Core::ExampleGroup::Nested...
Hekko,
what does the following mean?
1) PortfolioItemsController should render index
Failure/Error: @portfolio = mock_model(Portfolio)
undefined method `mock'' for
#<RSpec::Core::ExampleGroup::Nested_1:0x0000010214bba0>
# /Users/jan/.rvm/gems/ruby-1.9.2-p0 at
rails3/gems/actionpack-3.0.0/lib/action_dispatch/testing/assertions/routing.rb:177:in
`method_missing''
# /Users/jan/.rvm/gems/ruby-1.9.2-p0 at
rails3/gems/rspec-rails-2.0.0.beta.22/lib/rspec/rails/mocks.rb:71:in
`mock_model''
# ./spec/controllers/portfolio_items_controller_spec.rb:7:in `block (2
levels) in <top (required)>''
This is using mongoid, with rails 3
require ''spec_helper''
describe PortfolioItemsController do
render_views
before(:all) do
@portfolio = mock_model(Portfolio) #dies here
@item = mock_model(PortfolioItem)
@items = [@item, mock_model(PortfolioItem)]
PortfolioItem.stub!(:find).and_return(@item)
PortfolioItem.stub!(:all).and_return(@items)
@portfolio.stub!(:items).and_return(@items)
end
it "should render index" do
response.should be_success
end
end
#routes.rb
resources :portfolios do
resources :portfolio_items do
resources :images
end
end
class Portfolio
include Mongoid::Document
validates_presence_of :title
field :title, :type => String
embed_many :items, :class_name => PortfolioItem.name
end
class PortfolioItem
include Mongoid::Document
embedded_in :portfolio, :inverse_of => :items
field(:title)
field(:description)
field(:date)
embed_many(:images)
validates_presence_of :title, :date
end
Any idea, what I am doing wrong here?
On another note, I think be_success does not exist anymore, right?
--
Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20101004/9cf7d0c7/attachment.html>
Dan F.
2011-Jan-19 20:54 UTC
[rspec-users] undefined method `mock'' for #<RSpec::Core::ExampleGroup::Nested.
Please see: https://github.com/rspec/rspec-rails/issues/closed#issue/279 You can''t create mocks in before(:all), but it will work in before(:each) -- Posted via http://www.ruby-forum.com/.
Wilker
2011-Jan-19 21:12 UTC
[rspec-users] undefined method `mock'' for #<RSpec::Core::ExampleGroup::Nested.
Yeah, that is right, because mocks live on a space that is different for each spec (the MockSpace), this is why you can''t create it in before :all ;) --- Wilker L?cio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Wed, Jan 19, 2011 at 5:54 PM, Dan F. <lists at ruby-forum.com> wrote:> Please see: > https://github.com/rspec/rspec-rails/issues/closed#issue/279 > > You can''t create mocks in before(:all), but it will work in > before(:each) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110119/eed3f05b/attachment.html>