Re: [rspec-users] No Method Error

2013-11-22 Thread David Chelimsky
Is it that you don't understand the error message or you don't understand
what to do about it?


On Fri, Nov 22, 2013 at 9:39 AM, Richard Jones li...@ruby-forum.com wrote:

 Hi,

 I'm getting the error below, can someone explain what I need to do?

 Failure/Error: @numbers.exchange(1).should be_true
 NoMethodError:
  private method 'exchange' called for #Numbers_Game
 # ./numbers_spec.rb:55:in 'block (2 levels) in top (required)'

 Greatly appreciated

 Richy

 --
 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] How do you nest before(:all) or after(:all) blocks?

2013-10-24 Thread David Chelimsky
The lighthouse tracker was shut down years ago, sorry. But you can learn
about what works and what doesn't re: nested before/after hooks from
https://www.relishapp.com/rspec/rspec-core/docs/hooks and
http://rubydoc.info/gems/rspec-core/RSpec/Core/Hooks. Feel free to ask any
specific questions here on this list if the docs don't answer your
questions.

Cheers,
David


On Thu, Oct 24, 2013 at 1:39 PM, Dhananjay V. li...@ruby-forum.com wrote:

  http://rspec.lighthouseapp.com/projects/5645/tickets/632


 something i wish i could get additional information from other users??


 I could not see the status of the ticket as it was restricted..Any
 updates with regards to the use of the global variable objects in the
 same script call before test.. Any best practices mentioned or
 suggested???

 --
 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] help renders new/edit user_mst form

2013-06-10 Thread David Chelimsky
On Mon, Jun 10, 2013 at 3:47 AM, Oliver Jesus oliverjesus2...@yahoo.comwrote:

 Hello! I need a little help.

 If I run my rspec (rspec spec --backtrace) I've got error like this.
 Please help my. I greatly appreciated your answers.

 Finished in 14.39 seconds
 173 examples, 6 failures, 5 pending

 Failed examples:

 rspec ./spec/views/department_msts/edit.html.erb_spec.rb:12 #
 department_msts/ed
 it.html.erb renders the edit department_mst form
 rspec ./spec/views/department_msts/new.html.erb_spec.rb:12 #
 department_msts/new
 .html.erb renders new department_mst form
 rspec ./spec/views/employee_msts/edit.html.erb_spec.rb:19 #
 employee_msts/edit.h
 tml.erb renders the edit employee_mst form
 rspec ./spec/views/employee_msts/new.html.erb_spec.rb:19 #
 employee_msts/new.htm
 l.erb renders new employee_mst form
 rspec ./spec/views/user_msts/edit.html.erb_spec.rb:17 #
 user_msts/edit.html.erb
 renders the edit user_mst form
 rspec ./spec/views/user_msts/new.html.erb_spec.rb:17 #
 user_msts/new.html.erb re
 nders new user_mst form


This is not the full backtrace, but I see you sent that in another email.
Even without the full backtrace, the following excerpt points you directly
to a specific problem spot:

61) user_msts/new.html.erb renders new user_mst form
 Failure/Error: render
 ActionView::Template::Error:
   You have a nil object when you didn't expect it!
   You might have expected an instance of Array.
   The error occurred while evaluating nil.collect
 # ./app/views/user_msts/_form.html.erb:44:in `block in
_app_views_user_msts

What is on line 44 of ./app/views/user_msts/_form.html.erb?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] help renders new/edit user_mst form

2013-06-10 Thread David Chelimsky
On Mon, Jun 10, 2013 at 4:25 AM, oliver oliverjesus2...@yahoo.com wrote:

 %= f.select :group_name,
 options_for_select(@group_mst.collect{|x| [x.group_name]}), {:multiple =
 :multiple} %

 that is on the line 44.


And the error raised on that line says The error occurred while evaluating
nil.collect. The only thing receiving collect on that line is
@group_mst, so the spec has to do something to assign an Enumerable to
@group_mst before calling render in the spec. Is there a line in the
controller that assigns something to @group_mst? If so, what's on that line?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] help renders new/edit user_mst form

2013-06-10 Thread David Chelimsky
On Mon, Jun 10, 2013 at 4:39 AM, oliver oliverjesus2...@yahoo.com wrote:

   def new
 @user_mst = UserMst.new
 @group_mst = GroupMst.all


Under normal circumstances, this line ^^ would assign @group_mst an empty
collection, not nil, so something is wrong with the way things are set
up/configured.

What happens if you stub GroupMst.all in the spec:

GroupMst.stub(:all = [])

Please try that and then run just one example like this:

rspec spec/views/user_msts/new.html.erb_spec.rb:18 --backtrace

And then post the complete output.





 respond_to do |format|
   format.html # new.html.erb
   format.xml  { render :xml = @user_mst }
 end
   end


Those are the lines I include @group_mst.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] help renders new/edit user_mst form

