[rspec-users] how should i use response.should be sucess method pass

2008-10-20 Thread Mano ah

I want to test the basic controller test action and to make
response.should be_sucess method work for it. How can i do
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Mocks: expectations vs spying

2008-10-20 Thread Matt Wynne


On 19 Oct 2008, at 21:18, Ashley Moran wrote:



On Oct 19, 2008, at 9:32 am, Matt Wynne wrote:


[1] http://notahat.com/not_a_mock


Looks sweet - it will be in my first mock on Monday!


Thinking about it - how do you use multiple mocking frameworks in a  
given project?


Is it safe to re-open a Spec::Runner.configure do |config| block at  
the top of an individual spec after I've loaded spec_helper (which  
will have to be configured to use the default rspec mocking that 90%  
of the project uses)?


cheers,
Matt
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] how should i use response.should be sucess method pass

2008-10-20 Thread Matt Wynne

Have you looked at this:
http://rspec.info/documentation/rails/writing/controllers.html

Have you tried using the generators for rspec controllers?

On 20 Oct 2008, at 07:12, Mano ah wrote:



I want to test the basic controller test action and to make
response.should be_sucess method work for it. How can i do
--
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] RSpec vs Screw.Unit

2008-10-20 Thread Scott Taylor


On Oct 19, 2008, at 12:14 PM, Pat Maddox wrote:




BTW, Pat - Have you still been working on integrating test spy into
rspec?


Nope, I found not_a_mock [1] and it works well.


Also, relevant to the Screw.Unit and the spying threads, I've hacked  
together a Javascript mocking/stubbing framework which uses the test- 
spy pattern, if anyone is interested:


http://github.com/smtlaissezfaire/espionage/tree/master

Scott

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] RSpec-Rails bug with to_xml?

2008-10-20 Thread Bira
Hello, everyone. I've been lurking here for a while, but this is my first post.

I think I've run into a RSpec bug in a Rails project I'm working on. I
was working on a few REST controllers, and started getting failures on
a specific spec that verified whether a certain action returned XML
output. I spent quite a lot of time checking my code to see if it was
something I did wrong, but it works when I test it manually.

So I created an empty Rails app, and wrote the bare minimum of code
necessary to reproduce this problem. I'm using Rails 2.1.1, with
rspec-1.1.8 and rspec-rails-1.1.8, all installed as gems.

I started by creating a dead-simple model with two string attributes
and no validations, along with this fixture:

# spec/fixtures/users.yml
one:
  name: Name
  email: email

Then I created a simple controller, and its corresponding spec.

class UsersController  ApplicationController

  def index
respond_to do |format|
  format.xml { render :xml = User.find(:all).to_xml}
end
  end

end

# spec

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe UsersController do

  fixtures :users

  it should return a XML user list do
get :index, :format = :xml
response.body.should == User.find(:all).to_xml
  end


end

It all looks straightforward enough - I use the same call on both the
controller and the spec, so the two results should indeed be the same.
However, when I run the spec I get this failure:

1)
'UsersController should return a XML user list' FAILED
expected: ?xml version=\1.0\ encoding=\UTF-8\?\nusers
type=\array\\n  user\ncreated-at
type=\datetime\2008-10-20T11:24:28Z/created-at\n
emailemail/email\nid type=\integer\953125641/id\n
nameName/name\nupdated-at
type=\datetime\2008-10-20T11:24:28Z/updated-at\n
/user\n/users\n,
 got:   (using ==)
