Re: [rspec-users] RSpec 2, Rails 3, and SSL routes

2010-12-13 Thread Brian Ploetz
Anybody?

On Dec 9, 3:22 pm, Brian Ploetz bplo...@gmail.com wrote:
 Hi all,

 This is probably a stupid question, but I can't figure out how to do
 this.

 If I have some routes which require SSL, how do I test that with
 RSpec? For example:

 # routes.rb
 scope :constraints = { :protocol = https } do
   match '/foos.(:format)' = 'foos#index', :via = :get, :constraints
 = { :format = /(json|xml)/ }
 end

 In my routing spec, I've tried the following variants with no luck:

 describe routing to foos do
   it routes /foos.json to foos#index do
     { :get = /foos.json, :protocol = https }.should route_to(
       :controller = foos,
       :action = index,
       :format = json
     )
   end

 describe routing to foos do
   it routes /foos.json to foos#index do
     { :get = /foos.json }.should route_to(
       :controller = foos,
       :action = index,
       :format = json,
       :protocol = https
     )
   end

 Thanks in advance for any help.
 BP
 ___
 rspec-users mailing list
 rspec-us...@rubyforge.orghttp://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, Rails 3, and SSL routes

2010-12-13 Thread Brian Ploetz
OK, cool. I'll avoid banging my head against the wall in the mean
time. :-)

Thanks alot David.
BP


On Dec 13, 9:16 am, David Chelimsky dchelim...@gmail.com wrote:
 On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote:



  Anybody?

  On Dec 9, 3:22 pm, Brian Ploetz bplo...@gmail.com wrote:
  Hi all,

  This is probably a stupid question, but I can't figure out how to do
  this.

  If I have some routes which require SSL, how do I test that with
  RSpec? For example:

  # routes.rb
  scope :constraints = { :protocol = https } do
    match '/foos.(:format)' = 'foos#index', :via = :get, :constraints
  = { :format = /(json|xml)/ }
  end

  In my routing spec, I've tried the following variants with no luck:

  describe routing to foos do
    it routes /foos.json to foos#index do
      { :get = /foos.json, :protocol = https }.should route_to(
        :controller = foos,
        :action = index,
        :format = json
      )
    end

  describe routing to foos do
    it routes /foos.json to foos#index do
      { :get = /foos.json }.should route_to(
        :controller = foos,
        :action = index,
        :format = json,
        :protocol = https
      )
    end

  Thanks in advance for any help.

 There is an open issue in the Rails tracker about this [1]. 
 assert_recognizes, to which should route_to delegates, does not yet support 
 constraints. Sadly, this means there is no good way to do this at the moment.

 [1]https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_rec...for
  more info.

 ___
 rspec-users mailing list
 rspec-us...@rubyforge.orghttp://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, Rails 3, and SSL routes

2010-12-13 Thread Brian Ploetz
Actually, Rails seems to correctly support *some* routing constraints
in tests (:format being one), but not others (:protocol being one).
I'm coming up with a failing test which I'll attach to that Rails
ticket, but just noting it here as an FYI to others...


On Dec 13, 9:43 am, Brian Ploetz bplo...@gmail.com wrote:
 OK, cool. I'll avoid banging my head against the wall in the mean
 time. :-)

 Thanks alot David.
 BP

 On Dec 13, 9:16 am, David Chelimsky dchelim...@gmail.com wrote:

  On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote:

   Anybody?

   On Dec 9, 3:22 pm, Brian Ploetz bplo...@gmail.com wrote:
   Hi all,

   This is probably a stupid question, but I can't figure out how to do
   this.

   If I have some routes which require SSL, how do I test that with
   RSpec? For example:

   # routes.rb
   scope :constraints = { :protocol = https } do
     match '/foos.(:format)' = 'foos#index', :via = :get, :constraints
   = { :format = /(json|xml)/ }
   end

   In my routing spec, I've tried the following variants with no luck:

   describe routing to foos do
     it routes /foos.json to foos#index do
       { :get = /foos.json, :protocol = https }.should route_to(
         :controller = foos,
         :action = index,
         :format = json
       )
     end

   describe routing to foos do
     it routes /foos.json to foos#index do
       { :get = /foos.json }.should route_to(
         :controller = foos,
         :action = index,
         :format = json,
         :protocol = https
       )
     end

   Thanks in advance for any help.

  There is an open issue in the Rails tracker about this [1]. 
  assert_recognizes, to which should route_to delegates, does not yet 
  support constraints. Sadly, this means there is no good way to do this at 
  the moment.

  [1]https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_rec...more
   info.

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

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


Re: [rspec-users] should raise_error(ArgumentError) resulting in NoMethodError

2010-08-26 Thread Brian Ploetz
*smacks head* Duh.

Thanks David and Rob!