2013-06-10 Thread David Chelimsky
On Mon, Jun 10, 2013 at 5:09 AM, oliver oliverjesus2...@yahoo.com wrote:



 --- On *Mon, 6/10/13, David Chelimsky-2 [via Ruby] [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=4991637i=0
 * wrote:


 From: David Chelimsky-2 [via Ruby] [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=4991637i=1
 
 Subject: Re: help renders new/edit user_mst form
 To: oliver [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=4991637i=2
 
 Date: Monday, June 10, 2013, 9:57 AM

 On Mon, Jun 10, 2013 at 4:39 AM, oliver [hidden email] wrote:

   def new
 @user_mst = UserMst.new
 @group_mst = GroupMst.all


 Under normal circumstances, this line ^^ would assign @group_mst an empty
 collection, not nil, so something is wrong with the way things are set
 up/configured.

 What happens if you stub GroupMst.all in the spec:

 GroupMst.stub(:all = [])

 Please try that and then run just one example like this:

 rspec spec/views/user_msts/new.html.erb_spec.rb:18 --backtrace

 And then post the complete output.





 respond_to do |format|
   format.html # new.html.erb
   format.xml  { render :xml = @user_mst }
 end
   end


 Those are the lines I include @group_mst.




 ___
 rspec-users mailing list
 [hidden email]
 http://rubyforge.org/mailman/listinfo/rspec-users

 --
  If you reply to this email, your message will be added to the discussion
 below:

 http://ruby.11.x6.nabble.com/help-renders-new-edit-user-mst-form-tp4991623p4991635.html
  To unsubscribe from help renders new/edit user_mst form, click here.
 NAMLhttp://ruby.11.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml



 late.rb:127:in `render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:59:in `block in _render_template'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `block in instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications/instrumenter.rb:21:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:56:in `_render_template'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:26:in `render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/test
 _case.rb:107:in `render'
  # ./spec/views/user_msts/new.html.erb_spec.rb:20:in `block (2 levels)
 in t
 op (required)'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le.rb:48:in `instance_eval'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le.rb:48:in `block in run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le.rb:107:in `with_around_hooks'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le.rb:45:in `run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le_group.rb:294:in `block in run_examples'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le_group.rb:290:in `map'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le_group.rb:290:in `run_examples'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le_group.rb:262:in `run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/comma
 nd_line.rb:24:in `block (2 levels) in run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/comma
 nd_line.rb:24:in `map'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/comma
 nd_line.rb:24:in `block in run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/repor
 ter.rb:12:in `report'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/comma
 nd_line.rb:21:in `run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runne
 r.rb:80:in `run_in_process'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runne
 r.rb:69:in `run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runne
 r.rb:11:in `block in autorun'

 Finished in 0.67188 seconds
 1 example, 1 failure

 Failed examples:

 rspec ./spec/views/user_msts/new.html.erb_spec.rb:19 #
 user_msts/new.html.erb re
 nders new user_mst form

 That is the output

Re: [rspec-users] help renders new/edit user_mst form

2013-06-10 Thread David Chelimsky
On Mon, Jun 10, 2013 at 5:18 AM, oliver oliverjesus2...@yahoo.com wrote:

  # ./app/views/employee_msts/new.html.erb:3:in
 `_app_views_employee_msts_new
 _html_erb__385952098_22995768_655956278'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/temp
 late.rb:135:in `block in render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `block in instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications/instrumenter.rb:21:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/temp
 late.rb:127:in `render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:59:in `block in _render_template'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `block in instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications/instrumenter.rb:21:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:56:in `_render_template'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:26:in `render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/test
 _case.rb:107:in `render'
  # ./spec/views/employee_msts/new.html.erb_spec.rb:20:in `block (2
 levels) i
 n top (required)'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le.rb:48:in `instance_eval'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le.rb:48:in `block in run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le.rb:107:in `with_around_hooks'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le.rb:45:in `run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le_group.rb:294:in `block in run_examples'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le_group.rb:290:in `map'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le_group.rb:290:in `run_examples'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 le_group.rb:262:in `run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/comma
 nd_line.rb:24:in `block (2 levels) in run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/comma
 nd_line.rb:24:in `map'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/comma
 nd_line.rb:24:in `block in run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/repor
 ter.rb:12:in `report'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/comma
 nd_line.rb:21:in `run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runne
 r.rb:80:in `run_in_process'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runne
 r.rb:69:in `run'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runne
 r.rb:11:in `block in autorun'

   5) user_msts/edit.html.erb renders the edit user_mst form
  Failure/Error: render
  ActionView::Template::Error:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.collect
  # ./app/views/user_msts/_form.html.erb:44:in `block in
 _app_views_user_msts
 __form_html_erb__114702870_19515960_961344552'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/capture_helper.rb:40:in `block in capture'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/capture_helper.rb:172:in `with_output_buffer'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/capture_helper.rb:40:in `capture'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/form_helper.rb:545:in `fields_for'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/form_helper.rb:320:in `form_for'
  # ./app/views/user_msts/_form.html.erb:1:in
 `_app_views_user_msts__form_htm
 l_erb__114702870_19515960_961344552'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/temp
 late.rb:135:in `block in render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `block in 

Re: [rspec-users] help renders new/edit user_mst form

2013-06-10 Thread David Chelimsky
On Mon, Jun 10, 2013 at 5:53 AM, oliver oliverjesus2...@yahoo.com wrote:

 C:\Documents and Settings\Oliver\Desktop\amsrspec
 spec/views/user_msts/new.html
 .erb_spec.rb:19 --backtrace
 Run filtered including {:line_number=19}
 F

 Failures:

   1) user_msts/new.html.erb renders new user_mst form
  Failure/Error: # Run the generator again with the --webrat flag if
 you want
  to use webrat matchers
  ActionView::Template::Error:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.collect
  # ./app/views/user_msts/_form.html.erb:44:in `block in
 _app_views_user_msts
 __form_html_erb__212366709_16540380_1066166632'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/capture_helper.rb:40:in `block in capture'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/capture_helper.rb:172:in `with_output_buffer'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/capture_helper.rb:40:in `capture'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/form_helper.rb:545:in `fields_for'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/help
 ers/form_helper.rb:320:in `form_for'
  # ./app/views/user_msts/_form.html.erb:1:in
 `_app_views_user_msts__form_htm
 l_erb__212366709_16540380_1066166632'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/temp
 late.rb:135:in `block in render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `block in instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications/instrumenter.rb:21:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/temp
 late.rb:127:in `render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/partials.rb:333:in `render_partial'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/partials.rb:262:in `block in render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `block in instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications/instrumenter.rb:21:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/partials.rb:260:in `render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/partials.rb:378:in `_render_partial'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/test
 _case.rb:149:in `_render_partial'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:31:in `render'
  # ./app/views/user_msts/new.html.erb:3:in
 `_app_views_user_msts_new_html_er
 b__441458415_16571532__735039642'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/temp
 late.rb:135:in `block in render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `block in instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications/instrumenter.rb:21:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/temp
 late.rb:127:in `render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:59:in `block in _render_template'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `block in instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications/instrumenter.rb:21:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_suppor
 t/notifications.rb:52:in `instrument'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:56:in `_render_template'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/rend
 er/rendering.rb:26:in `render'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/test
 _case.rb:107:in `render'
  # ./spec/views/user_msts/new.html.erb_spec.rb:20:in `block (2 levels)
 in t
 op (required)'
  #
 C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/examp
 

Re: [rspec-users] How to generate TAP output for Selenium-WebDriver TC written in Ruby

2013-06-09 Thread David Chelimsky
On Sun, Jun 9, 2013 at 12:29 AM, Prasun Prabhakar li...@ruby-forum.comwrote:

 Hello,

 We need to integrate Jenkins with TestLink. For now Iam able to run
 Selenium-WebDriver test cases from Jenkins using the inputs from
 TestLink. Now the problem is the reverse communication where the Jenkins
 test result needs to be updated in TestLInk.

  For this Jenkins provide test reporting using junit,TAP and testNG
 formats. The only option we have is to use TAP output format as we are
 not using junit or testNG framework. Here we use RSpec to write
 Selenium-WebDriver for the web testing, Is there a way to create TAP
 output?

 Iam attaching a sample testcase in Selenium 2.
 To run the test : $ SITE=www.google.com TITLE=google rspec CheckTitle.rb

 Would really appreciate your help!


Here are a few options:

https://github.com/sj26/rspec_junit_formatter
http://rubyworks.github.io/rspec-ontap/
https://github.com/dgvncsz0f/rspec_formatters

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

Re: [rspec-users] Error uccored while evaluating nil.collect

2013-06-07 Thread David Chelimsky
On Fri, Jun 7, 2013 at 5:02 AM, Oliver Jesus oliverjesus2...@yahoo.comwrote:

 Hello, I am new to RSpec and I've got error something like this:
 You have a nil object when you didn't expect it!
 You might have expected an instance of Array.
 The error occurred while evaluating nil.collect

 In my controller:

 def new
 @employee_mst = EmployeeMst.new
 @branch_mst = BranchMst.all(:group = branch_code)
 @department_mst = DepartmentMst.all

 respond_to do |format|
   format.html # new.html.erb
   format.xml  { render :xml = @employee_mst }
   format.xml  { render :xml = @branch_mst }
   format.xml  { render :xml = @department_mst }


I've never seen more than one use of the same format in a respond_to block
like this. I don't know if it's related to your issue, but I'm curious if
you saw this documented somewhere as being supported.


 end
   end

 In my RSpec controller:

   describe GET new do
 it assigns a new employee_mst as @employee_mst do
   get :new
   assigns(:employee_mst).should be_a_new(EmployeeMst)
 end
   end


 I think something is missing in RSpec controller, because I've add 4 lines
 of codes:
  @branch_mst = BranchMst.all(:group = branch_code)
  @department_mst = DepartmentMst.all
   format.xml  { render :xml = @branch_mst }
   format.xml  { render :xml = @department_mst }

 Please help me regarding this error. I greatly appreciated all those
 answers.


Please run the example with the backtrace flag:

rspec spec/controllers --backtrace

and then post the full backtrace so we can see where that error is being
raised.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Fuzzy should_receive matching

2013-05-30 Thread David Chelimsky
On Thu, May 30, 2013 at 2:44 AM, Alexander Baronec abo...@gmail.com wrote:

 Hello.
 I have a test problem when I should test arguments in method not by exact
 matching buy with fuzzy matching.

 For example I have this test:

 require 'rspec'

 describe do
   it do
 o = Object.new
 o.should_receive(:api_send).with mode: :say

 o.api_send mode: :say, time: Time.now + rand(1..10), bans: { login1:
 {time: Time.now, expiration: Time.now + 100}}

  end
 end

 I want helper to test that method api_send receive mode: :say, time:
 Time.now + rand(1..10), bans: { login1: {time: Time.now, expiration:
 Time.now + 100}} but I do not care about what time exactly is.

 I want something like

 inspect_api o, mode: :say, time: Time, bans: { login:1: {time: Time,
 expiration: Time}}


See docs:

http://rubydoc.info/gems/rspec-mocks/file/README.md#Argument_Matchers
http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers#hash_including-instance_method

(the info in the 2nd link needs to be added to the first - sorry)

You could do either of:

o.should_receive(:api_send).with hash_including(mode: :say)
o.should_receive(:api_send).with mode: :say, time: instance_of(Time),
:bans { login1: {time: instance_of(Time), expiration: instance_of(Time) }

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

Re: [rspec-users] Rspec + Devise + BaseController

2013-03-20 Thread David Chelimsky
On Wed, Mar 20, 2013 at 11:21 AM, Ezequiel Delpero li...@ruby-forum.com wrote:
 Finally I could solve the problem. The problem was on the definition of
 the anonymous controller on the spec:

 instead of:

 controller do
   def index
   end
 end

 I used:

 controller(Admins::Base) do
   def index
   end
 end

 You need to specify always the anonymous controller you're testing
 unless is ApplicationController the one you're trying to test.

FYI - docs: 
http://rubydoc.info/gems/rspec-rails/RSpec/Rails/ControllerExampleGroup/ClassMethods#controller-instance_method
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Assign default tag

2013-03-19 Thread David Chelimsky
On Tue, Mar 19, 2013 at 7:20 AM, Иван Неверов ivan.neve...@gmail.com wrote:
 Hi all
 Could somebody tell me, is it possible to assign some tag=value to all
 examples in directory?

 Like I want to mark all tests in spec/unit as :type='shallow'. And have
 some tests in other directory also with type shallow (assigned in describe)
 And then filter them with -t type:shallow


 Thanks
 Ivan

Unfortunately, there's nothing built in to support this. I'd recommend
you submit a feature request to
http://github.com/rspec/rspec-core/issues.

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

Re: [rspec-users] Assign default tag

2013-03-19 Thread David Chelimsky
On Tue, Mar 19, 2013 at 9:52 AM, Perry Smith pedz...@gmail.com wrote:

 On Mar 19, 2013, at 10:41 AM, David Chelimsky wrote:

 On Tue, Mar 19, 2013 at 7:20 AM, Иван Неверов ivan.neve...@gmail.com wrote:
 Hi all
 Could somebody tell me, is it possible to assign some tag=value to all
 examples in directory?

 Like I want to mark all tests in spec/unit as :type='shallow'. And have
 some tests in other directory also with type shallow (assigned in describe)
 And then filter them with -t type:shallow


 Thanks
 Ivan

 Unfortunately, there's nothing built in to support this. I'd recommend
 you submit a feature request to
 http://github.com/rspec/rspec-core/issues.

 I do this:

 config.include RSpec::Rails::ViewExampleGroup, type: :presenter, 
 example_group: {
   file_path: config.escaped_path(%w[spec presenters])
 }

 and it appears to work for me.  But David would know better than I.

 Am I fooling myself somehow?  Or did I misunderstand the question?

Actually that does point to a solution. The trick is the OP wants to
add a tag to the groups in that directory so that those examples can
be filtered, which means it has to be added _before_ filtering
happens. I hadn't thought there was a good way to do this, but your
example reminded me there is, sort of. The caveat is that this is a
bit magical and relies on a somewhat buried API that may or may not be
supported in the long term. That said, for now you _can_ do this:

module ShallowExampleGroup
  def self.included(host)
host.metadata[:type] = 'shallow'
  end
end

RSpec.configure do |config|
  config.include ShallowExampleGroup, example_group: {
file_path: config.escaped_path(%w[spec unit])
  }
end

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

Re: [rspec-users] stubbed methods are not returning what I've stubbed them to return

2013-03-16 Thread David Chelimsky
On Sat, Mar 16, 2013 at 7:56 AM, Dan Brooking dmbrook...@gmail.com wrote:
 I'm working on a small Sintra app and am having trouble getting my stub to
 return what I want it to.  I've been searching and found quite a few with
 this question but no real answers.  I also posted this to the sinatrarb
 google group in case it's an issue there.

 I have a helper method that returns a random string. I'm hoping it's
 something very simple I'm doing wrong

 def random_string(length)
   (0..length).map{ rand(36).to_s(36) }.join
 end


 I have my test written as follows:

 describe #random_string do
 it returns a random string do
 #Sinatra::Application.any_instance.stub(:random_string).and_return(abcdef)
 Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef')
 str = random_string(6)

Here ^^ random_string is being called in the context of the example,
not the Sinatra::Application class or any of its instances. I don't
know how Sinatra includes helper modules, but assuming that includes
them in the Sinatra::Application object, then this should work:

Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef')
Sinatra::Application.random_string(6).should eq 'abcdef'

HTH,
David

 str.should == abcdef
 end
 end


 I have tried both lines shown in the code, and both times, the code runs.
 Yet my tests are still failing.  It doesn't look like the stub is taking. My
 failure looks like:

 #random_string returns a random string
  Failure/Error: str.should == abcdef
expected: abcdef
 got: xcz0g7a (using ==)

 Any ideas?

 ___
 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] stubbed methods are not returning what I've stubbed them to return

2013-03-16 Thread David Chelimsky
On Sat, Mar 16, 2013 at 9:11 AM, Dan Brooking dmbrook...@gmail.com wrote:
 I got it...

 I called it using instance_eval.

 def app
 Sinatra::Application
 end

 describe #random_string do
 it returns a random string do
 app.should_receive(:random_string).with(6).and_return('abcdef')
 str = app.instance_eval(random_string(6))
 str.should == abcdef
 end
 end

It might pass, but this example tells you nothing about how the
random_string method should work. What is it that you're actually
wanting to specify here?



 On Sat, Mar 16, 2013 at 10:05 AM, Dan Brooking dmbrook...@gmail.com wrote:

 OK, so I think based on this, I'm doing it right and it's a Sinatra issue.
 I did as you suggested and made a call to Sinatra::Application.random_string
 and now my error is private method `random_string' called for
 Sinatra::Application:Class.

 So, like I said, looks to me like a Sintra specific issue where I need to
 reference it in a certain way.  It's such a small method, I don't really
 need to test this but it's used in other modules so I wanted to isolate this
 to ensure I've got the stubbing down right.

 Thanks!


 On Sat, Mar 16, 2013 at 9:58 AM, David Chelimsky dchelim...@gmail.com
 wrote:

 On Sat, Mar 16, 2013 at 7:56 AM, Dan Brooking dmbrook...@gmail.com
 wrote:
  I'm working on a small Sintra app and am having trouble getting my stub
  to
  return what I want it to.  I've been searching and found quite a few
  with
  this question but no real answers.  I also posted this to the sinatrarb
  google group in case it's an issue there.
 
  I have a helper method that returns a random string. I'm hoping it's
  something very simple I'm doing wrong
 
  def random_string(length)
(0..length).map{ rand(36).to_s(36) }.join
  end
 
 
  I have my test written as follows:
 
  describe #random_string do
  it returns a random string do
 
  #Sinatra::Application.any_instance.stub(:random_string).and_return(abcdef)
 
  Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef')
  str = random_string(6)

 Here ^^ random_string is being called in the context of the example,
 not the Sinatra::Application class or any of its instances. I don't
 know how Sinatra includes helper modules, but assuming that includes
 them in the Sinatra::Application object, then this should work:


 Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef')
 Sinatra::Application.random_string(6).should eq 'abcdef'

 HTH,
 David

  str.should == abcdef
  end
  end
 
 
  I have tried both lines shown in the code, and both times, the code
  runs.
  Yet my tests are still failing.  It doesn't look like the stub is
  taking. My
  failure looks like:
 
  #random_string returns a random string
   Failure/Error: str.should == abcdef
 expected: abcdef
  got: xcz0g7a (using ==)
 
  Any ideas?
 
  ___
  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




 ___
 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] Help solve distributed cucumber feature pain in 2 minutes or less

2013-03-11 Thread David Chelimsky
You'll probably get more and better feedback from
https://groups.google.com/forum/?fromgroups#!forum/cukes

On Mon, Mar 11, 2013 at 3:31 PM, Dan Williams deft.of.cen...@gmail.com wrote:
 Hey everybody,

 I have been beating my head on the wall when dealing with creating cucumber
 features in a distributed work environment.  So, we decided to make a
 collaborative editor that solves this problem. Do have two minutes to help
 guide us?

 https://docs.google.com/forms/d/1tQbUHzDyUARHbbVvsy143p-OdE09VTJ5cyxDpNR8bK4/viewform

 Thanks for your input!

 -Dan

 ___
 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] uninitialized constant Factory (NameError)

2013-02-28 Thread David Chelimsky
See https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md

It's FactoryGirl, not Factory (which used to be the correct constant,
but is no longer).

On Thu, Feb 28, 2013 at 8:44 AM, ruby rails li...@ruby-forum.com wrote:
 I have installed factory_girl_rails gem in Gemfile for both test as well
 as development. And in the password_rest_spec file I have given

 require 'spec_helper'
 describe PasswordResets do
 it emails when user requesting password reset do
 user = Factory(:user)
 #forget_pwd.userid.should == ruby
 #forget_pwd.token.should == 123456
 #forget_pwd.userkey = 14dd
   visit auth_index_path
   click_link Forgot Password
   fill_in Email, :with= user.email
   click_button Submit
   current_path.should eq(login_path)
   page.should have_content(Hello Rails)
   last_email.to.should include(user.email)
end
 end

 I have created another file called factories.rb where I have created the
 data as below.

 Factory.define :user do |f|
   f.sequence(:email) {|n| foo#{n}@example.com}
   f.password Secret
   end
 But when I am running this spec, it is failing and showing the error as
 uninitialized constant Factory (NameError).
 I have followed exactly as in the railscasts.
 http://railscasts.com/episodes/275-how-i-test

 Please help

 --
 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] Validation Failed: Userkey has already been taken, Email has already been taken

2013-02-28 Thread David Chelimsky
On Thu, Feb 28, 2013 at 12:57 PM, ruby rails li...@ruby-forum.com wrote:
 Hi,

 I am using Factory girl with rspec and capybara for testing my rails
 appliction. I have the below code
 FactoryGirl.define do
   factory :user do |f|
   f.email s...@gmail.com
   f.userkey 12ssd345q62
   end
 end

 When I run the test it is failing as Validation Failed: Userkey has
 already been taken, Email has already been taken.

 What could be the reason for this. I am new to Rspec.

If you have unique validations on email and userkey, you'll want the
factory to generate diff values every time. Take a look at
https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#sequences

I appreciate that you're new to RSpec, and lists like this exist to
provide help, but this is the 2nd time you've asked FactoryGirl
questions that could be answered by reading the FactoryGirl docs.
Please do so before the next question about FactoryGirl and, if it's
about FactoryGirl, you probably want to hit up
https://groups.google.com/forum/?fromgroups#!forum/factory_girl, and
restrict your questions on this list to those actually about rspec. If
you're not sure what the cause is, and can't figure out where else to
send your question, we can point you in the right direction.

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


Re: [rspec-users] Getting started

2012-11-19 Thread David Chelimsky
On Mon, Nov 19, 2012 at 7:22 AM, Suman I. li...@ruby-forum.com wrote:
 Hi I am new to using Cucumber. I am new to Ruby basically.

This is an RSpec mailing list. Please send this query to the Cucumber
mailing list: https://groups.google.com/group/cukes

We're here if you have any RSpec questions.

Cheers,
David


 I have installed Ruby gems and Cucumber on my machine. How do I get
 started?

 For Eg: I need to test Google.com, then how do I start testing using
 Cucumber?

 I don't know where to start from. Any help regarding this is
 appreciated.

 Thanks,
 Suman.

 --
 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] Did I write my specs as I should?

2012-11-18 Thread David Chelimsky
On Sat, Nov 17, 2012 at 3:51 PM, dougui dougui_...@hotmail.com wrote:
 Hello,

 I read a lot about rails and BDD and I think I've found my own path. I want
 to share my method and to know what you think about that.

 This is my workflow :

 Creation of feature specs (example 1);

 Only the happy path
 Test only things than the user can view;

^^ This is a good guideline if you're not sharing these w/ non-tech
business folk. If you are, however, there are going to be cases
they'll want specified so you'll need to decide whether you want to
share the whole rspec suite or just those in the features directory.

 Don't test the number of records of the database, if an email is sent or 
 other things like that;
 Keep it very simple;

^^ This can mean a lot of different things. I'd phrase this keep
things very high level.


 Watch the feature specs fails;
 Create views and routes;

^^ This depends on _how_ the feature fails. What you do next is
completely dependent upon the failure message you get. What I often
find is that the first failure says no route .. so I add a route.
The next failure is no controller action ... so I add an empty
controller action. Next is there's no view so I create an empty view
template. Now we get a logical failure instead of an error, saying the
content couldn't be found. At this point I'll start driving things out
in controller specs and view specs as necessary. If there is no
conditional logic in either place, I might bypass those
(controller/view specs) for the moment, but as soon as a new scenario
appears that forces any conditional logic into the controller or view,
they get their own specs.

 Watch the feature specs fail again;
 Create the controllers specs (example 2);

If you're just outlining them with pending examples (i.e. no bodies)
that's fine.

 Write the specs in complete isolation;
 Use Factory Girl's build_stubbed;
 Write a context for all conditons in ifs;

 Create the code for the controllers specs;

Not all at once. They idea is to implement one example, watch it fail,
then implement the code to make it pass, then on to the next example.

 Create the specs for all model's methods I stubbed;
 Write the code to pass the model's specs;
 Refactor;
 Continue to the next feature;

 I try to respect the single responsability principle (SRP) and Keep It
 Simple, Stupid (KISS).

 With the SRP, the controller should manage the majority of objects and it
 should not be a lot of depth. The models are used only for an interface with
 the database and do validation. All other things should have their own
 classes.

This is an implementation decision which is neither correct, nor
incorrect in the context of BDD.

 I write specs for mailers, helpers and all other classes.

 I found this mail :
 http://www.mail-archive.com/rspec-users@rubyforge.org/msg03883.html. And I
 think it's similar.

 I don't like Cucumber and I prefer Capybara.

You're comparing too different kinds of things. Cucumber supports a
language (Gherkin) for expressing requirements at a high level and
then binding those expressions to executable code. Capybara supports
interaction with a browser (real or simulated). You can't replace
Cucumber's role with Capybara. You can choose to bypass
Cucumber/Gherkin if you like, but if you're not replacing it with high
level language for expressing requirements, you're not doing BDD as it
is described by it's thought leaders (mostly Liz Keogh -
http://lunivore.com/liz-keogh) today.

This is not to suggest that what you're doing something has no value.
It's just not BDD.


 I read this :
 http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html
 but I just must moved my request in a feature folder. I don't want to create
 request tests. I think it test the same thing

I'd recommend you read
http://blog.plataformatec.com.br/2012/06/improving-the-integration-between-capybara-and-rspec/,
in which José Valim explains the different kinds of things he thinks
should go in feature specs and what he calls api specs (which spec
request object internals like headers and response codes).

 than my feature specs and it
 will be slow to create two integration tests.

 Example 1 : A Request Spec

 describe 'Create' do
   it 'add a new project' do
 sign_in
 visit new_project_path
 within('#new_project') do
   fill_in(Title, with: My Project)
   fill_in(Url, with: http://www.google.com;)
   select(Ruby, from: Type)
   click_button Create
 end
 page.should have_content(Your project was created)
   end
 end


 Example 2 : A Controller Spec

 describe #create do
 context with valid data do
 it redirect to project's path
 it save the project
 it set a flash message
 end
 context with invalid data do
 it render new template
 end
 end

 What do you think about that? Did I write my specs as I should?

You're definitely on a good path, but it's difficult to judge by
looking at 

Re: [rspec-users] change() vs change{}

2012-10-24 Thread David Chelimsky
On Wed, Oct 24, 2012 at 12:26 PM, Kevin McCaughey li...@ruby-forum.com wrote:
 Hi,

 I am doing the rails tutorial and there is a line:

 expect { click_button submit }.not_to change(User, :count)

 When I looked up the rspec docs and book too, I found:

 change {} documentation (using curly brackets).

Not sure which docs you looked at, but both () and {} are supported,
as described in rspec's rdoc:
http://rubydoc.info/gems/rspec-expectations/RSpec/Matchers#change-instance_method


 Could someone tell me what the difference is, and if I use a block for
 the above example, what would it look like?

 I am very confused about why there are two versions and can't seem to
 get examples for the block {} version to see it's proper usage.

 Many thanks!

 Kevin McCaughey

 --
 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] Issues upgrading RSpec

2012-10-18 Thread David Chelimsky
On Thu, Oct 18, 2012 at 6:58 PM, Rodrigo Rosenfeld Rosas
lboc...@yahoo.com.br wrote:
 My specs work fine with this in my Gemfile.lock:

 grep rspec Gemfile.lock
 rspec (2.11.0)
   rspec-core (~ 2.11.0)
   rspec-expectations (~ 2.11.0)
   rspec-mocks (~ 2.11.0)
 rspec-core (2.11.0)
 rspec-expectations (2.11.1)
 rspec-mocks (2.11.1)
 rspec-rails (2.11.0)
   rspec (~ 2.11.0)
   rspec-rails (~ 2.11)

 After bundle update rspec, I started to have problems like this when

What's in your Gemfile.lock after you do the upgrade?

 running bundle exec rspec:

  Failure/Error: Unable to find matching line from backtrace
  NoMethodError:
undefined method `cmd_tuples' for nil:NilClass
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/adapters/postgres.rb:191:in
 `execute'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/adapters/postgres.rb:532:in
 `log_connection_execute'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/database/query.rb:547:in
 `rollback_transaction'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/database/query.rb:296:in
 `rescue in _transaction'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/database/query.rb:309:in
 `_transaction'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/database/query.rb:255:in
 `block in transaction'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/database/connecting.rb:229:in
 `block in synchronize'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/connection_pool/threaded.rb:88:in
 `hold'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/database/connecting.rb:229:in
 `synchronize'
  #
 /home/rodrigo/.rvm/gems/ruby-1.9.3-p286@rails/gems/sequel-3.35.0/lib/sequel/database/query.rb:253:in
 `transaction'
  # /home/rodrigo/ecore/src/ruby/matterhorn/spec/spec_helper.rb:51:in
 `block (3 levels) in top (required)'
  ...

 See this spec_helper extract:

 config.around(:each) do |example|
 51:  DB.transaction(savepoint: true, rollback: :always) do
 example.run
   end
 end

 Any idea of what has been changed since the releases I'm using that could be
 causing this?

 Only the first spec is failing. All others are passing.

 I don't have any clue why I can't upgrade RSpec... :(

 ___
 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] How can I create a active-record model w/o depending on the database?

2012-09-23 Thread David Chelimsky
On Sun, Sep 23, 2012 at 7:55 PM, S Ahmed sahmed1...@gmail.com wrote:
 I have a class that takes a class that inherits from activerecord as a
 parameter, e.g.:

 class SomeModel  ActiveRecord::Base
 end

 class MyClass
   attr_accessor :model
   def initialize(model)
 @model = model
   end
 end


 The class MyClass will then iterate over the Models attributes etc.

 Also I will need to know each attributes data type in mysql like: integer,
 boolean, etc.

 So my unit tests shouldnt' rely on the database, but I'm a little confused
 on how I can create stub/mock that will have attributes on it similiar to
 how it would be if I was creating a model and it reading the mysql columns
 as attributes.

 Thoughts on how I can do this w/o actually having to depend on a database
 for my spec tests?

There is a guideline that says Don't mock types you don't own, which
I've just learned was coined by my colleague at DRW, Joe Walnes [1].

In this case, this guideline suggests that you stub/mock MyClass in
tests for the objects that interact with it, thereby isolating _them_
from the database, but that the tests for MyClass itself are allowed
to interact w/ the database through the AR model. This limits your
dependency on AR to MyClass and its tests, so changes to ActiveRecord
and/or decisions to move to a different database abstraction don't fan
out very far.

Make sense?

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


Re: [rspec-users] How can I create a active-record model w/o depending on the database?

2012-09-23 Thread David Chelimsky
On Sun, Sep 23, 2012 at 8:56 PM, S Ahmed sahmed1...@gmail.com wrote:
 Yes, I think I get it.

 The actual class can interact since it is kinda necessary and vital to
 testing int anyhow, but when other classes are depending on MyClass, you can
 stub/mock since they are outside the scope or domain of the MyClass, so they
 shouldn't have to be depending on the dependancies of Myclass.

That's basically it.


 On Sun, Sep 23, 2012 at 8:31 PM, David Chelimsky dchelim...@gmail.com
 wrote:

 On Sun, Sep 23, 2012 at 7:55 PM, S Ahmed sahmed1...@gmail.com wrote:
  I have a class that takes a class that inherits from activerecord as a
  parameter, e.g.:
 
  class SomeModel  ActiveRecord::Base
  end
 
  class MyClass
attr_accessor :model
def initialize(model)
  @model = model
end
  end
 
 
  The class MyClass will then iterate over the Models attributes etc.
 
  Also I will need to know each attributes data type in mysql like:
  integer,
  boolean, etc.
 
  So my unit tests shouldnt' rely on the database, but I'm a little
  confused
  on how I can create stub/mock that will have attributes on it similiar
  to
  how it would be if I was creating a model and it reading the mysql
  columns
  as attributes.
 
  Thoughts on how I can do this w/o actually having to depend on a
  database
  for my spec tests?

 There is a guideline that says Don't mock types you don't own, which
 I've just learned was coined by my colleague at DRW, Joe Walnes [1].

 In this case, this guideline suggests that you stub/mock MyClass in
 tests for the objects that interact with it, thereby isolating _them_
 from the database, but that the tests for MyClass itself are allowed
 to interact w/ the database through the AR model. This limits your
 dependency on AR to MyClass and its tests, so changes to ActiveRecord
 and/or decisions to move to a different database abstraction don't fan
 out very far.

 Make sense?

 Make sense?
 ___
 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
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] how to stop rspec from creating helper/view specs?

2012-09-14 Thread David Chelimsky
On Fri, Sep 14, 2012 at 11:20 AM, S Ahmed sahmed1...@gmail.com wrote:
 I tried adding this to my application.rb:

 config.generators do |g|
   g.view_specs false
   g.helper_specs false
 end

See Customizing your workflow on http://guides.rubyonrails.org/generators.html

According to that, you need to something like this, but I've never
tried it, so if it doesn't work please consult the rails mailing list
(although, do let us know whether it does).

config.generators do |g|
  g.test_framework :rspec, :view_specs = false, :helper_specs = false
end

HTH,
David



 But it didn't stop the generator from creating view/helper specs.

 What am I doing wrong?

 Also also tried doing this the configuration section:

 config.view_specs = false
 config.helper_specs = false


 But it didn't do anything.

 ___
 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 for thor script

2012-09-14 Thread David Chelimsky
On Fri, Sep 14, 2012 at 11:31 AM, ankush m. li...@ruby-forum.com wrote:
 Hello all,
   I recently developed a CLI extending thor API.
 While i was trying to write specs for thor's tasks, I couldn't find any
 way to write the same for tasks with mandatory options or with  options.
 So can anyone please guide me for the same?

I haven't written any myself, but I'd recommend taking a look at
thor's own specs for guidance:
https://github.com/wycats/thor/tree/master/spec

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


Re: [rspec-users] Stub a controller method containing arguments

2012-09-09 Thread David Chelimsky
On Sun, Sep 9, 2012 at 1:00 AM, jeevan reddy li...@ruby-forum.com wrote:
 controller code:

 class BooksController  ApplicationController
   def index
param1, param2 = 123, 456
 @test = method_1(param1, param2)
   end

   private
   def method_1(param1, param2)
 return test
   end
 end

 controller tests

 describe GET index do
   it get books do
 param1, param2 = 12334, 456233
 controller.stub!(:method_1).with(param1,param2).and_return(test)
 get :index
 assert_response :success
 assigns(:test).should eq(test)
   end
 end

 How to stub a controller private method which will take any arguments

In your example above, the values of param1 and param2 are different
in the rspec example and the controller, so I'm guessing you're
getting a failure. If you're constraining a stub with specific args,
they have to match.

Curious - why do you care about the args in your real spec?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Newbie testing questions

2012-09-09 Thread David Chelimsky
On Fri, Sep 7, 2012 at 2:14 PM, Anand K V R. li...@ruby-forum.com wrote:
 Hi Friends.

 I'm an absolute Tester (little experience on development upto college
 level) and had been asked to Test an application developed in Rails. As
 our client selected Rspec, I have no other go.

 Can anyone help me with a basic program in Rspec how to open GMAIL,
 enter username / password , then login.

 Thanks in advance ,

 Aishwarya

Take a look at https://github.com/jnicklas/capybara. Everything you
need is referenced in the README on that page.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] your cuke forum is not opening

2012-09-04 Thread David Chelimsky
On Tue, Sep 4, 2012 at 12:57 AM, Fahim Patel pafa...@gmail.com wrote:
  https://groups.google.com/forum/?fromgroups#!forum/cukes.

 this link is not opening...
 can u give me accurate link...

Try http://groups.google.com/group/cukes
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Thanks

2012-09-01 Thread David Chelimsky
On Sat, Sep 1, 2012 at 6:43 AM, Fahim Patel pafa...@gmail.com wrote:
 Selenium automates web browsers.

 Cucumber automates tests.


 can u please explain this line??

Please read the docs for these tools:

http://cukes.info/
http://seleniumhq.org/

 thanks

 can u give answer on this questions

All of the questions below are about Cucumber. Please post these
questions to https://groups.google.com/forum/?fromgroups#!forum/cukes.


 Q1
 if i have 2 sceanario and 1 background  .
 but i want only 1 scenario should used that backgound  and 2nd  scenario
 dont use that background.


 and i want to run them same time.
 can it is possible ?

 Q2
 What is the diff between Capybara and Webrat?
 Which one is by default configure with cucumber  ?
 If both are providing  same functionality than which one i use?


 Q3
 How to test  view in cucumber ?
  I want to test CSS and body of page(DOM objects) are working perfectly or
 not  ?How to Write in Scenario to test View?


 Q4
 What is this Silenium Framework  ?
 Can i use this for Rails application   ?

 This framework is better than Cucumber for High level testing ?



 ___
 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] Question on Cucumber and siienium

2012-08-31 Thread David Chelimsky
On Fri, Aug 31, 2012 at 10:14 AM, Fahim Patel pafa...@gmail.com wrote:


 Hi all

 I work on Rspec and now i see some more framework which is cucumber and
 silenium
 I have one question..

 Which one is best for high level testing between cucumber and silinium?

 can we use both cucumber and silinium together ?


Selenium automates web browsers.

Cucumber automates tests.

Together, they let you automate tests in web browsers. If that's what
you want to do, they work very well together, but I'd also look at
Capybara, which provides a simpler interface to Selenium (via some
other tools like selenium-web-driver).

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


Re: [rspec-users] Fwd: [Rails] Re: hii friends, , , , , i m new to rails......i think there is a problem in destroy command .

2012-08-22 Thread David Chelimsky
On Wed, Aug 22, 2012 at 12:40 AM, Fahim Patel pafa...@gmail.com wrote:
 friends there is no reply from Rails community.Lots of days are gone.
 can u answer this problem.
 Regards
 Fahim Babar Patel


 -- Forwarded message --
 From: Fahim Patel pafa...@gmail.com
 Date: Fri, Aug 17, 2012 at 10:49 AM
 Subject: [Rails] Re: hii friends,i m new to rails..i think there is
 a problem in destroy command .
 To: rubyonrails-t...@googlegroups.com


 thanks for reply.let me explain 

 there is no such a  testing model present
  rails destroy model testing
   invoke  active_record
   removemigration.rb
   removeapp/models/testing.rb
   invokerspec
   remove  spec/models/testing_spec.rb
   invoke  factory_girl
   removespec/factories/testings.rb


 but it is still removing files.

 one more example
 rails destroy controller testing
   remove  app/controllers/testing_controller.rb
   invoke  erb
   removeapp/views/testing
   invoke  rspec
   removespec/controllers/testing_controller_spec.rb
   invoke  helper
   removeapp/helpers/testing_helper.rb
   invokerspec
   remove  spec/helpers/testing_helper_spec.rb
   invoke  assets
   invokecoffee
   remove  app/assets/javascripts/testing.js.coffee
   invokescss
   remove  app/assets/stylesheets/testing.css.scss

 there is no testing controller prsent.
 this thing is happen with all directory structure
 scaffold also  do the same thing..

 there should be any exception or error ??

 On Thursday, August 16, 2012 10:33:47 AM UTC+5:30, Fahim Patel wrote:

 let me explain this problem 
 ---rails destroythis command
 destroy model,scaffold etc .
 problem is that if a model or other structure is exist than ,this command
 will destroy all the related file to it...good ..till now no
 problem...
 but problem is that if a model etc is not exist than till this command
 remove the file ...it should not be done.there is no such a file name
 exist..
 some error or exception should be execute at this time 

 i think this a problem???
 if not than expalin me..

 Regards
 Fahim Babar Patel

Did you see 
https://groups.google.com/d/msg/rubyonrails-talk/R0A9Oid_I8M/FIO9RzriiXkJ
? I think it answers your question.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] and_raise with a message

2012-08-22 Thread David Chelimsky
On Wed, Aug 22, 2012 at 12:56 AM, Bas Vodde b...@odd-e.com wrote:

 Hiya all,

 I was trying to get and_raise to raise an exception filled with a message and 
 I was struggling with the API for a while (not on the latest RSpec, but 
 assume it didn't change).

 Based on that, I have a suggestion for improvement. My first attempt was to 
 mirror how I use raise, so I tried:

 subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, 
 execution error: System Events got an error: Access for assistive devices is 
 disabled. (-25211))

 This didn't work as the and_raise only has one parameter. Eventually I 
 figured out this works:

 
 subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new 
 (execution error: System Events got an error: Access for assistive devices 
 is disabled. (-25211)))

 And it does what I want it to do. Still… I would have prefered the first one 
 to work too :) Implementing that ought to be reasonably trivial, correct?
 (didn't implement it myself yet this time).

 Comments? Or is there anyone way of doing this?

 Thanks!

 Bas

Documentation here:
http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method.

That has been the API for something like 5 years so I'm not sure I
want to change it. It is used to prepare an exception to raise, not
compare with one that was already raised, so we'd have to support n
args, e.g.

and_raise(AnException, with_one_arg)
and_raise(AnException, with_one_arg, and_another_arg)

etc. I think this would be friendly, but it might also be confusing
because we'd effectively have 2 completely different APIs for the same
method. Also, I'm not sure that either of those examples are much
better than:

and_raise(AnException.new with_one_arg)
and_raise(AnException.new with_one_arg, and_another_arg)

I'm open to the idea though for one reason: the rspec-expectations
raise_exception method can accept 1 or two args, so I can imagine
something like:

describe Foo do
  it raises when x happens do
foo = Foo.new(Bar.new)
expect { Foo.do_something_bad }.to raise_exception(FooException,
with this message)
  end

  it does x when its bar raises do
bar = double
foo = Foo.new(bar)
bar.should_receive(:msg).and_raise(BarException, with this message)
  end
end

Your suggestion makes these two APIs align better if the exception
initializer accepts one argument and raise_exception gets a String.
But raise_exception can also take a regex, and exception initializers
can take more than one arg. Consider: InsufficientFunds.new(50, :USD).
The way things are today, you might see these two near each other
(hopefully not in the same example):

  expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/)
  source_account.should_receive(:withdraw).and_raise(InsufficientFunds.new
50, :USD)

With what you propose it would be this:

  expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/)
  source_account.should_receive(:withdraw).and_raise(InsufficientFunds,
50, :USD)

I think the way it is now tells a better story about what's really
going on (i.e. that you're supplying an initialized object to
and_raise) than the proposed change. But that's one opinion.

Any others out there?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] and_raise with a message

2012-08-22 Thread David Chelimsky
On Wed, Aug 22, 2012 at 6:43 AM, Bas Vodde b...@odd-e.com wrote:

 On 22 Aug, 2012, at 7:25 PM, David Chelimsky dchelim...@gmail.com wrote:

 On Wed, Aug 22, 2012 at 12:56 AM, Bas Vodde b...@odd-e.com wrote:

 Hiya all,

 I was trying to get and_raise to raise an exception filled with a message 
 and I was struggling with the API for a while (not on the latest RSpec, but 
 assume it didn't change).

 Based on that, I have a suggestion for improvement. My first attempt was to 
 mirror how I use raise, so I tried:

subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, 
 execution error: System Events got an error: Access for assistive devices 
 is disabled. (-25211))

 This didn't work as the and_raise only has one parameter. Eventually I 
 figured out this works:


 subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new 
 (execution error: System Events got an error: Access for assistive devices 
 is disabled. (-25211)))

 And it does what I want it to do. Still… I would have prefered the first 
 one to work too :) Implementing that ought to be reasonably trivial, 
 correct?
 (didn't implement it myself yet this time).

 Comments? Or is there anyone way of doing this?

 Thanks!

 Bas

 Documentation here:
 http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method.

 That has been the API for something like 5 years so I'm not sure I
 want to change it. It is used to prepare an exception to raise, not
 compare with one that was already raised, so we'd have to support n
 args, e.g.

 and_raise(AnException, with_one_arg)
 and_raise(AnException, with_one_arg, and_another_arg)

 etc. I think this would be friendly, but it might also be confusing
 because we'd effectively have 2 completely different APIs for the same
 method. Also, I'm not sure that either of those examples are much
 better than:

 and_raise(AnException.new with_one_arg)
 and_raise(AnException.new with_one_arg, and_another_arg)

 I'm open to the idea though for one reason: the rspec-expectations
 raise_exception method can accept 1 or two args, so I can imagine
 something like:

 describe Foo do
  it raises when x happens do
foo = Foo.new(Bar.new)
expect { Foo.do_something_bad }.to raise_exception(FooException,
 with this message)
  end

  it does x when its bar raises do
bar = double
foo = Foo.new(bar)
bar.should_receive(:msg).and_raise(BarException, with this message)
  end
 end

 Your suggestion makes these two APIs align better if the exception
 initializer accepts one argument and raise_exception gets a String.
 But raise_exception can also take a regex, and exception initializers
 can take more than one arg. Consider: InsufficientFunds.new(50, :USD).
 The way things are today, you might see these two near each other
 (hopefully not in the same example):

  expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/)
  source_account.should_receive(:withdraw).and_raise(InsufficientFunds.new
 50, :USD)

 With what you propose it would be this:

  expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/)
  source_account.should_receive(:withdraw).and_raise(InsufficientFunds,
 50, :USD)

 I think the way it is now tells a better story about what's really
 going on (i.e. that you're supplying an initialized object to
 and_raise) than the proposed change. But that's one opinion.

 Any others out there?

 Hi David,

 My main thinking was to make it consistent with the Kernel.raise.

 Like, in my production code, I have:

 raise Osaka::SystemCommandFailed, output_message

 so, it would make sense to the mock to work the same with:

 and_raise Osaka::SystemCommandFailed, Fake output message

 I figured it would be a relative minor change as it would add one extra 
 parameter which could default to an empty string.
 (as reference, see Kernel raise: 
 http://www.ruby-doc.org/core-1.9.3/Kernel.html)

 I had not considered the consistency with and_raise_exception, but I just 
 noticed that this was one of the cases where my default excepted behavior 
 from RSpec was different from what the API wanted. Therefore, I had to dive 
 in the RSpec doc to see how I could pass the message….

 Bas

Unfortunately, the Kernel#raise API also accepts a 3rd argument, which
is an Array of caller information (the backtrace):
http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-raise.

What that doc doesn't tell you is that the first arg can actually be
an initialized exception:

  raise InsufficientFunds.new(49, :USD)

I can't remember where I heard this but there was some advice from a
respected software developer that said something like APIs should be
loose with what they accept and strict with what they return. Based
on that advice, we should support your suggestion. It's not like if
you use one API or the other you're going to get a different result.
Beginning to lean in favor.

More opinions

Re: [rspec-users] and_raise with a message

2012-08-22 Thread David Chelimsky
On Wed, Aug 22, 2012 at 6:55 AM, David Chelimsky dchelim...@gmail.com wrote:
 On Wed, Aug 22, 2012 at 6:43 AM, Bas Vodde b...@odd-e.com wrote:

 On 22 Aug, 2012, at 7:25 PM, David Chelimsky dchelim...@gmail.com wrote:

 On Wed, Aug 22, 2012 at 12:56 AM, Bas Vodde b...@odd-e.com wrote:

 Hiya all,

 I was trying to get and_raise to raise an exception filled with a message 
 and I was struggling with the API for a while (not on the latest RSpec, 
 but assume it didn't change).

 Based on that, I have a suggestion for improvement. My first attempt was 
 to mirror how I use raise, so I tried:


 subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, 
 execution error: System Events got an error: Access for assistive devices 
 is disabled. (-25211))

 This didn't work as the and_raise only has one parameter. Eventually I 
 figured out this works:


 subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new
  (execution error: System Events got an error: Access for assistive 
 devices is disabled. (-25211)))

 And it does what I want it to do. Still… I would have prefered the first 
 one to work too :) Implementing that ought to be reasonably trivial, 
 correct?
 (didn't implement it myself yet this time).

 Comments? Or is there anyone way of doing this?

 Thanks!

 Bas

 Documentation here:
 http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method.

 That has been the API for something like 5 years so I'm not sure I
 want to change it. It is used to prepare an exception to raise, not
 compare with one that was already raised, so we'd have to support n
 args, e.g.

 and_raise(AnException, with_one_arg)
 and_raise(AnException, with_one_arg, and_another_arg)

 etc. I think this would be friendly, but it might also be confusing
 because we'd effectively have 2 completely different APIs for the same
 method. Also, I'm not sure that either of those examples are much
 better than:

 and_raise(AnException.new with_one_arg)
 and_raise(AnException.new with_one_arg, and_another_arg)

 I'm open to the idea though for one reason: the rspec-expectations
 raise_exception method can accept 1 or two args, so I can imagine
 something like:

 describe Foo do
  it raises when x happens do
foo = Foo.new(Bar.new)
expect { Foo.do_something_bad }.to raise_exception(FooException,
 with this message)
  end

  it does x when its bar raises do
bar = double
foo = Foo.new(bar)
bar.should_receive(:msg).and_raise(BarException, with this message)
  end
 end

 Your suggestion makes these two APIs align better if the exception
 initializer accepts one argument and raise_exception gets a String.
 But raise_exception can also take a regex, and exception initializers
 can take more than one arg. Consider: InsufficientFunds.new(50, :USD).
 The way things are today, you might see these two near each other
 (hopefully not in the same example):

  expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/)
  source_account.should_receive(:withdraw).and_raise(InsufficientFunds.new
 50, :USD)

 With what you propose it would be this:

  expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/)
  source_account.should_receive(:withdraw).and_raise(InsufficientFunds,
 50, :USD)

 I think the way it is now tells a better story about what's really
 going on (i.e. that you're supplying an initialized object to
 and_raise) than the proposed change. But that's one opinion.

 Any others out there?

 Hi David,

 My main thinking was to make it consistent with the Kernel.raise.

 Like, in my production code, I have:

 raise Osaka::SystemCommandFailed, output_message

 so, it would make sense to the mock to work the same with:

 and_raise Osaka::SystemCommandFailed, Fake output message

 I figured it would be a relative minor change as it would add one extra 
 parameter which could default to an empty string.
 (as reference, see Kernel raise: 
 http://www.ruby-doc.org/core-1.9.3/Kernel.html)

 I had not considered the consistency with and_raise_exception, but I just 
 noticed that this was one of the cases where my default excepted behavior 
 from RSpec was different from what the API wanted. Therefore, I had to dive 
 in the RSpec doc to see how I could pass the message….

 Bas

 Unfortunately, the Kernel#raise API also accepts a 3rd argument, which
 is an Array of caller information (the backtrace):
 http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-raise.

 What that doc doesn't tell you is that the first arg can actually be
 an initialized exception:

   raise InsufficientFunds.new(49, :USD)

 I can't remember where I heard this but there was some advice from a
 respected software developer that said something like APIs should be
 loose with what they accept and strict with what they return. Based
 on that advice, we should support your suggestion. It's not like if
 you use one API or the other you're going to get

Re: [rspec-users] How do I specify that a class does not receive any message

2012-08-22 Thread David Chelimsky
On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger m...@jbrains.ca wrote:
 On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde b...@odd-e.com wrote:


 JB is right.

 Sometimes, for clarity, it is useful to add should_not, but for
 functionality it is usually not needed.


 I know JMock has never() for this people. Should RSpec-mocks have something
 like object.should_receive(:nothing).

never() is not a catch all for _all_ messages. It is for a specific
message, just like it is in rspec-mocks

  # rspec
  object.should_receive(:msg).never

  #jmock
  never(object).msg()




 --
 J. B. (Joe) Rainsberger :: http://www.jbrains.ca ::
 http://blog.thecodewhisperer.com
 Author, JUnit Recipes
 Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.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] How do I specify that a class does not receive any message

2012-08-22 Thread David Chelimsky
On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger m...@jbrains.ca wrote:
 On Wed, Aug 22, 2012 at 10:07 AM, David Chelimsky dchelim...@gmail.com
 wrote:

 On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger m...@jbrains.ca wrote:
  On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde b...@odd-e.com wrote:
 
 
  JB is right.
 
  Sometimes, for clarity, it is useful to add should_not, but for
  functionality it is usually not needed.
 
 
  I know JMock has never() for this people. Should RSpec-mocks have
  something
  like object.should_receive(:nothing).

 never() is not a catch all for _all_ messages. It is for a specific
 message, just like it is in rspec-mocks

   # rspec
   object.should_receive(:msg).never

   #jmock
   never(object).msg()


 In JMock, you can write this:

 never(object);

 and this means never anything. Just like

 ignoring(object);
 allowing(object);

 which each equate to mock().as_null_object().

Perhaps it goes without saying, but I was not aware of that ;)

As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock
instances (returned by double(), mock(), or stub()) are strict by
default - e.g. they'll complain about any unexpected messages.
Obviously that does not account for any real objects.

I'm open to adding an API for this, but not
object.should_receive(:nothing) since that syntax is for declaring
expected messages.

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


Re: [rspec-users] error

2012-08-16 Thread David Chelimsky
On Thu, Aug 16, 2012 at 1:06 AM, Fahim Patel pafa...@gmail.com wrote:
 let me explain this problem 
 ---rails destroy

Please post questions about Rails to the Rails mailing list:
https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-talk
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Specing a method that returns a lambda

2012-08-11 Thread David Chelimsky
On Fri, Aug 10, 2012 at 8:22 AM, Iain Barnett iainsp...@gmail.com wrote:
 Hello,

 I have a class that takes callbacks and stores them for later use. It 
 supplies a default block for all the other methods to use, and you can set a 
 new default if you like. I want to check that the new default is being set 
 and that it's the same block as the one given. When I try and spec this, 
 however, I get the following message:

 When you call a matcher in an example without a String, like this:

   specify { object.should matcher }

   or this:

   it { should matcher }

or this:

specify { expect(object).to matcher

w000t!


   RSpec expects the matcher to have a #description method. You should either
   add a String to the example this matcher is being used in, or give it a
   description method. Then you won't have to suffer this lengthy warning 
 again.


 The code is as like this:

   DEFAULT_BLOCK = -(klass,field){
 -(term) {
   klass.filter(field.to_sym = 
 /#{term}.*/i).select(Sequel.as(field,value))
 }
   }


   def default_suggester=(block)
 @default_block = block
   end


   def default_suggester
 @default_block ||= DEFAULT_BLOCK
   end


 and the spec I had that gave that message:

 describe Adding a default suggester do
   include_context All pages # this loads the Sinatra app the code runs 
 in and puts it in a variable called app.
   let(:my_default) { -(klass,field) {
   -(term) {
 klass.filter(
   Sequel.like(field.to_sym, #{term}%)
 ).select(Sequel.as(field,value))
   }
 }
   }

   context When given a new default suggester do
 before :all do
   app.suggesters.clear
   app.default_suggester = my_default
 end
 it should be a lambda/proc do
   app.default_suggester.should respond_to? :call
 end
 it should be the same as my_default do
   app.default_suggester.should.equal? my_default
 end
 after :all do
   app.suggesters.clear
 end
   end
 end

 It appears to me that because it's a lambda that RSpec thinks it's a matcher? 
 Is there a way to change this to do what I intend?

That sounds like a red herring, but I'm not sure.


 Any suggestions or help would be much appreciated. I'm running Ruby 
 v1.9.3-p194 and RSpec 2.11.0

My guess is that it's related to the context being included and the
fact that you're using before :all. Try it with before :each and see
if that works. If not, please run the spec with the --backtrace flag
and post the full backtrace, along with the code in the included
context.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] should_receive with block or proc?

2012-08-06 Thread David Chelimsky
On Mon, Aug 6, 2012 at 3:48 AM, Alexander Baronec abo...@gmail.com wrote:
 2012/8/5 David Chelimsky dchelim...@gmail.com

 On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec abo...@gmail.com
 wrote:
  Hello.
  How can I test object to receive message and compare arguments of this
  message with value evaluated at present time? It is possible?
 
  For example:
 
  should_receive(:api_send).with( - { players.count } ) And players.count
  will be called and evaluated only when api_send is received.

 Look at Fake Implementation on
 https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs.
 You can do the same thing w/ should_receive, e.g.

 foo.should_receive(:api_send) do |player_count|
   player_count.should eq players.count
 end

 HTH,
 David

 It don't work when object received few messages. I described it there:
 http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages

should_receive, by default, expects exactly one call, but there are a
number of ways for you to specify more than one call. One possibility
would be:

foo.should_receive(:api_send).ordered
foo.should_receive(:api_send).with(2).ordered

See http://rubydoc.info/gems/rspec-mocks for more info
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] should_receive with block or proc?

2012-08-06 Thread David Chelimsky
On Mon, Aug 6, 2012 at 9:21 AM, Alexander Baronec abo...@gmail.com wrote:
 2012/8/6 David Chelimsky dchelim...@gmail.com

 On Mon, Aug 6, 2012 at 3:48 AM, Alexander Baronec abo...@gmail.com
 wrote:
  2012/8/5 David Chelimsky dchelim...@gmail.com
 
  On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec abo...@gmail.com
  wrote:
   Hello.
   How can I test object to receive message and compare arguments of
   this
   message with value evaluated at present time? It is possible?
  
   For example:
  
   should_receive(:api_send).with( - { players.count } ) And
   players.count
   will be called and evaluated only when api_send is received.
 
  Look at Fake Implementation on
  https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs.
  You can do the same thing w/ should_receive, e.g.
 
  foo.should_receive(:api_send) do |player_count|
player_count.should eq players.count
  end
 
  HTH,
  David

  It don't work when object received few messages. I described it there:
 
  http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages

 should_receive, by default, expects exactly one call, but there are a
 number of ways for you to specify more than one call. One possibility
 would be:

 foo.should_receive(:api_send).ordered
 foo.should_receive(:api_send).with(2).ordered

 See http://rubydoc.info/gems/rspec-mocks for more info

 I wan't to test order of received messages. I want to test only one message
 of few and compare it with real-time value.
 It's not possible?

It is, but you have to specify which time it should care if you're
going to compare it to a real time value.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] should_receive with block or proc?

2012-08-05 Thread David Chelimsky
On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec abo...@gmail.com wrote:
 Hello.
 How can I test object to receive message and compare arguments of this
 message with value evaluated at present time? It is possible?

 For example:

 should_receive(:api_send).with( - { players.count } ) And players.count
 will be called and evaluated only when api_send is received.

Look at Fake Implementation on
https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs.
You can do the same thing w/ should_receive, e.g.

foo.should_receive(:api_send) do |player_count|
  player_count.should eq players.count
end

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


Re: [rspec-users] Mock_model not recognizing act_as_mappable

2012-08-03 Thread David Chelimsky
On Fri, Aug 3, 2012 at 9:33 AM, Steve Loo isig...@gmail.com wrote:
 I am using mock_model in my tests, and I encountered a situation where my
 stub is failing.

You want stub_model for this case because you're counting on
functionality that is built into your real model.

See https://www.relishapp.com/rspec/rspec-rails/docs/mocks/mock-model
and https://www.relishapp.com/rspec/rspec-rails/docs/mocks/stub-model
for more info.

 Here's the scenario:

 Controller:

@locations = Location.al(:bounds=bounds)l

@locations.sort_by_distance_from([bounds.center.lat,bounds.center.lng])


 Rspec:

  @location = mock_model(Location)

  Location.stub(:all).and_return([@location])

  @location.stub!(:sort_by_distance_from).and_return([@location])


 Within real model: Location

act_as_mappable




 the :sort_by_distance_from  is a method from within act_as_mappable.

 Upon investigation, when I compare the available methods for both the
 Location model and the mock_model, I found act_as_mappable is missing from
 the mock_model.

 Which accounts for why it was failing in the stub
 @location.stub!(:sort_by_distance_from). It gives an error unexpected
 message :distance_to and the :distance_to method comes from
 act_as_mappable.


 When I switch to using Factory for the @location instance, the test passed.

 How should I go about using the mock_model for a situation as this, without
 resorting to using Factory? I believe this issue also the same for other
 act_as_ situations because I also noted that a number of my act_as.. are not
 available in the mock_model as they are in the actual model.


 Thanks for the help

 Steve


 ___
 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] config.before(:each) is not run after let! ?

2012-08-02 Thread David Chelimsky
On Thu, Aug 2, 2012 at 4:24 PM, Patrick J. Collins
patr...@collinatorstudios.com wrote:
 I have a model with an observer that emails out upon creation, and I
 want to do some testing of emails that get generated via various
 actions...  So I was hoping I could do:

 # spec_helper.rb

 config.before(:each) do
   ActionMailer::base.deliveries.clear
 end

 # my_phat_observer_spec.rb

 let!(:yo_momma) { create_yo_momma }

 describe after_update do
   it sends an email when it knows your daddy do
 expect { yo_momma.update_attribute(:daddy = create_daddy) }.to
 change(ActionMailer::Base, :deliveries).by(1)
   end
 end

 ...


 However, inside that example group, ActionMailer::Base.deliveries is 
 populated from the create_yo_momma
 method-- before the expectation is even declared.

 Is there a way to make a config.before(:each) that actually runs as the
 *LAST* before callback prior to the actual example group?

let! adds a before hook and before hooks get run in the order they're
declared, so just declare them in the other order:

let!(:yo_momma) { create_yo_momma }
config.before(:each) do
  ActionMailer::base.deliveries.clear
end

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


Re: [rspec-users] config.before(:each) is not run after let! ?

2012-08-02 Thread David Chelimsky
On Thu, Aug 2, 2012 at 6:29 PM, Patrick J. Collins
patr...@collinatorstudios.com wrote:
 let! adds a before hook and before hooks get run in the order they're
 declared, so just declare them in the other order:

 let!(:yo_momma) { create_yo_momma }
 config.before(:each) do
   ActionMailer::base.deliveries.clear
 end

 Hmm.. The way that I usually work is that my lets are specific to a
 spec...

 # some_spec.rb

 let!(:xyz) { XYZ }

 # some_other_spec.rb

 let!(:foo) { foobar! }

 ...

 So, my goal is to not have to clutter my actual spec files with things
 like ActionMailer::Base.deliveries.clear ...  That's something that I
 want to always assure is blank at the beginning of an example regardless
 of the what spec file I am running.

 I was hoping there was some way to change the order of hook execution,
 and make the stuff in spec_helper happen last...

Nope. Global befores will always run before the ones declared locally.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] rspec-rails does not have a matcher for assert_generates

2012-07-26 Thread David Chelimsky
On Thu, Jul 26, 2012 at 6:07 AM, deepak kannan kannan.dee...@gmail.com wrote:
 hi,

 rails minitest has assertions for assert_generates, assert_recognizes and
 assert_routing

 rpsec's routes_to delegates to assert_recognizes
 http://rubydoc.info/gems/rspec-rails/frames

 But there is no mention of assert_generates
 http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_generates

 why does rspec-rails not have a matcher for assert_generates ?

I never found assert_generates useful for the way I approach testing.
If you give me an example of how/when you'd use it I can try to
explain.

 i can of-course call 'assert_generates' from rspec

 --
 best,
 deepak

 ___
 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] A recently observed anti pattern: commented out tests

2012-07-26 Thread David Chelimsky
On Thu, Jul 26, 2012 at 4:06 PM, James Cox ja...@imaj.es wrote:
  so yes, pending is ok, but a second keyword broken might be nicer,
  which would act the same but output different info.

 You can actually do that!

 RSpec.configuration do |c|
   c.alias_example_to :broken, :pending = Broken
 end

 See
 http://rubydoc.info/gems/rspec-core/RSpec/Core/ExampleGroup.alias_example_to
 and
 https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/example_group.rb#L69-104


 David, i'm going to give that a go - see how it shakes out in real-world
 use. It might work to visually make it distinguishable enough to process. :)
 thanks.

Cool. Please report back if you learn anything interesting.

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


Re: [rspec-users] A recently observed anti pattern: commented out tests

2012-07-26 Thread David Chelimsky
On Thu, Jul 26, 2012 at 4:08 PM, James Cox ja...@imaj.es wrote:
 Chris,

 On Tue, Jul 24, 2012 at 4:54 PM, Chris Flipse cfli...@gmail.com wrote:



 On Tue, Jul 24, 2012 at 1:55 PM, James Cox ja...@imaj.es wrote:

 so yes, pending is ok, but a second keyword broken might be nicer,
 which would act the same but output different info.--


 There is a block form of pending.  It actually executes the contents of
 the block, but outputs as a pending test -- unless the test passes, in which
 case it fails with a differing message:

   it is a broken test that I need to fix sometime do
 pending(broke on nonesuch upgrade) {
   domain.do_failing_thing
 }
   end

 So,  that shows up in test output just like every other pending note.
 Whenever someone gets around to fixing whatever failed, the contents of the
 block start passing -- and the test will fail.  The failure is a signal to
 remove the pending block from around the test.

 This may not be as helpful as you like, if it's drowning in a sea of true
 pending tests ... but I feel that leaving unimplemented, pending tests in
 the suite for a long time is a Bad Thing -- precisely because you loose
 useful information like this.


 One of the examples i've found for commented out tests is when the code
 plainly doesn't work. Wouldn't it also fail (and output a backtrace) in this
 instance, therefore thoroughly confusing whoever is observing the test
 output? I do like the idea of this though: pend it until it passes, and then
 fail because you should check it, but … i dont' imagine that it'd really
 work that way.

No - this form passes if there is either an error or a failed
expectation (which is also an error, but internal to rspec). It will
only fail when the code works without event. This means that if the
code doesn't actually do anything it all, it will fail, but that never
happens in practice in my experience.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] A recently observed anti pattern: commented out tests

2012-07-25 Thread David Chelimsky
On Tue, Jul 24, 2012 at 1:55 PM, James Cox ja...@imaj.es wrote:
 Yeah, I love pending too. but it doesn't help me get a sense of the
 state of a suite before I start. now it's part of my practice to go in
 and find out how much is commented out.

 David,

 three concerns with pending as an option:

 a. it won't help the people who think it's ok to comment out whole
 tests. If you make that choice it's not a good thing (™). I don't
 think there's enough evangelism in the world to change them.

Those same people will work around whatever we make available to help them.

 b. how do you distinguish between a pending and a broken-but-fixing
 test? one means, i've got no coverage here, and i haven't thought
 about it' whereas the other says, 'i used to have coverage, and i need
 to fix it'. I know it's semantics, but that's important here: i need
 to know where no effort for testing has been made vs where testing
 existed (which may imply some domain knowledge which was at one point
 true).

What Chris Flipse said.

 c. if you see # it 'should …' or similar, that's a commented test, not
 a test comment. This metric is always going to be loose… but it may
 give an indication, a sniff test. some kind of idea of what the state
 of a test is. It's the same as running rake stats - you and I know
 it's a bullshit metric (it can't possibly tell me how good the tests
 are), but it tells me at least if any effort to test has happened.
 Then, I run coverage and figure out how exercised the code is..
 somewhere along that line, it'd be good to know if there used to be
 tests but they are commented out.

it is an alias for example, specify, and pending (among others), so
we'd have to parse for all of those.

 an anecdote… i experienced this recently with a project, and a
 significant majority of the tests were just commented out. They used
 to work, and a lot of it modeled the domain reasonably well - but
 either due to a breaking gem upgrade or a refactor or something - the
 original dev just didn't move/fix the test. So, on the face of it, the
 test scenario looked horrible, but in the end, for the key components,
 fixing the tests wasn't that painful. Regardless, I got a pretty fast
 sense of how much water he was treading at the time (or, how much he
 was under it :/)

 so yes, pending is ok, but a second keyword broken might be nicer,
 which would act the same but output different info.

You can actually do that!

RSpec.configuration do |c|
  c.alias_example_to :broken, :pending = Broken
end

See http://rubydoc.info/gems/rspec-core/RSpec/Core/ExampleGroup.alias_example_to
and 
https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/example_group.rb#L69-104

HTH,
David


 -james

 On Mon, Jul 23, 2012 at 10:58 PM, Adam Sroka adam.sr...@gmail.com wrote:
 I haven't posted in a while, but I want to say that as someone who spends a
 significant portion of his time teaching (T/B)DD I am totally in love with
 pending specs. There are analogous concepts in nearly every xUnit/xSpec, but
 pending is by far the best. Kudos.

 On Jul 23, 2012 9:57 PM, David Chelimsky dchelim...@gmail.com wrote:

 On Mon, Jul 23, 2012 at 11:19 AM, James Cox ja...@imaj.es wrote:
  Hey,
 
  in a bunch of the rescues i've recently done, I see a pretty big anti
  pattern: tests don't work, and so rather than making them work, the
  dev team just comments them out till 'later'.
 
  Does anyone think it'd be useful/interesting to get a flag for rspec
  which would compare lines vs lines-commented, and if the percentage
  was higher than xx, it'd issue some kind of warning?

 The pending feature is designed to help with this problem by allowing
 you to disable an example while still keeping it visible.

 If we were to do what you propose, we'd need to offer an opt-out
 and/or the ability to configure the percentage. Consider a suite that
 uses a lot of comments to annotate the specs. The problem with making
 it configurable is that the folks who's priorities lead them to
 comment out examples instead of fixing them will likely just disable
 this feature.

 I'd say, let's encourage people to use 'pending' correctly. WDYT?

 Cheers,
 David
 ___
 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



 --
 James Cox,
 Consultant, Raconteur, Photographer, Entrepreneur
 t: +1 347 433 0567  e: ja...@imaj.es w: http://imaj.es/
 talk: http://twitter.com/imajes photos: http://500px.com/imajes
 ___
 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] Issue when testing ActiveRecord after_commit callbacks

2012-06-28 Thread David Chelimsky
On Thu, Jun 28, 2012 at 2:11 PM, Dennis Kuczynski
dennis.kuczyn...@gmail.com wrote:
 In an ActiveRecord model, I have an after_commit callback (:enqueue_job)
 which places a job on my background processing queue (Sidekiq)

 To test that the callback was firing when the database transaction
 was committed, I was using:

 object.should_receive(:enqueue_job) #should pass

 Which seems to work.  However, to test that the test was valid, I attempted

 object.should_not_receive(:enqueue_job) #should fail

 But this did not fail.

 I tracked this down to ActiveRecord's
 DatabaseStatements' commit_transaction_records method, which ends up eating
 the RSpec Negative Method Expectation Exception (which fails fast)
 https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb

 If the negative method expectation did not fail fast, the test would
 probably work, but is there a better pattern for testing after_commit logic?

 (This was with rspec-mocks 2.10.1.  use_transactional_fixtures was turned
 off to enable the callback.)

 Thanks,
 Dennis

Nice work finding the source of the problem. I guess you could do
something like this:

received = false
obj.stub(:enqueue_job) do |*|
  received = true
end
# ...
received.should be_true

It ain't pretty, but it should work (should fail properly if you say
`received.should be_false`).

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


Re: [rspec-users] Rails 3.2 initializers not running when running Rspec without Spork

2012-06-25 Thread David Chelimsky
On Mon, Jun 25, 2012 at 6:07 PM, Avi Tzurel a...@kensodev.com wrote:
 Hi,

 We upgraded our app from 3.0.9 to 3.2.5.
 Latest Rspec version running of course.

 When I run rspec command, I get uninitialized constant error.
 The constant that Rspec is alerting on is in the initializers class.

 it seems that Rspec is not running the Rails initializers.
 Anyone else had/know this problem?

 Any info I can give to better pin point the problem?

 my spec_helper file is just a regular spec_helper out of the box with some
 config additions, I removed the entire spork section from there.

Please make helping you easier by posting actual code and actual error messages.

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


Re: [rspec-users] Rails 3.2 initializers not running when running Rspec without Spork

2012-06-25 Thread David Chelimsky
On Mon, Jun 25, 2012 at 6:49 PM, Avi Tzurel a...@kensodev.com wrote:
 Problem solved (although I am not sure where the bug is and if it's a bug).

 the initializers folder had modules defined in it (Facebook, Web).
 Those modules were not loading with Rails when Rspec was loading the
 environment and were not defined as modules in the constants.

 When I moved those modules to the lib folder (where they should have been in
 the first place), rspec ran with no problem at all.

Glad you fixed the problem. In terms of the diff behavior, this is
just a guess, but it sounds like between 3.0.9 and 3.2.5 Rails stopped
including config/initializers in the autoload paths in the test
environment. If that's the case, and you want them loaded, you can
always do it yourself in config/environments/test.rb.

Cheers,
David





 --
 Sincerely,
 Avi Tzurel


 English blog: http://www.kensodev.com
 Hebrew Blog: http://he.kensodev.com

 On Tuesday, June 26, 2012 at 1:30 AM, Avi Tzurel wrote:

 Sure, no problem

 here's the error message
 https://gist.github.com/2991793

 This is my spec_helper file
 https://gist.github.com/2991803

 The class that is missing is Web which actually does exist in initializers
 https://gist.github.com/2991809

 --
 Sincerely,
 Avi Tzurel

 English blog: http://www.kensodev.com
 Hebrew Blog: http://he.kensodev.com

 On Tuesday, June 26, 2012 at 1:25 AM, David Chelimsky wrote:

 On Mon, Jun 25, 2012 at 6:07 PM, Avi Tzurel a...@kensodev.com wrote:

 Hi,

 We upgraded our app from 3.0.9 to 3.2.5.
 Latest Rspec version running of course.

 When I run rspec command, I get uninitialized constant error.
 The constant that Rspec is alerting on is in the initializers class.

 it seems that Rspec is not running the Rails initializers.
 Anyone else had/know this problem?

 Any info I can give to better pin point the problem?

 my spec_helper file is just a regular spec_helper out of the box with some
 config additions, I removed the entire spork section from there.


 Please make helping you easier by posting actual code and actual error
 messages.

 Cheers,
 David
 ___
 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
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] An open source project with very good use of Cucumber?

2012-06-22 Thread David Chelimsky
On Fri, Jun 22, 2012 at 4:34 AM, Joshua Muheim li...@ruby-forum.com wrote:
 Hey everybody

 I came here through the RSpec Book, so I grant myself to ask something
 about Cucumber here. ;)

You can ask, but you'll probably have a more well versed
Cucumber-using audience on the Cucumber list:

https://groups.google.com/forum/?fromgroups#!forum/cukes

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


Re: [rspec-users] response.should have_content(1 movie) does not seem to work for me

2012-06-22 Thread David Chelimsky
On Fri, Jun 22, 2012 at 4:36 AM, Joshua Muheim li...@ruby-forum.com wrote:
 It seems I have to use

 page.should have_content(...)

 instead of

 response.should have_content(...)

 Maybe that's because Capybara is the default engine now and not Webrat?

While Capybara seems to have become the de facto standard, there is no
default (you have to configure one or the other in your app).


 --
 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] shared examples with controllers + included modules?

2012-06-19 Thread David Chelimsky
On Tue, Jun 19, 2012 at 12:16 AM, Patrick J. Collins
patr...@collinatorstudios.com wrote:
 Hi everyone,

 I ran into a little problem this evening and couldn't quite figure out
 how to solve it...

snip/
 So, then I had a controller test like:

 describe FooController do
  it_behaves_like omg, subject
 end

 ...

 shared_example omg do |obj|
snip/

  it gets something do
    Something.stubs(:new).returns lol
    get :show
    obj.something.should == lol
  end
 end

 .

 So this failed, and I saw-- ok-- subject apparently isn't a real
 instance of the controller outside of an it block..  It's a proc
 of some kind, and I didn't know what to do with it-- so I changed my
 test code slightly:

 describe FooController do
  it_behaves_like omg, FooController.new
 end

 ... and I got a failure, and upon inspecting, I found that in side the
 context of the shared examples, the obj variable was not the same
 controller instance as the one performing the get :show...  So
 obj.something never equalled lol, because it never got its setter
 method called..

 So I said to mself: 

 and thought I'd ask here:

 How can I refernence the real subject link this inside a shared example?

Assuming this is a controller spec, you can reference the controller
via the `controller` method (courtesy of
ActionController::TestCase::Behavior [1][2][3]):

shared_examples omg do
  it gets something do
Something.stubs(:new).returns lol
get :show
controller.something.should == lol
  end
end

describe FooController do
  it_behaves_like omg
end

HTH,
David

[1] 
https://github.com/rspec/rspec-rails/blob/9abdc0a588a78d3cd50bb58ce719ce72f9af34e1/lib/rspec/rails/example/controller_example_group.rb#L9
[2] 
https://github.com/rspec/rspec-rails/blob/9abdc0a588a78d3cd50bb58ce719ce72f9af34e1/lib/rspec/rails/example/controller_example_group.rb#L77
[3] 
https://github.com/rails/rails/blob/c1b1956a15d3d38d0a4504e168bb69638d71e536/actionpack/lib/action_controller/test_case.rb#L508
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] it blocks not executing

2012-06-09 Thread David Chelimsky
On Thu, Jun 7, 2012 at 11:51 AM, Robbie Leib rob...@onthecity.org wrote:
 *
 *
 rspec.rake
 *
 *

 gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f = 1.9

This might be the problem right here. Are you running in Ruby 1.9 and
do you have test-unit-1.2.3 installed?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Rspec include paths

2012-06-08 Thread David Chelimsky
On Fri, Jun 8, 2012 at 4:03 PM, Michael Madrid li...@ruby-forum.com wrote:
 'm using rspec 2.10 with Rails 3.2.1 and have problems with classes not
 being found.

 I have put a class called DbTasks under a dir app/util. Under spec, i've
 created file util/db_tasks_spec.rb which runs afer i included the line:

 require File.join(File.dirname(FILE), '../../app/util/db_tasks')

 However, rspec now isn't able to find my models. I don't want to have to
 include these manually. Is there a way to config rspecs paths so
 everything gets found?

Add 'app/util' to config.autoload_paths in config/application.rb.
That's where it belongs (not in your rspec config).
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Slow Focus tags

2012-06-07 Thread David Chelimsky
On Thu, Jun 7, 2012 at 4:00 AM, Rainer Kuhn rai...@incutio.com wrote:
 I narrowed it down to three things, the first one might be interesting to
 you, the other ones are my problem, although probably common among lots of
 projects:

 Since we don't mock we usually need a bit of test data prepared for each
 test. At first we used factories, but setting things up every time took way
 to long. So I went for fixture builder instead.
 (http://pivotallabs.com/users/georg/blog/articles/1864-fixture-builder-and-rspec-acceptance)
 It was an immediate improvement, although not a great one, since we have a
 generic setup_test_data method that runs before most tests and loads from
 the database into instance variables.

 1) config.global_fixtures = :all
 With this line in, the execution of a single focused spec jumps up to a
 minute. My unresearched guess is that it might load the fixtures for each
 spec, although it won't even be executed.

Would you please check log/test.log to verify this?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Slow Focus tags

2012-06-07 Thread David Chelimsky
On Thu, Jun 7, 2012 at 5:54 AM, David Chelimsky dchelim...@gmail.com wrote:
 On Thu, Jun 7, 2012 at 4:00 AM, Rainer Kuhn rai...@incutio.com wrote:
 I narrowed it down to three things, the first one might be interesting to
 you, the other ones are my problem, although probably common among lots of
 projects:

 Since we don't mock we usually need a bit of test data prepared for each
 test. At first we used factories, but setting things up every time took way
 to long. So I went for fixture builder instead.
 (http://pivotallabs.com/users/georg/blog/articles/1864-fixture-builder-and-rspec-acceptance)
 It was an immediate improvement, although not a great one, since we have a
 generic setup_test_data method that runs before most tests and loads from
 the database into instance variables.

 1) config.global_fixtures = :all
 With this line in, the execution of a single focused spec jumps up to a
 minute. My unresearched guess is that it might load the fixtures for each
 spec, although it won't even be executed.

 Would you please check log/test.log to verify this?

Actually I went ahead and checked this myself and what I see is that
it only creates fixtures before each spec that is run. If you run one,
it happens once ... 2, twice, etc.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Slow Focus tags

2012-06-07 Thread David Chelimsky
On Thu, Jun 7, 2012 at 6:17 AM, Rainer Kuhn rai...@incutio.com wrote:
 My guess was wrong, it can't seem to handle empty fixtures yml files. The
 gist contains only a brief snippets of the actual log, but you can see that
 it's trying to load fixtures from multiple specs

 https://gist.github.com/2888253

 cat event_critical_errors.yml
 --- {}

 Users/rainer/work/app_path/spec/controllers/accounts_controller_spec.rb:3:in
 `top (required)'
 Unable to load event_critical_error, underlying cause No such file to load
 -- event_critical_error

 /Users/rainer/work/carrier-pigeon/spec/requests/suppressed_emails_spec.rb:3:in
 `top (required)'
 Unable to load event_critical_error, underlying cause No such file to load
 -- event_critical_error

That's happening in Rails. Would you please report this to
http://github.com/rails/rails/issues?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Slow Focus tags

2012-06-07 Thread David Chelimsky
On Thu, Jun 7, 2012 at 6:26 AM, Rainer Kuhn rai...@incutio.com wrote:
 I guess I can forward this issue to fixture builder, It only happens for
 fixtures that are in a module, like
 Event::Confirm
 Event::CriticalError
 Those fixtures propably need to either be named differently or to live in a
 module subfolder.

 So, nothing wrong with RSpec, I am very sorry that I put this one on you, so
 many times you have already proven to people that the error lies elsewhere
 and rspec is running perfectly fine. But for many users like me it's where
 we see the error/problem we suspect it's origin.

Don't worry about blame, as long as you're not spewing hate in the
process. RSpec is far from perfect, and it's fine for you to report
problems here even if they end up being further down the stack. It's
useful for other RSpec users who might encounter the same problem, and
once we identify what the problem really is then it can be reported to
the proper place with more accuracy.

 And integration between all the testing tools is tricky to balance for devs.

This is true of non-testing tools as well :)

Thanks for doing the research.

Cheers,
David


 On Thu, Jun 7, 2012 at 12:15 PM, David Chelimsky dchelim...@gmail.com
 wrote:

 On Thu, Jun 7, 2012 at 5:54 AM, David Chelimsky dchelim...@gmail.com
 wrote:
  On Thu, Jun 7, 2012 at 4:00 AM, Rainer Kuhn rai...@incutio.com wrote:
  I narrowed it down to three things, the first one might be interesting
  to
  you, the other ones are my problem, although probably common among lots
  of
  projects:
 
  Since we don't mock we usually need a bit of test data prepared for
  each
  test. At first we used factories, but setting things up every time took
  way
  to long. So I went for fixture builder instead.
 
  (http://pivotallabs.com/users/georg/blog/articles/1864-fixture-builder-and-rspec-acceptance)
  It was an immediate improvement, although not a great one, since we
  have a
  generic setup_test_data method that runs before most tests and loads
  from
  the database into instance variables.
 
  1) config.global_fixtures = :all
  With this line in, the execution of a single focused spec jumps up to a
  minute. My unresearched guess is that it might load the fixtures for
  each
  spec, although it won't even be executed.
 
  Would you please check log/test.log to verify this?

 Actually I went ahead and checked this myself and what I see is that
 it only creates fixtures before each spec that is run. If you run one,
 it happens once ... 2, twice, etc.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users




 --
 Rainer Kuhn

 Rails Developer
 Incutio :: www.incutio.com
 http://www.facebook.com/Incutio
 https://twitter.com/incutio

 UK Head Office: Unit 4, The Bridge Business Centre, Ash Road South, Wrexham,
 LL13 9UG.

 US Head Office: 33 South Commercial Street, Manchester, NH 03101

 T: +44 (0) 1978 661 666
 F: +44 (0)7092 181 581


 ___
 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] Slow Focus tags

2012-06-07 Thread David Chelimsky
On Thu, Jun 7, 2012 at 6:29 AM, Rainer Kuhn rai...@incutio.com wrote:
 Follow up: is there a way to set RSpec to be less forgiving on errors. If my
 specs would have failed because of that error I would have fixed it months
 ago. (Or at least reported it)

I can't duplicate this behavior myself, but from what I can see in the
gist, it happens when rspec calls Rails `fixtures` method and does not
bubble back up to RSpec. If you see a place that RSpec is actively
hiding this please submit an issue to
http://github.com/rspec/rspec-rails/issues.

Cheers,
David



 On Thu, Jun 7, 2012 at 12:26 PM, Rainer Kuhn rai...@incutio.com wrote:

 I guess I can forward this issue to fixture builder, It only happens for
 fixtures that are in a module, like
 Event::Confirm
 Event::CriticalError
 Those fixtures propably need to either be named differently or to live in
 a module subfolder.

 So, nothing wrong with RSpec, I am very sorry that I put this one on you,
 so many times you have already proven to people that the error lies
 elsewhere and rspec is running perfectly fine. But for many users like me
 it's where we see the error/problem we suspect it's origin.
 And integration between all the testing tools is tricky to balance for
 devs.

 On Thu, Jun 7, 2012 at 12:15 PM, David Chelimsky dchelim...@gmail.com
 wrote:

 On Thu, Jun 7, 2012 at 5:54 AM, David Chelimsky dchelim...@gmail.com
 wrote:
  On Thu, Jun 7, 2012 at 4:00 AM, Rainer Kuhn rai...@incutio.com wrote:
  I narrowed it down to three things, the first one might be interesting
  to
  you, the other ones are my problem, although probably common among
  lots of
  projects:
 
  Since we don't mock we usually need a bit of test data prepared for
  each
  test. At first we used factories, but setting things up every time
  took way
  to long. So I went for fixture builder instead.
 
  (http://pivotallabs.com/users/georg/blog/articles/1864-fixture-builder-and-rspec-acceptance)
  It was an immediate improvement, although not a great one, since we
  have a
  generic setup_test_data method that runs before most tests and loads
  from
  the database into instance variables.
 
  1) config.global_fixtures = :all
  With this line in, the execution of a single focused spec jumps up to
  a
  minute. My unresearched guess is that it might load the fixtures for
  each
  spec, although it won't even be executed.
 
  Would you please check log/test.log to verify this?

 Actually I went ahead and checked this myself and what I see is that
 it only creates fixtures before each spec that is run. If you run one,
 it happens once ... 2, twice, etc.
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users




 --
 Rainer Kuhn

 Rails Developer
 Incutio :: www.incutio.com
 http://www.facebook.com/Incutio
 https://twitter.com/incutio

 UK Head Office: Unit 4, The Bridge Business Centre, Ash Road South,
 Wrexham, LL13 9UG.

 US Head Office: 33 South Commercial Street, Manchester, NH 03101

 T: +44 (0) 1978 661 666
 F: +44 (0)7092 181 581




 --
 Rainer Kuhn

 Rails Developer
 Incutio :: www.incutio.com
 http://www.facebook.com/Incutio
 https://twitter.com/incutio

 UK Head Office: Unit 4, The Bridge Business Centre, Ash Road South, Wrexham,
 LL13 9UG.

 US Head Office: 33 South Commercial Street, Manchester, NH 03101

 T: +44 (0) 1978 661 666
 F: +44 (0)7092 181 581


 ___
 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] it blocks not executing

2012-06-06 Thread David Chelimsky
On Tue, Jun 5, 2012 at 3:47 PM, Robbie Leib rob...@onthecity.org wrote:
 Rails 2.3.14 app

 rspec (1.3.2)
 rspec-rails (1.3.4)

 When I run bundle exec rake spec, not matter what, I get:

 0 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 
 notifications

This is not rspec's output, so something else is not configured
correctly. Would you mind posting the Rakefile and
spec/spec_helper.rb?

 0% passed

 I have one spec file, and I hit the first debug statement, and not the 2nd:

 require 'spec_helper'

 describe Api::Admin::V1::UsersController do
        describe /api/admin/v1/users do
                describe GET index do
                        debugger
                        it should return first 20 users do
                                debugger
                                assert_equal false, true
                        end
                        it should return page 2 do
                        end
                        it should filter on last name do
                        end
                end
        end
 end

 What could be causing this?

 Thanks,



 --

 Robbie
 ___
 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] Slow Focus tags

2012-06-06 Thread David Chelimsky
On Wed, Jun 6, 2012 at 5:14 AM, Rainer Kuhn rai...@incutio.com wrote:
 [This is my third and final attempt to post to this group, first 2 were with
 google groups]

The google group is a mirror of the rspec-users list, but for that to
work you actually have to post to the rspec-users list, not the google
group. We're considering retiring that list and only using the google
group, at which point you'd be able to post directly to the google
group.

 I noticed that focusing a single spec takes ages to run. We commonly use
 that, often in combination with guard to speed up our spec runs. I admit
 that the overall performance of our specs is bad, since we ditched mocking
 entirely and went with semi-integration specs on all levels. But this
 practice has served us very well on picking up failures.

 All runs on a single spec with focus: true that only tests (2 + 2).should ==
 4, among 700 other specs.
 Any ideas how to profile or even fix that?

 # What I want to get:
 $ time rspec spec/models/user_spec.rb:5
 Finished in 1.41 seconds 1 example, 0 failures
 real 0m13.768s
 user 0m11.269s
 sys 0m1.692s

Wow. This is _not_ what I'd want to get. Nearly 14 secs to run a
single example sounds like you're suffering some serious startup time.
What version of rspec, ruby, rails, etc are you running?

 # What I get using the focus tag:
 $ time rake spec
 Finished in 2.1 seconds 1 example, 0 failures
 real 1m5.502s
 user 0m46.467s
 sys 0m14.455s

When you run `rake spec` it loads up the Rails development environment
(because that's the environment you're running rake in) and then
shells out the `rspec spec` command with the Rails test environment.
That's why `rake spec` will always take longer than running `rspec
spec`.

 $time rspec spec
 Finished in 1.39 seconds 1 example, 0 failures
 real 0m51.350s
 user 0m36.069s
 sys 0m12.842s

When you run with `--tag focus` on the command line, or
`config.filter_run_including :focus`, rspec evaluates the metadata for
every example in the suite in order to find the one(s) that match(es)
the tag. It's possible that you've got a filter in your config or in a
spec that takes a long time to evaluate. What's in RSpec.configure in
spec/spec_helper.rb?

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


Re: [rspec-users] Slow Focus tags

2012-06-06 Thread David Chelimsky
On Wed, Jun 6, 2012 at 6:38 AM, Rainer Kuhn rai...@incutio.com wrote:
 I have started with a blank spec_helper and I'm seeing lots of improvements
 regarding the focus tag. Not the 12sec load time however. Let me do some
 legwork first and I present you with the results in a couple of hours.
 Tomorrow perhaps since I have a couple of hours of urgent dev work my list.

 My current spec_helper is a huge mess copy pasted from multiple sources over
 a period of 4 months. I'm really not proud of it especially since I'm using
 spec since 2008. Read it and weep:
 https://gist.github.com/2881400

There's a lot there. Redis, fog, all the macros modules. Any of them
could be contributing.

 On Wed, Jun 6, 2012 at 12:24 PM, David Chelimsky dchelim...@gmail.com
 wrote:

 On Wed, Jun 6, 2012 at 5:14 AM, Rainer Kuhn rai...@incutio.com wrote:
  [This is my third and final attempt to post to this group, first 2 were
  with
  google groups]

 The google group is a mirror of the rspec-users list, but for that to
 work you actually have to post to the rspec-users list, not the google
 group. We're considering retiring that list and only using the google
 group, at which point you'd be able to post directly to the google
 group.

  I noticed that focusing a single spec takes ages to run. We commonly use
  that, often in combination with guard to speed up our spec runs. I admit
  that the overall performance of our specs is bad, since we ditched
  mocking
  entirely and went with semi-integration specs on all levels. But this
  practice has served us very well on picking up failures.
 
  All runs on a single spec with focus: true that only tests (2 +
  2).should ==
  4, among 700 other specs.
  Any ideas how to profile or even fix that?
 
  # What I want to get:
  $ time rspec spec/models/user_spec.rb:5
  Finished in 1.41 seconds 1 example, 0 failures
  real 0m13.768s
  user 0m11.269s
  sys 0m1.692s

 Wow. This is _not_ what I'd want to get. Nearly 14 secs to run a
 single example sounds like you're suffering some serious startup time.
 What version of rspec, ruby, rails, etc are you running?

  # What I get using the focus tag:
  $ time rake spec
  Finished in 2.1 seconds 1 example, 0 failures
  real 1m5.502s
  user 0m46.467s
  sys 0m14.455s

 When you run `rake spec` it loads up the Rails development environment
 (because that's the environment you're running rake in) and then
 shells out the `rspec spec` command with the Rails test environment.
 That's why `rake spec` will always take longer than running `rspec
 spec`.

  $time rspec spec
  Finished in 1.39 seconds 1 example, 0 failures
  real 0m51.350s
  user 0m36.069s
  sys 0m12.842s

 When you run with `--tag focus` on the command line, or
 `config.filter_run_including :focus`, rspec evaluates the metadata for
 every example in the suite in order to find the one(s) that match(es)
 the tag. It's possible that you've got a filter in your config or in a
 spec that takes a long time to evaluate. What's in RSpec.configure in
 spec/spec_helper.rb?

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




 --
 Rainer Kuhn

 Rails Developer
 Incutio :: www.incutio.com
 http://www.facebook.com/Incutio
 https://twitter.com/incutio

 UK Head Office: Unit 4, The Bridge Business Centre, Ash Road South, Wrexham,
 LL13 9UG.

 US Head Office: 33 South Commercial Street, Manchester, NH 03101

 T: +44 (0) 1978 661 666
 F: +44 (0)7092 181 581


 ___
 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] overview of how rspec was designed

2012-05-15 Thread David Chelimsky
On Mon, May 14, 2012 at 2:23 PM, S Ahmed sahmed1...@gmail.com wrote:
 Other than jumping into the codebase myself, I was wondering if anyone has
 done a high-level (or better yet low level) write-up on how rspec works
 under the covers?

The RSpec Book has a fairly deep discussion on the inner workings.
Other than that, there are some things you can get from the docs, but
there is not a central this is how RSpec works document that I've
written or am aware of.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Stubs and contract tests

2012-05-11 Thread David Chelimsky
On Fri, May 11, 2012 at 9:24 AM, Alexandre de Oliveira 
chavedomu...@gmail.com wrote:

 Hey guys, could you help me (in)validating an idea?

 As you might know, Contract tests solve a problem stubs have: if the
 object interface changes, the stubbed tests will continue passing.

 In RSpec, it's common to use a shared_context to describe contracts, so
 both Posts and Comments tests would have PostsCommentsContract. If
 Comment's interface ever changed, Posts tests would present a failure
 wherever we ran it. However, it won't tell us which stubbed methods were
 invalid now; it just tell us the file that have invalid stubs.

 If we had, for example, #stub_contract(:method), automatically raising
 a failure if its reference (double) object's interface changed, how would
 it be bad?

 I'm trying to think the cons of it. Could you guys help me finding it?


See https://github.com/rspec/rspec-mocks/issues/15
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] how do I test for a status code in a :js = true test?

2012-05-10 Thread David Chelimsky
On Wed, May 9, 2012 at 11:14 PM, Patrick J. Collins
patr...@collinatorstudios.com wrote:
 I have a view with some javascript that does page redirection, and I
 wanted to confirm that under certain circumstances the user will get a
 500 error from CanCan::AccessDenied.

 It seems that when I am not using :js = true, I can do:

 page.status_code.shoud be 500

 but.. when I try that in a :js = true example group, I get:
 Capybara::NotSupportedByDriverError: Capybara::NotSupportedByDriverError

 also the request and response objects are nil in the context of this
 test...  My dirty workaround has just been to do:

 page.has_content CanCan::AccessDenied

 Which serves my purposes, but I was hoping for a better way...  Any
 ideas?

Not sure. I'd post this to the Capybara list.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] stub.as_null_object mock and double

2012-05-09 Thread David Chelimsky
On Wed, May 9, 2012 at 11:01 AM, Andrew Premdas aprem...@gmail.com wrote:
 Hi there,

 Is there any particular reason why stub is not stub.as_null_object by
 default?

See https://github.com/rspec/rspec-mocks/issues/56
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] is there a way to turn on :js = true in the middle of a spec?

2012-05-09 Thread David Chelimsky
On Wed, May 9, 2012 at 3:09 PM, Patrick J. Collins
patr...@collinatorstudios.com wrote:
 Hi,

 If I have a spec with some complicated background stuff--  like say for
 example logging in...

 it does stuff, :js = true do
  fancy_login_helper_method
  visit somewhere_over_the_rainbow_path
  click_button omg
  page.should have_content(waka waka)
 end

 ...  Is there any way to do something like :

 it does stuff do
  fancy_login_helper_method
  js do
    visit somewhere_over_the_rainbow_path
    click_button omg
    page.should have_content(waka waka)
  end
 end

 So that I can cut down the time it takes to excute that test a bit?  Or
 is that just impossible with the way headless vs browser stuff works?

iiuc, browser is the issue, not headless. The login
token/cookie/whatever needs to be stored in the client so it can
identify itself to the server. What your proposing switches the
client.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Retrying specs

2012-05-08 Thread David Chelimsky
On Tue, May 8, 2012 at 12:55 PM, Samer Masry samer.ma...@gmail.com wrote:
 Is it possible to run an example without displaying it's
 status ...F...

The 'F' comes from the ProgressFormatter. You could write your own
custom formatter.

https://www.relishapp.com/rspec/rspec-core/docs/formatters/custom-formatters

 I'm currently using an around(:each) to run the spec and passing the
 example block into vcr however occasionally the cassette needs to be
 rerecorded.  I'd like to delay recording it as an error until it has been
 retried.  Is that possible currently in rspec?

You could probably hack something together but rspec doesn't support
any notion of retry explicitly. Feel free to submit a feature request
to https://github.com/rspec/rspec-core/issues and we can discuss it
there.

Cheers,
David


 --
 DryBlis - www.dryblis.com
 Samer Masry | Rails Programmer
 11 Ambler Ln, Emeryville, CA 94608
 Tel.:510-991-7523 | Cel.: 714-814-8508
 ___
 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 2.10.0 breaks controller specs...

2012-05-04 Thread David Chelimsky
On Fri, May 4, 2012 at 3:07 PM, Patrick J. Collins
patr...@collinatorstudios.com wrote:
 Apparently 2.10.0 doesn't like this line in devise's 
 lib/devise/test_helpers.rb
  @request.env['warden'] = Warden::Proxy.new(@request.env, manager)

Please file bug reports to
https://github.com/rspec/rspec-rails/issues, and please look to see if
someone else already has before you do:

https://github.com/rspec/rspec-rails/issues/534

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


[rspec-users] rspec-2.10 is released!

2012-05-03 Thread David Chelimsky
rspec-2.10 is released!

Cucumber docs

http://rubydoc.info/gems/rspec-core
http://rubydoc.info/gems/rspec-expectations
http://rubydoc.info/gems/rspec-mocks
http://rubydoc.info/gems/rspec-rails

API Docs (RDoc)

http://relishapp.com/gems/rspec-core
http://relishapp.com/gems/rspec-expectations
http://relishapp.com/gems/rspec-mocks
http://relishapp.com/gems/rspec-rails

### rspec-core-2.10.0

full changelog: http://github.com/rspec/rspec-core/compare/v2.9.0...v2.10.0

Enhancements

* Add `prepend_before` and `append_after` hooks (preethiramdev)
* intended for extension libs
* restores rspec-1 behavior
* Reporting of profiled examples (moro)
* Report the total amount of time taken for the top slowest examples.
* Report what percentage the slowest examples took from the total runtime.

Bug fixes

* Properly parse `SPEC_OPTS` options.
* `example.description` returns the location of the example if there is no
  explicit description or matcher-generated description.
* RDoc fixes (Grzegorz Świrski)
* Do not modify example ancestry when dumping errors (Michael Grosser)

### rspec-expectations-2.10.0

full changelog: 
http://github.com/rspec/rspec-expectations/compare/v2.9.1...v2.10.0

Enhancements

* Add new `start_with` and `end_with` matchers (Jeremy Wadsack)
* Add new matchers for specifying yields (Myron Marson):
* `expect {...}.to yield_control`
* `expect {...}.to yield_with_args(1, 2, 3)`
* `expect {...}.to yield_with_no_args`
* `expect {...}.to yield_successive_args(1, 2, 3)`
* `match_unless_raises` takes multiple exception args

Bug fixes

* Fix `be_within` matcher to be inclusive of delta.
* Fix message-specific specs to pass on Rubinius (John Firebaugh)

### rspec-mocks-2.10.0

full changelog: http://github.com/rspec/rspec-mocks/compare/v2.9.0...v2.10.0

Bug fixes

* fail fast when an `exactly` or `at_most` expectation is exceeded  

### rspec-rails-2.10.0

full changelog: http://github.com/rspec/rspec-core/compare/v2.9.0...v2.10.0

Bug fixes

* `render_views` called in a spec can now override the config setting. 
(martinsvalin)
* Fix `render_views` for anonymous controllers on 1.8.7. (hudge, mudge)
* Eliminate use of deprecated `process_view_paths`
* Fix false negatives when using `route_to` matcher with `should_not`
* `controller` is no longer nil in `config.before` hooks
* Change `request.path_parameters` keys to symbols to match real Rails
  environment (Nathan Broadbent)
* Silence deprecation warnings in pre-2.9 generated view specs
  (Jonathan del Strother)



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

Re: [rspec-users] stuck in testing hell...

2012-05-01 Thread David Chelimsky
On Tue, May 1, 2012 at 2:17 PM, Patrick J. Collins
patr...@collinatorstudios.com wrote:
 The frustration your experiencing is actually a good thing, its your brain 
 saying hey something is just not right. Of
 course our natural reaction to this is just to get angry, but if we can get 
 past that there is an opportunity to learn
 something important. In my limited experience I've found that listening to 
 tests is one of the best ways to learn. There
 is probably something seriously wrong with your existing tests and code. So 
 instead of trying to work around it, and get
 your tests to pass, seize the opportunity and try and work out why your 
 tests and code suck and get to the bottom of the
 problem. This is a real opportunity to learn something.

 I hear you, but honestly these tests are very straight forward and not
 overly complicated in any way, shape, or form.  I did some more
 experimenting and was able to narrow the problem down to:  Serialization and 
 Mocha.

Tests have to run code. Your tests are running already complicated
code (Rails), that is further complicated by introducing
Serialization, and then further complicated by using Mocha. I do these
things too, so I'm not saying they are bad, but they are nothing if
they are not un-straight-forward and complicated. Just because syntax
hides all that complexity from you doesn't make it go away.

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


[rspec-users] This is a test to see if the google mirror is working again

2012-04-26 Thread David Chelimsky
This is a test to see if the google mirror is working again. Sorry for the 
noise.

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

[rspec-users] New google groups (help, please)

2012-04-25 Thread David Chelimsky
Hi all.

Google is in the process of changing the google group format and,
unless I'm missing something, seems to have abandoned the mirror
functionality this list has relied on for several years now (posting
to rspec-users also posts to the google group).

If anybody on this list knows how to solve this problem in the google
group UI, please let me know.

If not, we need to retire/archive either the rspec-users mailing list
or the google group. Any thoughts on this?

Thanks in advance for your help/advice.

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


Re: [rspec-users] using rspec in a non-rails environment

2012-04-23 Thread David Chelimsky
On Mon, Apr 23, 2012 at 12:26 PM, S Ahmed sahmed1...@gmail.com wrote:
 My folder structure is as follows:

 /myapp/
 /myapp/lib/class1.rb

 /myapp/rspec/spec_helper.rb
 /myapp/rspec/lib/class1_spec.rb

 My spec_helper has:

 require 'rubygems'

^^ If you've installed rspec as a gem and you're running the rspec
command, you don't need to require 'rubygems'. ^^

 require 'rspec'

^^ This should be 'rspec/autorun'. ^^


 RSpec.configure do |config|
 end

This ^^ is not necessary unless you're using it

 My class1_spec.rb has:

 require 'spec_helper'
 require '../../lib/class1'

 describe Class1 do
   it should do something
 end


 How do I require my class1 correct, when I run:

 rspec spec/lib/class1_spec.rb I am getting:

 1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file --
 ../../lib/class1.rb (LoadError)

RSpec adds 'lib' to the LOAD_PATH, so you can just `require class1`,
but it's conventional to do this in spec_helper.rb instead.

HTH,
David


 Also, in a non-rails app, what kind of things do you put in the spec_helper
 normally? any popular config settings that I should know about?

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


Re: [rspec-users] How to modify database inside a transaction in before(:all)?

2012-04-23 Thread David Chelimsky
On Mon, Apr 23, 2012 at 5:39 PM, Rodrigo Rosenfeld Rosas
rr.ro...@gmail.com wrote:
 I have a set of examples that should run with a specific set of records in
 the database.

 Since setting those records is an expensive operation I'd like to perform it
 just once per context.

 For example:

 context 'sample tree' do
     before(:all) { create_tree_records }

     example ...
 end

 The problem with this is that while before(:each) and the examples will run
 in a transaction that will be rolled back at the end of each example, that
 won't happen to the records created/modified by the before(:all) block.

 It seems my database vendor (PostgreSQL) supports nested transactions
 (savepoints):

 http://www.postgresql.org/about/

 I should also notice that I'm using Sequel and it seems that transactions
 are reentrant in Sequel:

 http://cheat.errtheblog.com/s/sequel/

 Database#transaction is re-entrant:

   DB.transaction do # BEGIN issued only here
     DB.transaction
   dataset  {:first_name = 'Inigo', :last_name = 'Montoya'}
     end
 end # COMMIT issued only here

 So, this logic wouldn't work for me. I need a save point in a before(:all),
 so that I'd restore it on a before(:each).

 Is there any recommendation to make this work in my specs?

Nothing built into RSpec now, but you could disable the Rails
transaction management and use DatabaseCleaner on your own.

This is currently being discussed in
https://github.com/rspec/rspec-rails/issues/496 as well. Feel free to
join that convo.

Cheers,
David


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


Re: [rspec-users] One error reported recursively if two pages visited by request spec

2012-04-22 Thread David Chelimsky
Looks like this is related to https://github.com/rspec/rspec-core/issues/585, 
which is already fixed in master. If you point your Gemfile to github now 
you'll see it fixed. 2.10 release coming soon.

group :test do
  gem 'rspec-rails',:git = git://github.com/rspec/rspec-rails.git
  gem 'rspec-core', :git = git://github.com/rspec/rspec-core.git
  gem 'rspec-expectations', :git = 
git://github.com/rspec/rspec-expectations.git
  gem 'rspec-mocks',:git = git://github.com/rspec/rspec-mocks.git
  gem 'capybara', '1.1.2'
end



Cheers,
David


-- 
David Chelimsky
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Thursday, April 19, 2012 at 5:55 PM, Mark Berry wrote:

 On Thu, Apr 19, 2012 at 8:54 AM, Mark Berry mcbsyst...@gmail.com 
 (mailto:mcbsyst...@gmail.com) wrote:
  On Wed, Apr 18, 2012 at 8:09 PM, David Chelimsky dchelim...@gmail.com 
  (mailto:dchelim...@gmail.com) wrote:
   On Wednesday, April 18, 2012 at 4:30 PM, Mark Berry wrote:
   
   On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote:
   On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote:
   
   Hi,
   
   I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0.
   
   I've been getting recursive errors, where one error is reported
   multiple times. It's quite spectacular in a long suite, with the
   errors overflowing the console buffer. I've whittled down a simple
   example:
   
   require 'spec_helper'
   describe public pages do
   subject { page }
   describe details page do
   before do
   visit root_path
   end
   describe when visiting a second page before example do
   before { visit sign_in_path }
   it { should have_link(Sign in) }
   end
   end
   end
   
   The error here is that sign_in_path should really be signin_path.
   But I get that error five times, and when I run with --format
   documentation, it looks like RSpec is generating it recursively before
   it blows up with a stack trace (see output below).
   
   Obviously this test doesn't really need two before blocks, but
   sometimes I do want to visit two pages before a test.
   
   Am I doing something wrong, or is this a bug?
   
   Mark Berry
   
   ~
   Test output:
   
   [myproject (tests)]$ rspec spec/requests/test2* --format documentation
   No DRb server is running. Running in local process instead ...
   
   public pages
   details page
   when no user is signed in
   when visiting a second page before example
   when visiting a second page before example
   when no user is signed in
   when visiting a second page before example
   details page
   when no user is signed in
   when visiting a second page before example
   
   Failures:
   
   1) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   2) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   3) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   4) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   5) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   
   This is what I would expect. There is nothing recursive about this. 
   There
   is a failure in
   a before block that runs before every example. It's the same as if you had
   the same
   broken code directly in each example.
   
   
   HTH,
   David
   
   
   [Sorry if this starts a new thread. I

Re: [rspec-users] One error reported recursively if two pages visited by request spec

2012-04-18 Thread David Chelimsky
On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote:
 Hi,
 
 I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0.
 
 I've been getting recursive errors, where one error is reported
 multiple times. It's quite spectacular in a long suite, with the
 errors overflowing the console buffer. I've whittled down a simple
 example:
 
 require 'spec_helper'
 describe public pages do
 subject { page }
 describe details page do
 before do
 visit root_path
 end
 describe when visiting a second page before example do
 before { visit sign_in_path }
 it { should have_link(Sign in) }
 end
 end
 end
 
 The error here is that sign_in_path should really be signin_path.
 But I get that error five times, and when I run with --format
 documentation, it looks like RSpec is generating it recursively before
 it blows up with a stack trace (see output below).
 
 Obviously this test doesn't really need two before blocks, but
 sometimes I do want to visit two pages before a test.
 
 Am I doing something wrong, or is this a bug?
 
 Mark Berry
 
 ~
 Test output:
 
 [myproject (tests)]$ rspec spec/requests/test2* --format documentation
 No DRb server is running. Running in local process instead ...
 
 public pages
 details page
 when no user is signed in
 when visiting a second page before example
 when visiting a second page before example
 when no user is signed in
 when visiting a second page before example
 details page
 when no user is signed in
 when visiting a second page before example
 
 Failures:
 
 1) public pages details page when no user is signed in when visiting
 a second page before example
 Failure/Error: before { visit sign_in_path }
 NameError:
 undefined local variable or method `sign_in_path' for
 #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
 # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
 top (required)'
 
 2) public pages details page when no user is signed in when visiting
 a second page before example
 Failure/Error: before { visit sign_in_path }
 NameError:
 undefined local variable or method `sign_in_path' for
 #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
 # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
 top (required)'
 
 3) public pages details page when no user is signed in when visiting
 a second page before example
 Failure/Error: before { visit sign_in_path }
 NameError:
 undefined local variable or method `sign_in_path' for
 #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
 # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
 top (required)'
 
 4) public pages details page when no user is signed in when visiting
 a second page before example
 Failure/Error: before { visit sign_in_path }
 NameError:
 undefined local variable or method `sign_in_path' for
 #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
 # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
 top (required)'
 
 5) public pages details page when no user is signed in when visiting
 a second page before example
 Failure/Error: before { visit sign_in_path }
 NameError:
 undefined local variable or method `sign_in_path' for
 #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
 # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
 top (required)'
 
 
 