./spec/controllers/users_controller_spec.rb:10:
/usr/lib64/ruby/1.8/timeout.rb:53:in `timeout'

Finished in 0.256981 seconds


This happens both when using rake spec and when running only that
spec file. Firing up the app and accessing localhost:3000/users.xml
returns the correct result. In the real project, it's even weirder:
the expected site of the assertion shows a string composed of the
XML out put concatenated to itself, and the got side has the correct
output. Something like Expected 'aa' but got 'a'.

What could the problem be? Is it really a RSpec bug, or is it
something I did wrong?


-- 
Bira
http://compexplicita.wordpress.com
http://compexplicita.tumblr.com
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] testing a render layout statement in a controller

2008-10-20 Thread Bart Zonneveld


On 16-okt-2008, at 8:50, Dave Gamphani Phiri wrote:


Here, I was trying to test if the out put displays with a layouts/menu
template.
Can somebody help on how you test the render(:layout = layouts/
menu) statement in a controller or this is supposed to be tested in
the view?


Try this:

render(:layout = layouts/menu) and return

cheers,
bartz
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread David Chelimsky
On Mon, Oct 20, 2008 at 6:53 AM, Harry Bishop [EMAIL PROTECTED] wrote:
 Scott Taylor wrote:
 On Oct 20, 2008, at 1:00 AM, Harry Bishop wrote:

  before(:each) do
 true.
 end
 action.

 A mock would require rebuilding the User model for all the checks done
 in the controller and I am trying to avoid that by using a fixture
 called from the database to test the true interaction between user and
 motion.

 Not necessarily.  Have you looked into using a null_object mock?

 Scott

 Yes, I tried null object but it doesn't get past is_showable? which says
 it has a nil object passed in.
 The idea is to use @current_user to determine if @motion is shown on the
 view.  So how come @current_user isn't available in the controller?

Can you please post the controller code?


 TIA,
 HR
 --
 Posted via http://www.ruby-forum.com/.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
David Chelimsky wrote:
 On Mon, Oct 20, 2008 at 6:53 AM, Harry Bishop [EMAIL PROTECTED] 
 wrote:
 called from the database to test the true interaction between user and
 motion.

 Not necessarily.  Have you looked into using a null_object mock?

 Scott

 Yes, I tried null object but it doesn't get past is_showable? which says
 it has a nil object passed in.
 The idea is to use @current_user to determine if @motion is shown on the
 view.  So how come @current_user isn't available in the controller?
 
 Can you please post the controller code?

Hi,
The controller show action is:

 def show
@motion = Motion.find(params[:id])
if is_showable?(@current_user, @motion)
  (@vote = @motion.votes.find_by_shortname(@current_user.shortname)) 
if is_votable?(@current_user, @motion)

  respond_to do |format|
format.html # show.html.erb
format.xml  { render :xml = @motion }
end
else
flash[:error] = You are not in that group.
redirect_to motions_path
end
  end

HR
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread David Chelimsky
On Mon, Oct 20, 2008 at 7:24 AM, Harry Bishop [EMAIL PROTECTED] wrote:
 David Chelimsky wrote:
 On Mon, Oct 20, 2008 at 6:53 AM, Harry Bishop [EMAIL PROTECTED]
 wrote:
 called from the database to test the true interaction between user and
 motion.

 Not necessarily.  Have you looked into using a null_object mock?

 Scott

 Yes, I tried null object but it doesn't get past is_showable? which says
 it has a nil object passed in.
 The idea is to use @current_user to determine if @motion is shown on the
 view.  So how come @current_user isn't available in the controller?

 Can you please post the controller code?

 Hi,
 The controller show action is:

  def show
@motion = Motion.find(params[:id])
if is_showable?(@current_user, @motion)
  (@vote = @motion.votes.find_by_shortname(@current_user.shortname))
 if is_votable?(@current_user, @motion)

  respond_to do |format|
format.html # show.html.erb
format.xml  { render :xml = @motion }
end
else
flash[:error] = You are not in that group.
redirect_to motions_path
end
  end

Where is @current_user defined in the controller?


 HR
 --
 Posted via http://www.ruby-forum.com/.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
Harry Bishop wrote:
 David Chelimsky wrote:
 On Mon, Oct 20, 2008 at 6:53 AM, Harry Bishop [EMAIL PROTECTED] 
 wrote:
 called from the database to test the true interaction between user and
 motion.

 Not necessarily.  Have you looked into using a null_object mock?

 Scott

 Yes, I tried null object but it doesn't get past is_showable? which says
 it has a nil object passed in.
 The idea is to use @current_user to determine if @motion is shown on the
 view.  So how come @current_user isn't available in the controller?
 
 Can you please post the controller code?
 
 Hi,
 The controller show action is:

  def show
 @motion = Motion.find(params[:id])
 if is_showable?(@current_user, @motion)
   (@vote = 
@motion.votes.find_by_shortname(@current_user.shortname))
 if is_votable?(@current_user, @motion)

   respond_to do |format|
 format.html # show.html.erb
 format.xml  { render :xml = @motion }
 end
 else
 flash[:error] = You are not in that group.
 redirect_to motions_path
 end
   end

 HR

and is_showable? here:

  def is_showable?(user, motion)
user.group_member?( motion.group_name )
  end
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
@current_user is retrieved in the application controller with 
retrieve_user.
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread David Chelimsky
On Mon, Oct 20, 2008 at 7:30 AM, Harry Bishop [EMAIL PROTECTED] wrote:
 @current_user is retrieved in the application controller with
 retrieve_user.

I don't see where retrieve_user is getting called in the rspec example
code or in the show action. Maybe it's not actually getting called
anywhere?

 --
 Posted via http://www.ruby-forum.com/.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
David Chelimsky wrote:
 On Mon, Oct 20, 2008 at 7:30 AM, Harry Bishop [EMAIL PROTECTED] 
 wrote:
 @current_user is retrieved in the application controller with
 retrieve_user.
 
 I don't see where retrieve_user is getting called in the rspec example
 code or in the show action. Maybe it's not actually getting called
 anywhere?

I guess that is what's happening, although I have this line in the 
before(:each)

controller.stub!(:retrieve_user).and_return(@current_user)

and the show action has a :login_required which calls :logged_in?
since MotionsController is a subclass of ApplicationController doesn't 
running the rspec test invoke the methods here:

class ApplicationController  ActionController::Base
  helper :all # include all helpers, all the time
  before_filter :retrieve_user

  protected

  def retrieve_user
return unless session[:user_id]
@current_user = Person.current_auth_record(session[:user_id])
  end

  def logged_in?
@current_user.is_a?(Person)
  end
  helper_method :logged_in?

  def login_required
return true if logged_in?
session[:return_to] = request.request_uri
redirect_to new_session_path and return false
  end

end
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread David Chelimsky
On Mon, Oct 20, 2008 at 8:02 AM, Harry Bishop [EMAIL PROTECTED] wrote:
 David Chelimsky wrote:
 On Mon, Oct 20, 2008 at 7:30 AM, Harry Bishop [EMAIL PROTECTED]
 wrote:
 @current_user is retrieved in the application controller with
 retrieve_user.

 I don't see where retrieve_user is getting called in the rspec example
 code or in the show action. Maybe it's not actually getting called
 anywhere?

 I guess that is what's happening, although I have this line in the
 before(:each)

 controller.stub!(:retrieve_user).and_return(@current_user)

 and the show action has a :login_required which calls :logged_in?
 since MotionsController is a subclass of ApplicationController doesn't
 running the rspec test invoke the methods here:

 class ApplicationController  ActionController::Base
  helper :all # include all helpers, all the time
  before_filter :retrieve_user

  protected

  def retrieve_user
return unless session[:user_id]
@current_user = Person.current_auth_record(session[:user_id])
  end

retrieve_user, the real method, sets an instance variable that other
methods expect to be set rather than returning a value. When this is
stubbed with a *return value* of the user, the instance variable never
gets set inside the controller.

I'd add a current_user method that returns @current_user, and then
stub *that* in the code examples:

# in ApplicationController

def current_user
  @current_user
end

# in MotionsController

def show
  ...
  if is_showable?(current_user, @motion)
  ...
end

# in example

controller.stub!(:current_user).and_return(@current_user)

HTH,
David




  def logged_in?
@current_user.is_a?(Person)
  end
  helper_method :logged_in?

  def login_required
return true if logged_in?
session[:return_to] = request.request_uri
redirect_to new_session_path and return false
  end

 end
 --
 Posted via http://www.ruby-forum.com/.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] RSpec-Rails bug with to_xml?

2008-10-20 Thread Zach Dennis
On Mon, Oct 20, 2008 at 7:30 AM, Bira [EMAIL PROTECTED] wrote:
 Hello, everyone. I've been lurking here for a while, but this is my first 
 post.

 I think I've run into a RSpec bug in a Rails project I'm working on. I
 was working on a few REST controllers, and started getting failures on
 a specific spec that verified whether a certain action returned XML
 output. I spent quite a lot of time checking my code to see if it was
 something I did wrong, but it works when I test it manually.

 So I created an empty Rails app, and wrote the bare minimum of code
 necessary to reproduce this problem. I'm using Rails 2.1.1, with
 rspec-1.1.8 and rspec-rails-1.1.8, all installed as gems.

 I started by creating a dead-simple model with two string attributes
 and no validations, along with this fixture:

 # spec/fixtures/users.yml
 one:
  name: Name
  email: email

 Then I created a simple controller, and its corresponding spec.

 class UsersController  ApplicationController

  def index
respond_to do |format|
  format.xml { render :xml = User.find(:all).to_xml}
end
  end

 end

 # spec

 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

 describe UsersController do

  fixtures :users

  it should return a XML user list do
get :index, :format = :xml
response.body.should == User.find(:all).to_xml
  end


 end

 It all looks straightforward enough - I use the same call on both the
 controller and the spec, so the two results should indeed be the same.
 However, when I run the spec I get this failure:

 1)
 'UsersController should return a XML user list' FAILED
 expected: ?xml version=\1.0\ encoding=\UTF-8\?\nusers
 type=\array\\n  user\ncreated-at
 type=\datetime\2008-10-20T11:24:28Z/created-at\n
 emailemail/email\nid type=\integer\953125641/id\n
 nameName/name\nupdated-at
 type=\datetime\2008-10-20T11:24:28Z/updated-at\n
 /user\n/users\n,
 got:   (using ==)
 ./spec/controllers/users_controller_spec.rb:10:
 /usr/lib64/ruby/1.8/timeout.rb:53:in `timeout'

 Finished in 0.256981 seconds


 This happens both when using rake spec and when running only that
 spec file. Firing up the app and accessing localhost:3000/users.xml
 returns the correct result. In the real project, it's even weirder:
 the expected site of the assertion shows a string composed of the
 XML out put concatenated to itself, and the got side has the correct
 output. Something like Expected 'aa' but got 'a'.

 What could the problem be? Is it really a RSpec bug, or is it
 something I did wrong?