On Aug 26, 12:35 am, Rob Biedenharn r...@agileconsultingllc.com
wrote:
 On Aug 26, 2010, at 12:14 AM, David Chelimsky wrote:



  On Aug 25, 2010, at 10:13 PM, Brian Ploetz wrote:
  Environment
  --
  ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
  rspec (1.3.0)

  Code
  ---
     def currency_to_dollars(currency_amount)
       raise ArgumentError(Currency amount can't be nil) if  
  currency_amount.nil?
     end

  Spec
  
     it should raise an ArgumentError if currency_amount is nil do
       lambda { @service.currency_to_dollars(nil) }.should  
  raise_error(ArgumentError)
     end

  Results in this failure:
  1)
  'Service should raise an ArgumentError if currency_amount is nil'  
  FAILED
  expected ArgumentError, got #NoMethodError: undefined method  
  `ArgumentError' for #Service:0x010087e5f0

  This message is telling you there is no ArgumentError method, not  
  that the constant ArgumentError is missing. The method needs to be  
  (adding .new):

     def currency_to_dollars(currency_amount)
       raise ArgumentError.new(Currency amount can't be nil) if  
  currency_amount.nil?
     end

 You might see this form, too.

     def currency_to_dollars(currency_amount)
       raise ArgumentError, Currency amount can't be nil if  
 currency_amount.nil?
     end

 Note the comma that separates the arguments to raise (Kernel#raise).

 -Rob





  test/spec/service_spec.rb:92:in `block (2 levels) in top  
  (required)'

  Changing the test to either of these two variants allows the the to  
  pass:

     lambda { @service.currency_to_dollars(nil) }.should  
  raise_error(StandardError)
     lambda { @service.currency_to_dollars(nil) }.should raise_error

  These pass because NoMethodError, which is what is being thrown, is  
  a subclass of StandardError and Exception.

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

 Rob Biedenharn          
 r...@agileconsultingllc.com  http://AgileConsultingLLC.com/
 r...@gaslightsoftware.com            http://GaslightSoftware.com/

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


[rspec-users] should raise_error(ArgumentError) resulting in NoMethodError

2010-08-25 Thread Brian Ploetz
Environment
--
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
rspec (1.3.0)

Code
---
def currency_to_dollars(currency_amount)
  raise ArgumentError(Currency amount can't be nil) if
currency_amount.nil?
end

Spec

it should raise an ArgumentError if currency_amount is nil do
  lambda { @service.currency_to_dollars(nil) }.should
raise_error(ArgumentError)
end

Results in this failure:
1)
'Service should raise an ArgumentError if currency_amount is nil' FAILED
expected ArgumentError, got #NoMethodError: undefined method
`ArgumentError' for #Service:0x010087e5f0
test/spec/service_spec.rb:92:in `block (2 levels) in top (required)'


Changing the test to either of these two variants allows the the to pass:

lambda { @service.currency_to_dollars(nil) }.should
raise_error(StandardError)
lambda { @service.currency_to_dollars(nil) }.should raise_error

Why am I unable to test for a specific StandardError subclass?

Thanks in advance for any help.
BP
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] should raise_error(ArgumentError) resulting in NoMethodError

2010-08-25 Thread Brian Ploetz
FYI, the same thing happens with rspec 2.0.0.beta.20 as well:

  1) Service should raise an ArgumentError if currency_amount is nil
 Failure/Error: lambda
{ @service.currency_to_dollars(nil) }.should
raise_error(ArgumentError)
 expected ArgumentError, got #NoMethodError: undefined method
`ArgumentError' for #Service:0x01029665d8
 # ./test/spec/service_spec.rb:92:in `block (2 levels) in top
(required)'



On Aug 25, 11:13 pm, Brian Ploetz bplo...@gmail.com wrote:
 Environment
 --
 ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
 rspec (1.3.0)

 Code
 ---
     def currency_to_dollars(currency_amount)
       raise ArgumentError(Currency amount can't be nil) if
 currency_amount.nil?
     end

 Spec
 
     it should raise an ArgumentError if currency_amount is nil do
       lambda { @service.currency_to_dollars(nil) }.should
 raise_error(ArgumentError)
     end

 Results in this failure:
 1)
 'Service should raise an ArgumentError if currency_amount is nil' FAILED
 expected ArgumentError, got #NoMethodError: undefined method
 `ArgumentError' for #Service:0x010087e5f0
 test/spec/service_spec.rb:92:in `block (2 levels) in top (required)'

 Changing the test to either of these two variants allows the the to pass:

     lambda { @service.currency_to_dollars(nil) }.should
 raise_error(StandardError)
     lambda { @service.currency_to_dollars(nil) }.should raise_error

 Why am I unable to test for a specific StandardError subclass?

 Thanks in advance for any help.
 BP

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