This is what I would expect. There is nothing recursive about this. There is 
a failure in a before block that runs before every example. It's the same as if 
you had the same broken code directly in each example.

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

Re: [rspec-users] Access controller object in controller macro

2012-04-18 Thread David Chelimsky
On Tuesday, April 17, 2012 at 2:30 PM, Nasir Jamal wrote:
 
 Hi
 
 We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 
 2.6. We are having two problems with rspec currently and any help would be 
 great.
 
 1) We have some controller macros where we have been using the controller 
 object, session hash, response, etc. in different methods for e.g.
 
 module ControllerMacros
   def imaginary_method_with_example_calls
  # in actual code different methods call one of the below, this is just 
 an example of things not working
 controller.stubs(:method)
 controller.class.skip_before_filter(:name)
 session[:user_id] = user.id
 response.something
   end
 end
 
 But now after upgrading to Rspec 2.6 they do not work and calling controller 
 just returns nil and hence undefined method 'skip_before_filter' for NilClass 
 error. I did google but found nothing regarding this.
Is imaginary_method_with_example_calls called in a config.before hook? If so, 
the issue is that controller is nil [1]. This has been fixed on master, but not 
yet released (look for the 2.10 release in the next couple of weeks.

 2) Changing 'request.request_uri' to 'request.full_path' raises the following 
 error when running rspec
 NoMethodError:
undefined method `full_path' for 
 #ActionController::TestRequest:0x1bfa46f8
I'd check the rails docs for this one. I'm not immediately familiar w/ what's 
going on.

HTH,
David

[1] https://github.com/rspec/rspec-rails/issues/391___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] One error reported recursively if two pages visited by request spec

2012-04-18 Thread David Chelimsky
On Wednesday, April 18, 2012 at 4:30 PM, Mark Berry wrote:
  On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote:
  On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote:
   Hi,
   
   I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0.
   
   I've been getting recursive errors, where one error is reported
   multiple times. It's quite spectacular in a long suite, with the
   errors overflowing the console buffer. I've whittled down a simple
   example:
   
   require 'spec_helper'
   describe public pages do
   subject { page }
   describe details page do
   before do
   visit root_path
   end
   describe when visiting a second page before example do
   before { visit sign_in_path }
   it { should have_link(Sign in) }
   end
   end
   end
   
   The error here is that sign_in_path should really be signin_path.
   But I get that error five times, and when I run with --format
   documentation, it looks like RSpec is generating it recursively before
   it blows up with a stack trace (see output below).
   
   Obviously this test doesn't really need two before blocks, but
   sometimes I do want to visit two pages before a test.
   
   Am I doing something wrong, or is this a bug?
   
   Mark Berry
   
   ~
   Test output:
   
   [myproject (tests)]$ rspec spec/requests/test2* --format documentation
   No DRb server is running. Running in local process instead ...
   
   public pages
   details page
   when no user is signed in
   when visiting a second page before example
   when visiting a second page before example
   when no user is signed in
   when visiting a second page before example
   details page
   when no user is signed in
   when visiting a second page before example
   
   Failures:
   
   1) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   2) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   3) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   4) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
   5) public pages details page when no user is signed in when visiting
   a second page before example
   Failure/Error: before { visit sign_in_path }
   NameError:
   undefined local variable or method `sign_in_path' for
   #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0xb6f3460
   # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in
   top (required)'
   
  
  
 
 
  This is what I would expect. There is nothing recursive about this. There 
  is a failure in
  a before block that runs before every example. It's the same as if you had 
  the same
  broken code directly in each example.
  
 
 
  HTH,
  David
  
 
 
 [Sorry if this starts a new thread. I was attempting to monitor and
 reply to the group through Google Groups, but apparently that mirror
 stopped working on April 10, so I'm having to reconstruct this reply.]
 
 Thanks for the reply.
 
 Although the output says 5 examples, 5 failures, there is only one
 example, hence my confusion about it failing five times. Also, the
 documentation output lists each describe block (except the first)
 two to four times.
 
 When I fix the error, I get one line per describe, plus one example
 completed, as expected:
 
 
 [myproject (tests)]$ rspec spec/requests/test2* --format documentation
 
 public pages
 details page
 when visiting a second page before example
 should has link Sign in
 
 Finished in 1.44 seconds
 1 example, 0 failures
 
 
 I have since discovered that the problem only occurs when using
 --format documentation. Without that, with the error back in place,
 RSpec only gives me one error, not five:
 
 
 [myproject

Re: [rspec-users] how can I get prettier failure messages for integration specs?

2012-04-18 Thread David Chelimsky
On Wednesday, April 18, 2012 at 7:01 PM, Patrick J. Collins wrote:
 When an integration test fails, I get a whole mess of garbage that is
 all in red, very painful to the eyes-- Especially when I quickly just
 want to see what went wrong-- in this case, all I want to see is
 ActiveRecord::RecondNotFound-- but instead I see: 
 
 Failure/Error: page.should have_content Submit Payment
 expected there to be content Submit Payment in Action
 Controller: Exception caught\n body { background-color: #fff; color:
 #333; }\n\n body, p, ol, ul, td {\n font-family: helvetica,
 verdana, arial, sans-serif;\n font-size: 13px;\n
 line-height: 18px;\n }\n\n pre {\n background-color: #eee;\n
 padding: 10px;\n font-size: 11px;\n white-space: pre-wrap;\n
 }\n\n a { color: #000; }\n a:visited { color: #666; }\n a:hover
 { color: #fff; background-color:#000; }\n \n\n\n
 ActiveRecord::RecordNotFound\n ... bla bla bla bla bla bla forever.
 
 .. Are there any options to reformat this output? A small
 improvement would be to actually turn \n into actual new lines...
 However, an even better option would be to make this automatically
 launch the browser so that the error page could be read properly.
 
 Is this possible?
If you're using capybara you could put save_and_open_page in an after hook. 
You'd still get the console output, but at least you'd see the page in a 
browser.

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

Re: [rspec-users] RSpec exactly behavior (it doesn't exactly fail)

2012-04-15 Thread David Chelimsky
On Sunday, April 15, 2012 at 1:32 AM, Bas Vodde wrote:
 
 Hiya all,
 
 I've got a quick question related to RSpec. I was test-driving some code and 
 ended up in an endless loop. I was surprised by this, but traced it down to 
 the mock not failing on additional calls but only in the end. Let me explain.
 
 I was writing code like this:
 
 subject.wrapper.should_receive(:window_list).exactly(4).times.and_return {
 counter = counter + 1
 counter = 4 ? [ new window ] : []
 }
 
 The idea was that it would call the code-block 4 times exactly and then 
 return a new value (and thus stop calling it). As the code to implement 
 wasn't there yet, it led to a recursive call. I had expected RSpec to stop 
 after 4 calls though, as I had instructed the mock that I expected exactly 4 
 calls.
 
 I added a new test in RSpec itself in precision_counts_spec.rb:
 
 it fails when a method is called more than n times, but fails within the 
 method call do
 @mock.should_receive(:random_call).exactly(1).times
 lambda do
 @mock.random_call
 @mock.random_call
 end.should raise_error(RSpec::Mocks::MockExpectationError) 
 end
 
 which failed :( (or it failed to fail and therefore failed!)
 
 It would be nice if it would fail. Is there any reason for not failing 
 already at this point in time?
 
 (I'm using RSpec 2.6-0. I quickly browsed the latest and didn't see this 
 changed)
 
 Thanks,
 
 Bas
There is no philosophical reason for this to happen, and there are other types 
of failures that do fail-fast (e.g. obj.should_receive(:bar).with(1,2) fails 
immediately if it receives :bar with any other args).

Please submit this to https://github.com/rspec/rspec-mocks/issues and I'll 
start looking into a fix.

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

Re: [rspec-users] RSpec exactly behavior (it doesn't exactly fail)

2012-04-15 Thread David Chelimsky
Actually I just went ahead and fixed it sans-bug report: 
https://github.com/rspec/rspec-mocks/commit/fb9c76c2e40b4b25f4dcc5de95f8c60319b6d9c1.
 It'll be fixed in the next release (2.10).

Cheers,
David


-- 
David Chelimsky
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Sunday, April 15, 2012 at 4:48 PM, David Chelimsky wrote:

 On Sunday, April 15, 2012 at 1:32 AM, Bas Vodde wrote:
  
  Hiya all,
  
  I've got a quick question related to RSpec. I was test-driving some code 
  and ended up in an endless loop. I was surprised by this, but traced it 
  down to the mock not failing on additional calls but only in the end. Let 
  me explain.
  
  I was writing code like this:
  
  subject.wrapper.should_receive(:window_list).exactly(4).times.and_return {
  counter = counter + 1
  counter = 4 ? [ new window ] : []
  }
  
  The idea was that it would call the code-block 4 times exactly and then 
  return a new value (and thus stop calling it). As the code to implement 
  wasn't there yet, it led to a recursive call. I had expected RSpec to stop 
  after 4 calls though, as I had instructed the mock that I expected exactly 
  4 calls.
  
  I added a new test in RSpec itself in precision_counts_spec.rb:
  
  it fails when a method is called more than n times, but fails within the 
  method call do
  @mock.should_receive(:random_call).exactly(1).times
  lambda do
  @mock.random_call
  @mock.random_call
  end.should raise_error(RSpec::Mocks::MockExpectationError) 
  end
  
  which failed :( (or it failed to fail and therefore failed!)
  
  It would be nice if it would fail. Is there any reason for not failing 
  already at this point in time?
  
  (I'm using RSpec 2.6-0. I quickly browsed the latest and didn't see this 
  changed)
  
  Thanks,
  
  Bas
 There is no philosophical reason for this to happen, and there are other 
 types of failures that do fail-fast (e.g. obj.should_receive(:bar).with(1,2) 
 fails immediately if it receives :bar with any other args).
 
 Please submit this to https://github.com/rspec/rspec-mocks/issues and I'll 
 start looking into a fix.
 
 Cheers,
 David
 
 


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

Re: [rspec-users] RSpec exactly behavior (it doesn't exactly fail)

2012-04-15 Thread David Chelimsky
Sorry about that. I don't always jump on things like that, but this one was 
bugging me and I had the time so I just did it. That doesn't always happen :) I 
look forward to your future contributions.

Cheers,
David


-- 
David Chelimsky
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Sunday, April 15, 2012 at 9:30 PM, Bas Vodde wrote:

 
 Hiya,
 
 Kewl, thanks!
 
 (To be honest, I was a bit disapointed as I was thinking of doing it myself 
 and sending it to you :P)
 
 Anyways, much appreciated!
 
 Bas
 
 On 16-Apr-2012, at 10:14 AM, David Chelimsky wrote:
 
  Actually I just went ahead and fixed it sans-bug report: 
  https://github.com/rspec/rspec-mocks/commit/fb9c76c2e40b4b25f4dcc5de95f8c60319b6d9c1.
   It'll be fixed in the next release (2.10).
  
  Cheers,
  David
  
  -- 
  David Chelimsky
  Sent with Sparrow
  
  On Sunday, April 15, 2012 at 4:48 PM, David Chelimsky wrote:
  
   On Sunday, April 15, 2012 at 1:32 AM, Bas Vodde wrote:

Hiya all,

I've got a quick question related to RSpec. I was test-driving some 
code and ended up in an endless loop. I was surprised by this, but 
traced it down to the mock not failing on additional calls but only in 
the end. Let me explain.

I was writing code like this:

subject.wrapper.should_receive(:window_list).exactly(4).times.and_return
 {
counter = counter + 1
counter = 4 ? [ new window ] : []
}

The idea was that it would call the code-block 4 times exactly and then 
return a new value (and thus stop calling it). As the code to implement 
wasn't there yet, it led to a recursive call. I had expected RSpec to 
stop after 4 calls though, as I had instructed the mock that I expected 
exactly 4 calls.

I added a new test in RSpec itself in precision_counts_spec.rb:

it fails when a method is called more than n times, but fails within 
the method call do
@mock.should_receive(:random_call).exactly(1).times
lambda do
@mock.random_call
@mock.random_call
end.should raise_error(RSpec::Mocks::MockExpectationError)
end

which failed :( (or it failed to fail and therefore failed!)

It would be nice if it would fail. Is there any reason for not failing 
already at this point in time?

(I'm using RSpec 2.6-0. I quickly browsed the latest and didn't see 
this changed)

Thanks,

Bas
   There is no philosophical reason for this to happen, and there are other 
   types of failures that do fail-fast (e.g. 
   obj.should_receive(:bar).with(1,2) fails immediately if it receives :bar 
   with any other args).
   
   Please submit this to https://github.com/rspec/rspec-mocks/issues and 
   I'll start looking into a fix.
   
   Cheers,
   David
   
  
  
  ___
  rspec-users mailing list
  rspec-users@rubyforge.org (mailto:rspec-users@rubyforge.org)
  http://rubyforge.org/mailman/listinfo/rspec-users
  
 
 
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org (mailto: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] Smart mocks for ActiveRecord to speed up tests

2012-04-15 Thread David Chelimsky
On Sunday, April 15, 2012 at 9:23 PM, Rodrigo Rosenfeld Rosas wrote:
 Em 14-04-2012 10:11, David Chelimsky escreveu: 
  On Friday, April 13, 2012 at 2:09 PM, Rodrigo Rosenfeld Rosas wrote:
   Hello old friends, I'm getting back to Rails and Ruby programming full 
   time again (Yay!)
   
   I've stopped doing Rails programming to work with Grails in 2009 after 2 
   years working with Rails due to a better job offer.
   
   Since then I've changed my job once more, but still on Grails, but I 
   found a critical bug in Grails more than a week ago that didn't seem to 
   get much attention and is affecting the production system I maintain:
   
   http://jira.grails.org/browse/GRAILS-8994
   
   As I couldn't work around that bug and I can't see myself reading the 
   Grails source code (a real mess!) I decided to take another approach that 
   would allow me to get back to Rails programming.
   
   I created a Devise / Warden strategy to send the cookies to the current 
   system and it will return me the current logged in user. So I can set up 
   Nginx to proxy some requests affected by the Grails bug to this new Rails 
   application.
   
   I've finished this action last Monday but when I was about to send all 
   the hard work to the server lots of my directories were suddenly gone 
   when I was using them. I still don't know what happened but I've replaced 
   my hard-drive just in case, but it means I had to do all over again :(
   
   Anyway, now I got it back to work but testing a single action (an 
   update/insert one) will take about a full second to run using RSpec and 
   FactoryGirl.
   
   I really don't like Grails but they had a great feature for unit testing. 
   They were able to mock their domain class (that is how they call their 
   models) in such a way that they can perform most of the operations you 
   can do on real objects.
   
   Of course it have another serious bug that will prevent me to use it in 
   lots of cases:
   
   http://jira.grails.org/browse/GRAILS-8854
   
   But the idea is great as it works seamlessly like in a memory database.
   
   So, I'd like to be able to keep my tests easy to read but avoid touching 
   the database that much.
   
   But my controller spec rely on lots of the setting of ActiveRecord for my 
   models, like maximum calculations in before callbacks, custom foreign 
   keys and depends: :delete_all in some has_many associations. Also I do 
   also need a user object that Devise will accept on its sign_in helper 
   method.
   
   Is there any place I could read more about writing faster tests without 
   getting crazy writing so many mocks manually. For example, mocking a 
   Grails domain class in a unit test would be as easy as:
   
   @mock(User)
   class UserTests...
   
   Then I'm able to do most operations using the Grails domain class API 
   using the User mock.
   
   Is there something like this for Rails and Rspec? Is there some way that 
   I could set up FactoryGirl to use those mocks instead of hitting the 
   database when I want to?
   
   Am I going in the wrong direction here? If so, what would be the right 
   direction?
   
   Thanks in advance.
   
   Glad to be part of the Ruby, Rails and Rspec community full-time again :D
   
   Cheers,
   Rodrigo. 
  You can use mock_model or stub_model to create model instances, or you can 
  use FactoryGirl.build instead of FactoryGirl.create. Only mock_model will 
  actually avoid db calls entirely (the others will still query for column 
  names even if you don't save anything).
  
  Those techniques, however, don't help you with finders. You still have to 
  stub any finders with the object generated by any of the aforementioned 
  techniques: 
  
  thing = mock_model(Thing) 
  Thing.stub(:domain_specific_finder = [thing])
  
 
 
 I'm not sure what you're suggesting. For example, the first part of my 
 controller action looks like this:
 
 instance = Model.where(id: params[:id]).first_or_initialize(parent_id: 
 params[:parentId])
The controller is interacting with an ActiveRecord API on the model instead of 
a domain-specific-finder. I'd recommend wrapping this in a method on the model 
and then mocking _that_ method.
 The spec starts with something like this:
 
 root = FactoryGirl.create :field, label: 'ROOT'
 post 'action', parentId: root.id
 
 In the before/after Model callbacks there will be other kind of finders for 
 the same class.
Think I'd need to see more of the code to comment on this.
 How would you suggest me to change this block to use FactoryGirl.build and 
 mock Model?
Use one or the other (they both serve a similar purpose).
 Also, I couldn't find how to mock 'open' from 'open-uri', so I'm currently 
 mocking my controller's action:
 
 controller.should_receive(:clear_fields_cache).exactly(3).times # 1 creation 
 and 2 updates
 
 The action is implemented this way:
 
 require 'open-uri'
 ...
 private
   def clear_fields_cache
 open INTEGRATION_BASE_URL

Re: [rspec-users] Smart mocks for ActiveRecord to speed up tests

2012-04-14 Thread David Chelimsky
On Friday, April 13, 2012 at 2:09 PM, Rodrigo Rosenfeld Rosas wrote:
 Hello old friends, I'm getting back to Rails and Ruby programming full time 
 again (Yay!)
 
 I've stopped doing Rails programming to work with Grails in 2009 after 2 
 years working with Rails due to a better job offer.
 
 Since then I've changed my job once more, but still on Grails, but I found a 
 critical bug in Grails more than a week ago that didn't seem to get much 
 attention and is affecting the production system I maintain:
 
 http://jira.grails.org/browse/GRAILS-8994
 
 As I couldn't work around that bug and I can't see myself reading the Grails 
 source code (a real mess!) I decided to take another approach that would 
 allow me to get back to Rails programming.
 
 I created a Devise / Warden strategy to send the cookies to the current 
 system and it will return me the current logged in user. So I can set up 
 Nginx to proxy some requests affected by the Grails bug to this new Rails 
 application.
 
 I've finished this action last Monday but when I was about to send all the 
 hard work to the server lots of my directories were suddenly gone when I was 
 using them. I still don't know what happened but I've replaced my hard-drive 
 just in case, but it means I had to do all over again :(
 
 Anyway, now I got it back to work but testing a single action (an 
 update/insert one) will take about a full second to run using RSpec and 
 FactoryGirl.
 
 I really don't like Grails but they had a great feature for unit testing. 
 They were able to mock their domain class (that is how they call their 
 models) in such a way that they can perform most of the operations you can do 
 on real objects.
 
 Of course it have another serious bug that will prevent me to use it in lots 
 of cases:
 
 http://jira.grails.org/browse/GRAILS-8854
 
 But the idea is great as it works seamlessly like in a memory database.
 
 So, I'd like to be able to keep my tests easy to read but avoid touching the 
 database that much.
 
 But my controller spec rely on lots of the setting of ActiveRecord for my 
 models, like maximum calculations in before callbacks, custom foreign keys 
 and depends: :delete_all in some has_many associations. Also I do also need a 
 user object that Devise will accept on its sign_in helper method.
 
 Is there any place I could read more about writing faster tests without 
 getting crazy writing so many mocks manually. For example, mocking a Grails 
 domain class in a unit test would be as easy as:
 
 @mock(User)
 class UserTests...
 
 Then I'm able to do most operations using the Grails domain class API using 
 the User mock.
 
 Is there something like this for Rails and Rspec? Is there some way that I 
 could set up FactoryGirl to use those mocks instead of hitting the database 
 when I want to?
 
 Am I going in the wrong direction here? If so, what would be the right 
 direction?
 
 Thanks in advance.
 
 Glad to be part of the Ruby, Rails and Rspec community full-time again :D
 
 Cheers,
 Rodrigo.
You can use mock_model or stub_model to create model instances, or you can use 
FactoryGirl.build instead of FactoryGirl.create. Only mock_model will actually 
avoid db calls entirely (the others will still query for column names even if 
you don't save anything).

Those techniques, however, don't help you with finders. You still have to stub 
any finders with the object generated by any of the aforementioned techniques:

thing = mock_model(Thing)
Thing.stub(:domain_specific_finder = [thing])

It's not pretty, but it's the best way I know of to get what you're after. I 
started a lib called stubble a few years back that attempted to address this 
more holistically (https://github.com/dchelimsky/stubble) but I never released 
it as a gem because there were just too many different ways to access model 
data via the ActiveRecord API and they don't all flow through a single part of 
the codebase that we can override in an extension.

HTH,
David

-- 
David Chelimsky
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

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

Re: [rspec-users] Argument Non-Matchers

2012-04-11 Thread David Chelimsky
On Wed, Apr 11, 2012 at 12:18 PM, Matt Hauck mattha...@gmail.com wrote:
 On Tuesday, April 10, 2012 8:48:37 PM UTC-7, Justin Ko wrote:


 On Apr 9, 2012, at 2:41 PM, Matt Hauck wrote:

 Is there a way to specify a message expectation on an object to occur
 _without_ a particular argument?

 There is a particular function, which in some special circumstance takes a
 unique argument, but in normal circumstances does not take this unique
 argument. I want to say something like this:

 it should recognize the special state do

 obj.set_special_state true
 obj.should_receive(:my_method).with(/special_state/)
 obj.my_method

 end
 it should operate fine without the special state do

 obj.set_special_state false
 obj.should_receive(:my_method).without(/special_state/)
 obj.my_method

 end

 This does not appear to be possible to set a non-expectation on an
 argument matcher. Is there a way to do this? Or am I just going about this
 the wrong way?
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users


 Sorry for the late reply. This is what you want:

 http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers:no_args

 Hmm, that's not exactly what I was thinking of... I don't mean that there
 should be no arguments at all, but that the arguments should _not_ be of a
 certain match.


You can do this:

obj.should_receive(:my_method) do |arg|
  arg.should_not match(/special_state/)
end

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


Re: [rspec-users] Error running RSpec on RVM OSX Lion

2012-04-11 Thread David Chelimsky
On Tue, Apr 10, 2012 at 5:28 PM, Ryan Macy ryan.m...@borderjump.com wrote:
 /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/ffi/
 library.rb:121:in `block in ffi_lib': Could not open library '/usr/lib/
 liblpcapi_ssl.so': dlopen(/usr/lib/liblpcapi_ssl.so, 5): image not
 found (LoadError)
        from /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/
 ffi/library.rb:88:in `map'
        from /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/
 ffi/library.rb:88:in `ffi_lib'


 I've tried searching around for the liblpcapi_ssl library with no luck.

I'm not familiar with liblpcapi_ssl, but every line in that backtrace
references ffi. I'd recommend submitting an issue to
https://github.com/ffi/ffi/issues or contacting one of the maintainers
(I don't see a mailing list listed in the project README:
https://github.com/ffi/ffi).

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


Re: [rspec-users] The test is failing Whyy?

2012-04-04 Thread David Chelimsky
On Wed, Apr 4, 2012 at 7:47 AM, Lunarose A. li...@ruby-forum.com wrote:
 I am actually a newbie in Ruby rails nd Rspec.. So it could be something
 basic.. Plz helpp


 This is my rspec test code::

  describe GET new do
    it assigns a new kase as @kase do
      get :new
      assigns(:kase).should be_a_new(Kase)
    end
  end

 Its failing saying:

   KasesController GET new assigns a new kase as @kase
     Failure/Error: assigns(:kase).should be_a_new(Kase)
       expected nil to be a new Kase(id: integer, name: string,
 description: text, item_loc_id: integer, created_at: datetime,
 updated_at: datetime, previous_visit_id_cache: integer)
     # ./spec/controllers/kases_controller_spec.rb:37

This looks like the controller spec generated when you run `rails
generate scaffold ...`. If so, did it fail immediately after
generating it? Or did you change something in the controller since you
generated it? Would you please post the controller code (at least the
:new action)?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] rspec-expectations-2.9.1 is released!

2012-04-03 Thread David Chelimsky
rspec-expectations-2.9.1 is released!

This is a bug-fix only release, and is recommended for everybody using 
rspec-2.9.

### rspec-expectations-2.9.1 / 2012-04-03
[full 
changelog](http://github.com/rspec/rspec-expectations/compare/v2.9.0...2.9.1)

Bug fixes

* Provide a helpful message if the diff between two objects is empty.
* Fix bug diffing single strings with multiline strings.
* Fix for error with using custom matchers inside other custom matchers
 (mirasrael)
* Fix using execution context methods in nested DSL matchers (mirasrael)
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] using shared_context in a global way

2012-04-02 Thread David Chelimsky
On Sun, Apr 1, 2012 at 11:34 PM, Bradley bradleyrobert...@gmail.com wrote:
 I have some let and before declarations that I want to define for all of my
 tests.  I can't seem to figure out how to do this in a clean way (ie by
 including a module in my Rspec config).  I don't want to have to
 include_context for each test, I just want to run some before(:all) hooks
 and provide access to some default variables that example groups could
 override with their own let declarations.

 I must be missing something because I can't find anywhere in the docs how I
 might achieve this.  Any help is greatly appreciated.

There is a documented way to declare a module with let and before
declarations: http://rubydoc.info/gems/rspec-core/RSpec/Core/SharedContext.

There is also a documented way to include a module in every
ExampleGroup: 
http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration#include-instance_method

There is, admittedly, no doc that says you can use these two features
together. Obviously we can't do that for every pair of features, but
perhaps this pair is worth citing specifically. I'll look into doing
that for the next release.

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


Re: [rspec-users] isolating controller tests from models

2012-03-31 Thread David Chelimsky
On Sat, Mar 31, 2012 at 2:49 AM, Justin Ko jko...@gmail.com wrote:

 On Mar 30, 2012, at 11:11 PM, Fearless Fool wrote:

 This is a rehash of a question I posed at:
 http://stackoverflow.com/questions/9952317/isolating-controller-tests-from-models
 The basic question: If I have a FoosController and a Foo model, can I
 run FoosController rspec tests without creating the foos database table?
 I haven't found a good way to avoid it.

 Consider this simple controller:

   # file: app/controllers/foos_controller.rb
   class FoosController  ApplicationController
     respond_to :json
     def create
       @foo = Foo.create(params[:foo])
       respond_with @foo
     end
   end

 In my RSpec tests, I can do

   @foo = mock_model(Foo)
   Foo.stub(:create) { @foo }
   post :create, :format = :json

 ... but that fails in the call to respond_with @foo, because
 ActionController calls @foo.has_errors? which in turn hits the database
 to look up column names.

mock_model is not an ActiveRecord object, so if it's hitting the db
then something's not wired up correctly.

 I could stub out has_errors?, but that means
 that I'm reaching into the internals of the system -- probably not a
 good idea for a test suite.

 Oh, the irony!

 You're using rspec-rails, which reaches *much further* into the system than 
 `has_errors?`.

There's a difference between a library doing this and end-user specs
doing this. They both bear risk, but the burden is on the library
developer (and in one place) if it's the lib, whereas its on all end
users who stray on their own.

 Mucking with a non-public API is not a never ever thing :)

Care to elaborate on what the risks are and when you think it's worth it?

 If the answer to my question can I do controller testing without
 creating the underlying database tables? is 'no', then I'll accept that
 (with regret).  But I'd rather hear that it is somehow possible.

Of course its possible - just a matter of whether its worth it. This
relates to an earlier question which I believe you posted about why
the generated controller specs changed for rails 3. respond_with is
another addition to rails 3 that tightly couples controllers to
models, making it more challenging to stub models in controller specs.
If you're going to violate the mock your code, not other people's
guideline, you might find it safer to do it at a higher level of
abstraction: mock respond_with directly on the controller. Still a
violation of stub/mock guidelines, but at least it deals with code
that you can see and change in the controller.

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


Re: [rspec-users] Why stop using mock_model in scaffold controller spec?

2012-03-29 Thread David Chelimsky
On Tue, Mar 27, 2012 at 9:24 AM, Mike Mazur mma...@gmail.com wrote:
 Hi,

 On Tue, Mar 27, 2012 at 22:10, Mike Mazur mma...@gmail.com wrote:
 In May last year, the controller specs generated with `rspec g
 scaffold` were changed to use real model objects instead of
 `mock_model`.

 I'm curious why this change was made?

 As soon I sent this email off, I noticed this text in the template:

 # Compared to earlier versions of this generator, there is very limited use of
 # stubs and message expectations in this spec.  Stubs are only used when there
 # is no simpler way to get a handle on the object needed for the example.
 # Message expectations are only used when there is no simpler way to specify
 # that an instance is receiving a specific message.

 That explains things a bit, but I'm still curious!

 One might argue that the earlier approach (with `mock_model`) may be
 better for at least two reasons:

 - looser coupling between specs and models
 - faster spec execution (ie: don't have to create a real ActiveRecord 
 instance)

 I imagine RSpec is treading the fine line between ideal best
 practices (ie: minimize coupling) and being more pragmatic and easier
 to understand by the average developer. What's the current thinking on
 this topic?

It wasn't really a loose coupling with models, it was a loose coupling
with the underlying data. It was still very tightly coupled to
ActiveRecord APIs (all, find, etc) because the generated controller
code is coupled to those APIs.

In rails-2, you could stub Model.find, and if you added constraints to
find the specs would still pass because you were still using find. In
rails-3, additional constraints are added via ARel APIs, which don't
end up going through find, so you have to change all the specs when
you change the implementation. This created additional friction which
was annoying to people who understood what was going on, and confusing
for people who didn't.

In terms of the speed benefit, I do think that has merit and I stub
model APIs all the time, but they are domain-specific APIs, not
ActiveRecord APIs (most of the time). e.g. rather than stubbing
Article.where(date = ?, Date.today - 1.week) I'll stub
Article.recent and call that from the controller. This, however, is
not something that a generator can do for you since it doesn't know
your domain.

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


Re: [rspec-users] validating if a cell has any of the options.

2012-03-29 Thread David Chelimsky
On Wed, Mar 28, 2012 at 5:11 PM, Hillary Hueter weimar1...@gmail.com wrote:
 I'm testing the filter on a table. One of the filter options is Show All.
 So for my other tests I've been looping through the rows and seeing if the
 table cell that contains the status doesn't include text (cell.should_not ==
 'Active').

Please post one of these examples so we can see precisely what you're
already doing.

Thx,
David

 However when the filter is set to all it can include any of the three
 statuses (Active, Inactive, Deleted).

 Using any of the rspec matchers how can I validate this?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] [rspec-rails] Mailer tests should be similar to Controller tests

2012-03-29 Thread David Chelimsky
On Mon, Mar 26, 2012 at 7:20 PM, Paulo Luis Franchini Casaretto
pcasare...@gmail.com wrote:
 Hey,

 When I'm testing a controller, I basically test three things.
 Does it assign the variables the view needs?
 Does it render the right template?
 Does it do whatever the action is supposed to do?
 And when testing mailers I feel it should be basically the same.
 Does it assign the variables the view needs?
 Does it render the right template?
 Does it set the right headers?
 I don't want to test the actual mail object, the same way I don't want to
 test the views in controller tests.
 On the other hand, the mail object IS the output of the mailer, so I don't
 know.
 What do you guys think about this?

Seems reasonable, but unlikely to change. Here's why. rspec-rails
provides wrappers around test classes provided by rails. Rails
functional tests support the three questions you pose above, but rails
mailer tests are different. From
http://guides.rubyonrails.org/action_mailer_basics.html: Testing
mailers normally involves two things: One is that the mail was queued,
and the other one that the email is correct.

To support what you'd like to see in mailer specs, rspec-rails would
have to provide it's own ExampleGroup (rather than wrap the rails
class), which would have to be tightly bound to rails' internals. I
took great pains in rspec-rails-2 to constrain coupling to public
APIs, and this has had a big payoff: we've only had one case where a
rails 3.x release required a release of rspec-rails (i.e. there was a
breaking change). With rails-2, pretty much every release broke
rspec-rails because rspec-rails was tied to internals (rspec-rails'
fault, not rails).

If you really want to see this change, you'll need to get it changed
in rails itself, at which point rspec-rails will happily wrap the new
and improved MailerTestCase.

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


Re: [rspec-users] Rspec not loading fixtures

2012-03-26 Thread David Chelimsky
On Thu, Mar 22, 2012 at 9:54 AM, Pito Salas li...@ruby-forum.com wrote:
 I am taking over a code base and am trying to run the tests. I am
 somewhat new to RSpec so this might be a trivial problem.

 Basically I can tell that the fixtures are not getting loaded. All 100
 tests fail with a similar error.

 But I don't know why.  Below is the code, with my narrative with ***
 before it... Can you see anything or give me a clue where to look. So
 far I am coming up empty...

 Thanks!

 Pito Salas

  In spec_helper.rb, which I know is running, I see:

 Spec::Runner.configure do |config|
  config.global_fixtures = :all
 end

  One of the tests in spec/controllers/downloads_controller_spec.rb
 is below. I know it is running and I know that before the 'describe',
 Partner.count == 0, so no fixture.

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

 describe DownloadsController do
  integrate_views

  describe when PDF is ready do
    before(:each) do
      @registrant = Factory.create(:step_5_registrant)
      stub(@registrant).merge_pdf { `touch #{@registrant.pdf_file_path}`
 }
      @registrant.generate_pdf
      @registrant.save!
    end

    it provides a link to download the PDF do
      get :show, :registrant_id = @registrant.to_param
      assert_not_nil assigns[:registrant]
      assert_response :success
      assert_template show
      assert_select span.button a[target=_blank]
      assert_select span.button a[onclick]
    end

    after(:each) do
      `rm #{@registrant.pdf_file_path}`
    end
  end

  And here is what in various directories:

 spec/fixtures/partners.yml - which contains 2 yaml records:

 sponsor:
  id: 1
  username: rtv
  email: ro...@example.com
  crypted_password:
 c8e5b51b237344fe0e72539af0cac7197f094a5e933ffacf6e7fa612363c5933f520710c6427ac31fc4c68a2d7bb48eae601c74b96e7838f9ca1a0740b67576a
  password_salt: Y4PPzYx2ert3vC0OhEMo
  name: Rocky
  organization: Rock The Vote
  url: http://rockthevote.com
  address: 123 Wherever
  city: Washington
  state_id: 9
  zip_code: 20001
  phone: 555-555-1234
  survey_question_1_en: What school did you go to?
  survey_question_2_en: What is your favorite musical group?
  created_at: %= Time.now %
  updated_at: %= Time.now %
 # TODO: remove partner 2 in production
 partner:
  id: 2
  username: bull_winkle
  email: bull_win...@example.com
  crypted_password:
 c8e5b51b237344fe0e72539af0cac7197f094a5e933ffacf6e7fa612363c5933f520710c6427ac31fc4c68a2d7bb48eae601c74b96e7838f9ca1a0740b67576a
  password_salt: Y4PPzYx2ert3vC0OhEMo
  name: Bullwinkle
  organization: Bullwinkle, Inc.
  url: http://example.com
  address: 123 Wherever
  city: Washington
  state_id: 9
  zip_code: 20001
  phone: 555-555-1234
  survey_question_1_en: What school did you go to?
  survey_question_2_en: What is your favorite musical group?
  created_at: %= Time.now %
  updated_at: %= Time.now %


What's the actual failure/error message you're seeing? Also, what
happens when you set `fixtures :users` directly in one of the example
groups e.g.

describe DownloadsController do
  integrate_views
  fixtures :users
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] rspec-rails does execute any tests

2012-03-23 Thread David Chelimsky
On Fri, Mar 23, 2012 at 3:34 AM, Josh Moore j...@resumecompanion.com wrote:
 I  have inherited a rails 2.3.14 application with no tests. I have gotten
 cucumber working but when I try to user rspec will not run any of the test
 cases. These are the first four lines in myspec/spec_helper.rb.

 ENV[RAILS_ENV] ||= 'test'
 require
 File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
 require 'spec/autorun'
 require 'spec/rails'

 When I run bundle exec rake spec it does not have any test cases. But, when
 I remove require 'spec/rails' it runs correctly and the test cases are
 executed. I have looked at all the code and even started digging into the
 rspec-rails gem (rspec-rails 1.3.4 and rspec 1.3.2) but have not found
 anything. Any ideas of what might be going wrong when rspec-rails is used?

What's in the Gemfile?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


  1   2   3   4   5   6   7   8   9   10   >