Look up  integrate_views on the rspec-rails docs:
   http://rspec.rubyforge.org/rspec-rails/1.1.8/

Also there is a section called Integration Model. Read that. If you
have any further questions don't hesitate to ask. HTH,


-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
David Chelimsky wrote:
 retrieve_user, the real method, sets an instance variable that other
 methods expect to be set rather than returning a value. When this is
 stubbed with a *return value* of the user, the instance variable never
 gets set inside the controller.
 
 I'd add a current_user method that returns @current_user, and then
 stub *that* in the code examples:

 Hi David,
I understand your response now that its pointed out what is happening 
between controller and rspec, however, this means changing my code to 
test it.  This strikes me as backward. Isn't there another way to get 
the @current_user set for use in the controller?

BTW - the actual code runs fine.

HR


-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
 David Chelimsky wrote:

 
 I'd add a current_user method that returns @current_user, and then
 stub *that* in the code examples:

  Hi David,

I found that I can stub out is_showable?(@current_user, @motion) and the 
test passes.  I was trying to use the code logic to do this, but now see 
that @current_user won't be seen by the show action as it is set in the 
actual code.
Thanks for your help.
HR
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread David Chelimsky
On Mon, Oct 20, 2008 at 8:29 AM, Harry Bishop [EMAIL PROTECTED] wrote:
 David Chelimsky wrote:
 retrieve_user, the real method, sets an instance variable that other
 methods expect to be set rather than returning a value. When this is
 stubbed with a *return value* of the user, the instance variable never
 gets set inside the controller.

 I'd add a current_user method that returns @current_user, and then
 stub *that* in the code examples:

  Hi David,
 I understand your response now that its pointed out what is happening
 between controller and rspec, however, this means changing my code to
 test it.  This strikes me as backward.

