I installed Rspec and am getting the following failure: $ sudo gem install rspec Successfully installed rspec-1.0.8 Installing ri documentation for rspec-1.0.8... Installing RDoc documentation for rspec-1.0.8... $ spec -v RSpec-1.0.8 (r2338) - BDD for Ruby http://rspec.rubyforge.org/ $ cat acct.rb describe Account, " when first created" do it "should have a balance of $0" do ... end end $ spec acct.rb /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/runner/ behaviour_runner.rb:106:in `load'': ./acct.rb:3: syntax error, unexpected tDOT3 (SyntaxError) from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ runner/behaviour_runner.rb:106:in `load_specs'' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ runner/behaviour_runner.rb:105:in `each'' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ runner/behaviour_runner.rb:105:in `load_specs'' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ runner/behaviour_runner.rb:49:in `prepare!'' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ runner/behaviour_runner.rb:19:in `run'' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ runner/command_line.rb:17:in `run'' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/bin/spec:3 from /opt/local/bin/spec:16:in `load'' from /opt/local/bin/spec:16 Must be a version or other config problem. Can anyone point me in the right direction? Thanks, Pito
On Nov 28, 2007 11:58 AM, Pito Salas <rps at salas.com> wrote:> I installed Rspec and am getting the following failure: > > $ sudo gem install rspec > Successfully installed rspec-1.0.8 > Installing ri documentation for rspec-1.0.8... > Installing RDoc documentation for rspec-1.0.8... > > $ spec -v > RSpec-1.0.8 (r2338) - BDD for Ruby > http://rspec.rubyforge.org/ > > $ cat acct.rb > describe Account, " when first created" do > it "should have a balance of $0" do > ... > end > end > $ spec acct.rb > /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/runner/ > behaviour_runner.rb:106:in `load'': ./acct.rb:3: syntax error, > unexpected tDOT3 (SyntaxError) > from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ > runner/behaviour_runner.rb:106:in `load_specs'' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ > runner/behaviour_runner.rb:105:in `each'' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ > runner/behaviour_runner.rb:105:in `load_specs'' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ > runner/behaviour_runner.rb:49:in `prepare!'' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ > runner/behaviour_runner.rb:19:in `run'' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/ > runner/command_line.rb:17:in `run'' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/bin/spec:3 > from /opt/local/bin/spec:16:in `load'' > from /opt/local/bin/spec:16 > > Must be a version or other config problem. Can anyone point me in the > right direction? > > Thanks, > > Pito > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >it''s saying you have a syntax error.. Can you post your whole file? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071128/a2210782/attachment.html
That *was* the whole file. And I think therein lies the problem. I didn''t realize that I needed a class def for Acct. So this, now, works: class Account end describe Account, " when first created" do it "should have a balance of $0" do end end (as I said: newbie :) Thanks! Pito
On 11/27/07, Pito Salas <rps at salas.com> wrote:> That *was* the whole file. And I think therein lies the problem.Wait, so your file had "..." in it? Yes, that would indeed be a syntax error. Pat
Good day all :-) I am getting into RSpec and am a little confused by an aspect of mocks / mock_models in controller tests. I''ve gone through the online docs and the PeepCode movies and have them slightly contradictory on this matter. I hope you can clarify. Many thanks in advance :-) I''m writing a system that uses the restful authentication plugin and am writing a test for the following controller create method: class AccountsController < ApplicationController def create @account = Account.new(params[:account]) if @account.save! self.current_account = @account redirect_back_or_default(''/'') flash[:notice] = "Thanks for signing up!" end rescue ActiveRecord::RecordInvalid render :action => ''new'' end ... end I''ve created the following spec test to simply ensure that the Account model receives a call to :new, but the spec is failing as it also receives a call to :save! and it isn''t expecting it. I am using "@account mock_model(Account)". If i replace this with "@account = mock(''account'', :null_object => true)" the test passes, but i''m not sure that''s really what i want. I''m pretty sure i need to us mock_model in this instance. The code is below. Also, are my use of comment blocks within the spec against the RSpec *way*. I appreciate that this isn''t using fixtures and i might use them later. I also appreciate that i can write modules to contain these methods, but i can''t quite see the point in muddying things. Comments most welcome. Thanks describe AccountsController, "allows users to create only valid accounts" do ####### ### Reusable methods ####### def do_post(params = nil) post :create, :account => params end def valid_account_form_details { :password => "password", :password_confirmation => "password", :login => "new_login", :email => "test at test.com" } end ####### ### Before block ####### before do @account = mock_model(Account) Account.stub!(:new).and_return(@account) end ####### ### It Statements ####### it "should display the new account template when the user visits /accounts/new" do get ''new'' response.should render_template(:new) end it "should tell the Account model to create a new account on form POST" do Account.should_receive(:new).with(:anything).and_return(@account) do_post end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/151ae095/attachment.html
On 4 Dec 2007, at 15:41, Andy Goundry wrote:> I''ve created the following spec test to simply ensure that the > Account model receives a call to :new, but the spec is failing as it > also receives a call to :save! and it isn''t expecting it. I am using > "@account = mock_model(Account)". If i replace this with "@account = > mock(''account'', :null_object => true)" the test passes, but i''m not > sure that''s really what i want. I''m pretty sure i need to us > mock_model in this instance.mock_model doesn''t do anything magic -- it just creates a mock (with a conveniently-chosen name) and stubs out a few useful methods for you. In your case you need to stub out #save! too, so that you don''t get the failure: @account = mock_model(Account, :save! => true). Cheers, -Tom
cheers Tom. That worked. I''ll go dig in the rspec source... On 04/12/2007, Tom Stuart <tom at experthuman.com> wrote:> > On 4 Dec 2007, at 15:41, Andy Goundry wrote: > > I''ve created the following spec test to simply ensure that the > > Account model receives a call to :new, but the spec is failing as it > > also receives a call to :save! and it isn''t expecting it. I am using > > "@account = mock_model(Account)". If i replace this with "@account > > mock(''account'', :null_object => true)" the test passes, but i''m not > > sure that''s really what i want. I''m pretty sure i need to us > > mock_model in this instance. > > mock_model doesn''t do anything magic -- it just creates a mock (with a > conveniently-chosen name) and stubs out a few useful methods for you. > In your case you need to stub out #save! too, so that you don''t get > the failure: @account = mock_model(Account, :save! => true). > > Cheers, > -Tom > _______________________________________________ > 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/20071204/2e0862a9/attachment.html