When things are hard to test they are hard to maintain, so
maintainability requires testability. When a simple change makes
something easier to test, that change brings a lot of value. That's
the spirit of rspec, BDD and even TDD.

 Isn't there another way to get
 the @current_user set for use in the controller?

Sure, but it's fugly:

controller.instance_eval { @current_user = people(:someuser) }

 BTW - the actual code runs fine.

Since maintainability requires testability, just because it works
doesn't mean it's maintainable.

FWIW,
David


 HR


 --
 Posted via http://www.ruby-forum.com/.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
David Chelimsky wrote:

 When things are hard to test they are hard to maintain, so
 maintainability requires testability. When a simple change makes
 something easier to test, that change brings a lot of value. That's
 the spirit of rspec, BDD and even TDD.

Thanks David,
I am new to rspec and am enjoying the interchange between build a test 
then build the code.  In this case I'm late to the party.  This 
particular setup for @current_user makes sense to me but I understand 
your point about maintainability.

In trying to understand what rspec is doing, my thinking was that since 
MotionsController is a subclass of ApplicationController any instance 
variable set in ApplicationController was available to 
MotionsController. I think you are telling me that rspec doesn't invoke 
this. So I need to think about the implications here.

Yes, I want the advantages of rspec and having maintainable code.

HR

-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Zach Dennis
On Mon, Oct 20, 2008 at 10:09 AM, Harry Bishop [EMAIL PROTECTED] wrote:
 David Chelimsky wrote:

 When things are hard to test they are hard to maintain, so
 maintainability requires testability. When a simple change makes
 something easier to test, that change brings a lot of value. That's
 the spirit of rspec, BDD and even TDD.

 Thanks David,
 I am new to rspec and am enjoying the interchange between build a test
 then build the code.  In this case I'm late to the party.  This
 particular setup for @current_user makes sense to me but I understand
 your point about maintainability.

 In trying to understand what rspec is doing, my thinking was that since
 MotionsController is a subclass of ApplicationController any instance
 variable set in ApplicationController was available to
 MotionsController. I think you are telling me that rspec doesn't invoke
 this. So I need to think about the implications here.

The @current_user instance variable was being set by the
ApplicationController#retrieve_user method, but your spec was stubbing
out the #retrieve_user method. This means that the original
ApplicationController#retreieve_user method is not going to get called
because you have explicitly told RSpec to stub out that method and
return the current user from your spec. Since the original method is
not going to get called the @current_user instance variable in the
controller never gets set.


-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
Scott Taylor wrote:
 On Oct 20, 2008, at 1:00 AM, Harry Bishop wrote:
 
  before(:each) do
 true.
 end
 action.

 A mock would require rebuilding the User model for all the checks done
 in the controller and I am trying to avoid that by using a fixture
 called from the database to test the true interaction between user and
 motion.
 
 Not necessarily.  Have you looked into using a null_object mock?
 
 Scott

Yes, I tried null object but it doesn't get past is_showable? which says 
it has a nil object passed in.
The idea is to use @current_user to determine if @motion is shown on the 
view.  So how come @current_user isn't available in the controller?

TIA,
HR
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] RSpec-Rails bug with to_xml?

2008-10-20 Thread Nick Hoffman

On 2008-10-20, at 09:19, Zach Dennis wrote:

Look up  integrate_views on the rspec-rails docs:
  http://rspec.rubyforge.org/rspec-rails/1.1.8/

Also there is a section called Integration Model. Read that. If you
have any further questions don't hesitate to ask. HTH,


Hi Zach. I searched for integration on that page, searched Google,  
and did a Google site-search on rspec.info and rspec.rubyforge.org for  
integration model, but no relevant hits came up. When you have a  
minute, would you mind sending a link our way, please?


Thanks,
Nick
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] RSpec-Rails bug with to_xml?

2008-10-20 Thread David Chelimsky
On Mon, Oct 20, 2008 at 10:21 AM, Nick Hoffman [EMAIL PROTECTED] wrote:
 On 2008-10-20, at 09:19, Zach Dennis wrote:

 Look up  integrate_views on the rspec-rails docs:
  http://rspec.rubyforge.org/rspec-rails/1.1.8/

 Also there is a section called Integration Model. Read that. If you
 have any further questions don't hesitate to ask. HTH,

 Hi Zach. I searched for integration on that page, searched Google, and did
 a Google site-search on rspec.info and rspec.rubyforge.org for integration
 model, but no relevant hits came up. When you have a minute, would you mind
 sending a link our way, please?

It's Integration Mode, not Model :)

http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html

Cheers,
David


 Thanks,
 Nick
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] RSpec-Rails bug with to_xml?

2008-10-20 Thread Zach Dennis
On Mon, Oct 20, 2008 at 11:24 AM, David Chelimsky [EMAIL PROTECTED] wrote:
 On Mon, Oct 20, 2008 at 10:21 AM, Nick Hoffman [EMAIL PROTECTED] wrote:
 On 2008-10-20, at 09:19, Zach Dennis wrote:

 Look up  integrate_views on the rspec-rails docs:
  http://rspec.rubyforge.org/rspec-rails/1.1.8/

 Also there is a section called Integration Model. Read that. If you
 have any further questions don't hesitate to ask. HTH,

 Hi Zach. I searched for integration on that page, searched Google, and did
 a Google site-search on rspec.info and rspec.rubyforge.org for integration
 model, but no relevant hits came up. When you have a minute, would you mind
 sending a link our way, please?

 It's Integration Mode, not Model :)

Sorry about that Nick, typo on my end!


 http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html

 Cheers,
 David



-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
Zach Dennis wrote:

 The @current_user instance variable was being set by the
 ApplicationController#retrieve_user method, but your spec was stubbing
 out the #retrieve_user method. This means that the original
 ApplicationController#retreieve_user method is not going to get called
 because you have explicitly told RSpec to stub out that method and
 return the current user from your spec. Since the original method is
 not going to get called the @current_user instance variable in the
 controller never gets set.
 
Hi Zack,
I put the stub in to advance the process to the MotionsController 
because without it the process hangs in ApplicationController with a 
redirect to show.
My test log shows the 302 but show doesn't get called.  Is there some 
way around that?

So far David's method of making retrieve_user return @current_user
and stubbing the protected method is_showable? works but doesn't 
recognize the inheritance that should be there for @current_user.

HR

-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] ????? lots of Q's about integration tests with rspec

2008-10-20 Thread Rasmus Rasmussen
Hello all,

where should I put the integration tests when using rspec?

There is an integration-folder in test-directory, but if I place tests
here then how can I benefit from the fixtures-dir in spec-folder? I want
to stay in the spec-folder, right? I do not want to maintain two
fixtures. I'm not sure how important it is to stick with the
default-folders that come with rspec and rails. What if I need those
scripts someday.

According to rspec's documentation they recommend that I stub out the
model when testing controller. For me there is not much value from
testing controllers this way. Controller-code is small, it is often
mostly workflow-code. Also, I thought that part of the whole method of
BDD was to begin with full-integration tests at the outermost level and
that I then perhaps could work my way in to the model with unit tests. I
cannot understand why I should stub out model in controller-tests and
call db in model-tests. Shouldn't it be the other way round? Drill
through the whole cake from controller-tsts and stub everything else out
from model-tests ?

I would rather delete spec/controller and have something like spec/full
or maybe spec/requirements. That would give me my full-integration tests
and the controller-tests. Are there any problems with this strategy?

Thanks for advice!

/Rasmus
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread David Chelimsky
On Mon, Oct 20, 2008 at 11:34 AM, Harry Bishop [EMAIL PROTECTED] wrote:
 Zach Dennis wrote:

 The @current_user instance variable was being set by the
 ApplicationController#retrieve_user method, but your spec was stubbing
 out the #retrieve_user method. This means that the original
 ApplicationController#retreieve_user method is not going to get called
 because you have explicitly told RSpec to stub out that method and
 return the current user from your spec. Since the original method is
 not going to get called the @current_user instance variable in the
 controller never gets set.

 Hi Zack,
 I put the stub in to advance the process to the MotionsController
 because without it the process hangs in ApplicationController with a
 redirect to show.
 My test log shows the 302 but show doesn't get called.  Is there some
 way around that?

 So far David's method of making retrieve_user return @current_user

That's not what I recommended. I recommended adding a new method named
current_user that returns @current_user, so you can refer to just
current_user in method calls and stub that out if you want to control
its value from the code example.

 and stubbing the protected method is_showable? works but doesn't
 recognize the inheritance that should be there for @current_user.

Inheritance?


 HR

 --
 Posted via http://www.ruby-forum.com/.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread Harry Bishop
Hi David,

Yes, I understand.  I was trying to answer Zack with regard to my 
attempt to set the @current_user and what happened.

I will be using your method as a test shortly.

Thanks,
HR
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Where is current_user?

2008-10-20 Thread David Chelimsky
On Mon, Oct 20, 2008 at 12:01 PM, Harry Bishop [EMAIL PROTECTED] wrote:
 Hi David,

 Yes, I understand.  I was trying to answer Zack with regard to my
 attempt to set the @current_user and what happened.

 I will be using your method as a test shortly.

Cool.


 Thanks,
 HR
 --
 Posted via http://www.ruby-forum.com/.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] ????? lots of Q's about integration tests with rspec

2008-10-20 Thread Zach Dennis
On Mon, Oct 20, 2008 at 12:49 PM, Rasmus Rasmussen [EMAIL PROTECTED] wrote:
 Hello all,

 where should I put the integration tests when using rspec?

 There is an integration-folder in test-directory, but if I place tests
 here then how can I benefit from the fixtures-dir in spec-folder? I want
 to stay in the spec-folder, right? I do not want to maintain two
 fixtures. I'm not sure how important it is to stick with the
 default-folders that come with rspec and rails. What if I need those
 scripts someday.


If you don't need it today and it's not being used, delete it. If you
find you need it, well, that's why use version control.

 According to rspec's documentation they recommend that I stub out the
 model when testing controller. For me there is not much value from
 testing controllers this way. Controller-code is small, it is often
 mostly workflow-code. Also, I thought that part of the whole method of
 BDD was to begin with full-integration tests at the outermost level and
 that I then perhaps could work my way in to the model with unit tests. I
 cannot understand why I should stub out model in controller-tests and
 call db in model-tests. Shouldn't it be the other way round? Drill
 through the whole cake from controller-tsts and stub everything else out
 from model-tests ?

A controller test is not an integration test. In default Rails testing
(non-rspec) controllers are often tested this way, but in RSpec
controllers are treated as objects that should be tested in isolation.
Stories/features are used to run through the whole stack. Cucumber is
the tool that you'll want to look into for providing that full-stack
integration testing when using RSpec:
http://github.com/aslakhellesoy/cucumber/wikis

I know there are people who use controller specs are integration-style
tests with RSpec. You'll want to look into Integration Mode  if you
are interested in doing that:
http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html

I don't do that, and I don't encourage others to do that, but there
are situations where people feel it is valuable, just not me. The fact
that controllers are simple is a great thing. Spec'ing controllers in
isolation puts you in a position to leave controllers simple as the
application grows and changes


 I would rather delete spec/controller and have something like spec/full
 or maybe spec/requirements. That would give me my full-integration tests
 and the controller-tests. Are there any problems with this strategy?

There is a well-defined directory structure for a reason. When writing
Rails apps you get a lot of niceties for free from rspec-rails based
on how the directory structure is laid out. You could come up with
whatever directory you want, but you'll have to configure and/or tweak
rspec so it gives you the same niceties.

I recommend trying to do things the default rspec way, and then as you
become familiar with it you should start branching out into trying
different ways of doing things, and post back to the mailing list
along the way so you can share. Perhaps some of what you find out will
prove to be helpful to others, or will even lead to changes for the
betterment of writing software using RSpec.

I'm off to catch a plane, hopefully this has helped and not added
further confusion or frustration,

-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] ????? lots of Q's about integration tests with rspec

2008-10-20 Thread Matt Wynne

On 20 Oct 2008, at 17:49, Rasmus Rasmussen wrote:

I would rather delete spec/controller and have something like spec/ 
full
or maybe spec/requirements. That would give me my full-integration  
tests

and the controller-tests. Are there any problems with this strategy?


Find the cucumber project on github and you'll get a /features folder  
where you can write your full-stack tests, like rails 'integration'  
tests, or what the XP crowd like to call 'acceptance tests'.


You can then use the specs in the spec folder to drive out changes to  
individual classes, what the XP crowd calls unit testing.


How isolated you make those specs is up to you, but you'll find most  
people on this list will advocate using mocking to isolate  
controllers, I certainly do.


cheers,
Matt

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Merb

2008-10-20 Thread Ashley Moran


On Oct 19, 2008, at 10:31 pm, Caius Durling wrote:

Funny you should post this, I picked up merb today as well (seeing  
as the API is finally frozen) and was thinking about posting to see  
if anyone else was.


Well, I've done a bit more research (asking around on the Merb list),  
and it seems the best practice* in Merbland is to use controller specs  
in much the same way as Rails integration tests[1].  While I see the  
point that you should test behaviour not implementation, I think that  
goes a *little* too far.  In short, it's not recommended to do the  
equivalent of:


  it should create a new, unsaved person on GET to create do
Person.should_receive(:new).and_return(@person)
get 'create'
  end

There is an API for this though[2], and it was deprecated as of RC1,  
but has now apparently been reintroduced.


Lawrence Pit on the merb list explains the syntax:

 #  Example
 #   dispatch_to(MyController, :create, :name = 'Homer' ) do
|controller|
 # controller.stub!(:current_user).and_return(@user)
 #   end



And I assume it works similarly with the #get, #post etc.  (I have yet  
to try it though, and I can't visualise a clean way to write specs  
with it.)



Anyway the whole discussion provoked me to crystallise my thoughts on  
Ruby web BDD, which I decided to blog[3], and I thought it may be of  
interest to people here, in case there's yet a third right way of  
doing things.


(If anyone finds this of interest, let me know.  If so, I might start  
an Adventures in Merb BDD series - or something - on my blog.)



Ashley


* I've padded up in anticipation of the chair I know Aslak will hurl  
when he reads that ;o)


[1] http://www.slideshare.net/wycats/testing-merb-presentation
[2] 
http://merbivore.com/documentation/0.9.9/doc/rdoc/merb-core/index.html?a=C0147name=RequestHelper
[3] http://aviewfromafar.net/2008/10/20/web-app-bdd-thoughts-as-i-move-to-merb


--
http://www.patchspace.co.uk/
http://aviewfromafar.net/

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Merb

2008-10-20 Thread Ben Mabey

Ashley Moran wrote:


On Oct 19, 2008, at 10:31 pm, Caius Durling wrote:

Funny you should post this, I picked up merb today as well (seeing as 
the API is finally frozen) and was thinking about posting to see if 
anyone else was.


Well, I've done a bit more research (asking around on the Merb list), 
and it seems the best practice* in Merbland is to use controller specs 
in much the same way as Rails integration tests[1].  While I see the 
point that you should test behaviour not implementation, I think that 
goes a *little* too far.  In short, it's not recommended to do the 
equivalent of:


  it should create a new, unsaved person on GET to create do
Person.should_receive(:new).and_return(@person)
get 'create'
  end

There is an API for this though[2], and it was deprecated as of RC1, 
but has now apparently been reintroduced.


Lawrence Pit on the merb list explains the syntax:

 #  Example
 #   dispatch_to(MyController, :create, :name = 'Homer' ) do
|controller|
 # controller.stub!(:current_user).and_return(@user)
 #   end



And I assume it works similarly with the #get, #post etc.  (I have yet 
to try it though, and I can't visualise a clean way to write specs 
with it.)



Anyway the whole discussion provoked me to crystallise my thoughts on 
Ruby web BDD, which I decided to blog[3], and I thought it may be of 
interest to people here, in case there's yet a third right way of 
doing things.


(If anyone finds this of interest, let me know.  If so, I might start 
an Adventures in Merb BDD series - or something - on my blog.)



Ashley


* I've padded up in anticipation of the chair I know Aslak will hurl 
when he reads that ;o)


[1] http://www.slideshare.net/wycats/testing-merb-presentation
[2] 
http://merbivore.com/documentation/0.9.9/doc/rdoc/merb-core/index.html?a=C0147name=RequestHelper 

[3] 
http://aviewfromafar.net/2008/10/20/web-app-bdd-thoughts-as-i-move-to-merb 




Yeah... In regards to the controller specs... I wouldn't call that 'best 
practice' or 'the' right way.  I would call that wycats's way of testing 
and how most of the merb community has decided to follow suite.  I'm not 
saying a purely mock-based approach is 'best practices' either- they are 
both good practices and infinitively better than the alternative of 
having no tests at all!


That being said, I'm a big proponent of outside-in development which is 
largely made possible by being able to spec out your interface with 
mocks *before* it exists.  We had a good discussion on the tradeoffs of 
using mocks on this list recently.  Here is a message from that thread, 
by Zach Dennis, in which he explains outside-in development very well:

http://rubyforge.org/pipermail/rspec-users/2008-September/008426.html

It seems like the merb community places more emphasis on application 
wide tests- which is good since that is all the customer will really 
care about in the end.   Application wide tests are great (and that is 
why we have cucumber) but I wouldn't forgoe having a fast object level 
suite.  Without a lightning fast suite the refactoring process will be 
drawn out and tracking down breaks can be harder without the focused 
object examples.  That has been my experience at least and so that is 
why I like to have application level features which touch the entire 
stack and then have faster and more focussed object level specs that 
rely on mocking.


Like I said, that is how I like to development my apps and not 'the' 
right way to do it.


Anyways, thanks for sharing your findings.

-Ben


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] [ANN] rspec 1.1.9 Released

2008-10-20 Thread David Chelimsky
rspec version 1.1.9 has been released!

* http://rspec.info/

Behaviour Driven Development for Ruby.

Changes:

### Version 1.1.9 / 2008-10-20

WARNING: This release removes implicit inclusion of modules in example groups.
This means that if you have 'describe MyModule do', MyModule will not be
included in the group.

* 2 major enhancements

  * Add extend to configuration (thanks to advice from Chad Fowler)
  * Modules are no longer implicitly included in example groups

* 4 minor enhancements

  * mingw indicates windows too (thanks to Luis Lavena for the tip)
  * improved output for partial mock expecation failures
  * it_should_behave_like now accepts n names of shared groups
  * eliminated redundant inclusion/extension of ExampleGroupMethods

* 6 bug fixes

  * spec command with no arguments prints help
  * fixed typo in help. Fixes #73.
  * fixed bug where should_receive..and_yield after similar stub added
the args_to_yield to the stub's original args_to_yield (Pat Maddox)
  * fixed bug where rspec-autotest (autospec) was loading non-spec
files in spec directory. Fixes #559.
  * fixed bug where should_not_receive was reporting twice
  * fixed bug where rspec tries to run examples just because it is
required (even if there are no examples loaded). Fixes #575.

* http://rspec.info/
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] [ANN] rspec-rails 1.1.9 Released

2008-10-20 Thread David Chelimsky
rspec-rails version 1.1.9 has been released!

* http://rspec.info/

Behaviour Driven Development for Ruby on Rails.

Changes:

### Version 1.1.9 / 2008-10-20

* 4 bug fixes

  * require 'rubygems' in script/spec
  * fix failure message for error_on and errors_on (Patch from Mike
Vincent). Fixes #566.
  * fix issues that arise in view spec if passing actual template name
to render (Patch from Mike Vincent). Fixes #551.
  * fixed bug accessing assigns from helper examples

* http://rspec.info/
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users