From ekampp at gmail.com Sun Jan 1 12:14:51 2012 From: ekampp at gmail.com (ekampp) Date: Sun, 1 Jan 2012 09:14:51 -0800 (PST) Subject: [rspec-users] Testing dragonfly image attachment. Message-ID: <35c38d3d-3c45-4e20-9fba-d0daca5bec03@f33g2000yqh.googlegroups.com> Hi people. I have the following problem when testing a project model with an attached dragonfly logo: When building a project test record through factory girl the project seems valid, but testing `project.should be_valid` fails. I have tried printing the errors array to check, but there seems to be no errors present on the project object. So what is the deal? Am I simply missing something? I have posted my code snippets below, and I would appreciate any input you have, that could point me towards a solution. # project.rb class Project include Mongoid::Document include Mongoid::Slug include Mongoid::Timestamps field :logo_uid field :name field :description field :url field :featured, :type => Boolean, :default => false field :done_back_end, :type => Boolean, :default => false field :done_front_end, :type => Boolean, :default => false field :done_concept, :type => Boolean, :default => false field :done_design, :type => Boolean, :default => false field :done_identity, :type => Boolean, :default => false slug :name image_accessor :logo attr_accessible :name, :description, :new_file, :logo, :url, :featured, :done_back_end, :done_front_end, :done_concept, :done_design, :done_identity belongs_to :user embeds_many :project_images validates :logo, :presence => true, :on => :create validates :name, :presence => true validates :name, :uniqueness => true scope :featured, where(:featured => true) end # project_spec.rb require 'spec_helper' describe Project do let(:project) { Factory.build(:project) } context "validations" do it "should be valid when build" do project.should be_valid end end end # factories.rb FactoryGirl.define do factory :project do name Faker::Name.name description Faker::Lorem.paragraphs url Faker::Internet.domain_name user Factory.build(:user) project_images [Factory.build(:project_image), Factory.build(:project_image)] logo "#{Rails.root}/spec/assets/test-image.jpg" # This image exists end end From mcha226 at gmail.com Thu Jan 5 04:26:22 2012 From: mcha226 at gmail.com (m) Date: Thu, 5 Jan 2012 01:26:22 -0800 (PST) Subject: [rspec-users] Can I set subject to its own method call? Message-ID: <1f137b9d-4f32-4bee-b98f-3a52e1f5062e@p16g2000yqd.googlegroups.com> The symbol "subject" by default is an instance of the described class. In some method testing I often want to set the subject to be a method call to the instance, for example "city.parse_input()". I tried to do describe '#parse_input' do subject{ subject.parse_input() } #returns hash ... end but I can't. I want to ask where did I get the semantic of this subject command wrong which prevent me from doing this. Thanks. From andrew at andrewtimberlake.com Thu Jan 5 11:31:59 2012 From: andrew at andrewtimberlake.com (Andrew Timberlake) Date: Thu, 5 Jan 2012 18:31:59 +0200 Subject: [rspec-users] Can I set subject to its own method call? In-Reply-To: <1f137b9d-4f32-4bee-b98f-3a52e1f5062e@p16g2000yqd.googlegroups.com> References: <1f137b9d-4f32-4bee-b98f-3a52e1f5062e@p16g2000yqd.googlegroups.com> Message-ID: <999450239A254D4AAB89D48F430C5D72@andrewtimberlake.com> Why don't you use let: describe MyClass do # Will set subject to an instance of MyClass context '#parse_input' do let(:input) { subject.parse_input } # calling input in your specs will now return the result of parse_input it 'is a hash' do input.should be_a(Hash) # This evaluates let(:input) end end end Hope that helps. Andrew On Thursday 05 January 2012 at 11:26 AM, m wrote: > The symbol "subject" by default is an instance of the described class. > In some method testing I often want to set the subject to be a method > call to the instance, for example "city.parse_input()". > > I tried to do > > describe '#parse_input' do > subject{ subject.parse_input() } #returns hash > ... > end > > but I can't. > > I want to ask where did I get the semantic of this subject command > wrong which prevent me from doing this. Thanks. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > http://rubyforge.org/mailman/listinfo/rspec-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From apnea.diving.deep at gmail.com Thu Jan 5 18:45:42 2012 From: apnea.diving.deep at gmail.com (apneadiving) Date: Thu, 5 Jan 2012 15:45:42 -0800 (PST) Subject: [rspec-users] why is 'get :index, :page => 2' different from 'get :index, :page => "2"' Message-ID: Hi, After coding my app and enjoying a green wave of tests, I had horrible feedback about some bugs. Those bugs happened to some well tested parts of my app. After some research, I found out that get :index, :page => 2, :per_page => 5 is different from: get :index, :page => "2", :per_page => "5" So I simply missed some 'to_i' in my controller. I thought, the 'get' parameters would have been stringified, like it is in a standard request. Why is it not the case? From dchelimsky at gmail.com Thu Jan 5 18:55:03 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 5 Jan 2012 17:55:03 -0600 Subject: [rspec-users] why is 'get :index, :page => 2' different from 'get :index, :page => "2"' In-Reply-To: References: Message-ID: On Thu, Jan 5, 2012 at 5:45 PM, apneadiving wrote: > Hi, > > After coding my app and enjoying a green wave of tests, I had horrible > feedback about some bugs. > > Those bugs happened to some well tested parts of my app. > > After some research, I found out that > > get :index, :page => 2, :per_page => 5 > > is different from: > > get :index, :page => "2", :per_page => "5" > > So I simply missed some 'to_i' in my controller. > > I thought, the 'get' parameters would have been stringified, like it > is in a standard request. That's what I thought too! https://github.com/rails/rails/pull/1203 > > Why is it not the case? It is, depending on what version of Rails you're using. Don't remember which version included my patch(es), but I *think* it was 3.1. HTH, David From apnea.diving.deep at gmail.com Thu Jan 5 19:08:19 2012 From: apnea.diving.deep at gmail.com (apneadiving) Date: Thu, 5 Jan 2012 16:08:19 -0800 (PST) Subject: [rspec-users] why is 'get :index, :page => 2' different from 'get :index, :page => "2"' In-Reply-To: References: Message-ID: <9c4dd248-85d5-494f-8057-c53d5301bbfc@z19g2000vbe.googlegroups.com> On Jan 6, 12:55?am, David Chelimsky wrote: > On Thu, Jan 5, 2012 at 5:45 PM, apneadiving wrote: > > Hi, > > > After coding my app and enjoying a green wave of tests, I had horrible > > feedback about some bugs. > > > Those bugs happened to some well tested parts of my app. > > > After some research, I found out that > > > get :index, :page => 2, :per_page => 5 > > > is different from: > > > get :index, :page => "2", :per_page => "5" > > > So I simply missed some 'to_i' in my controller. > > > I thought, the 'get' parameters would have been stringified, like it > > is in a standard request. > > That's what I thought too! > > https://github.com/rails/rails/pull/1203 > > > > > Why is it not the case? > > It is, depending on what version of Rails you're using. Don't remember > which version included my patch(es), but I *think* it was 3.1. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users You definitely rock. Thanks a bunch for this neat & quick answer :) From mcha226 at gmail.com Thu Jan 5 20:21:49 2012 From: mcha226 at gmail.com (m) Date: Thu, 5 Jan 2012 17:21:49 -0800 (PST) Subject: [rspec-users] Can I set subject to its own method call? In-Reply-To: <999450239A254D4AAB89D48F430C5D72@andrewtimberlake.com> References: <1f137b9d-4f32-4bee-b98f-3a52e1f5062e@p16g2000yqd.googlegroups.com> <999450239A254D4AAB89D48F430C5D72@andrewtimberlake.com> Message-ID: <415e2de1-1766-43ac-a965-2cb4cc786923@u6g2000vbc.googlegroups.com> Thanks, I was using another way before until I properly read through the rspec doc. I was doing this in another example: let(:instance) { described_class.new() } describe ' subject { instance.parse_log() } its([:duration]){ should == mock_duration} its([:owner]){ should == mock_editor} I guess it just feels more natural to me to put the describe method call in the center of the spec, which is the subject. And it is more abbreviated (I don't have to put a shoulda in a it block which is three lines). On 1?6?, ??12?31?, Andrew Timberlake wrote: > Why don't you use let: > > describe MyClass do ? ? ? ? ? ? ? ? ? ? ? ? # Will set subject to an instance of MyClass > ? context '#parse_input' do > ? ? let(:input) { subject.parse_input } ? ? # calling input in your specs will now return the result of parse_input > > ? ? it 'is a hash' do > ? ? ? input.should be_a(Hash) ? ? ? ? ? ? ?# This evaluates let(:input) > ? ? end > ? end > end > > Hope that helps. > > Andrew > > On Thursday 05 January 2012 at 11:26 AM, m wrote: > > > > > > > > > The symbol "subject" by default is an instance of the described class. > > In some method testing I often want to set the subject to be a method > > call to the instance, for example "city.parse_input()". > > > I tried to do > > > describe '#parse_input' do > > subject{ subject.parse_input() } #returns hash > > ... > > end > > > but I can't. > > > I want to ask where did I get the semantic of this subject command > > wrong which prevent me from doing this. Thanks. > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org (mailto:rspec-us... at rubyforge.org) > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Fri Jan 6 17:49:27 2012 From: lists at ruby-forum.com (Gayle C.) Date: Fri, 06 Jan 2012 23:49:27 +0100 Subject: [rspec-users] where does cucumber.yml live? In-Reply-To: <57c63afe0903050927k39e1caabj887df484e67a72e8@mail.gmail.com> References: <57c63afe0903050645n7d4a580bo2606baef85e6429f@mail.gmail.com> <8d961d900903050855h28dab74bof0f1d0d0d3cade33@mail.gmail.com> <57c63afe0903050927k39e1caabj887df484e67a72e8@mail.gmail.com> Message-ID: David Chelimsky wrote in post #790531: >> http://wiki.github.com/aslakhellesoy/cucumber/running-features > > Since ppl are having a hard time finding this, I added > http://wiki.github.com/aslakhellesoy/cucumber/cucumberyml, which > references > http://wiki.github.com/aslakhellesoy/cucumber/running-features. I know this post is from a few years ago, and so these links are broken now. Any updated links have the same information? -- Posted via http://www.ruby-forum.com/. From jko170 at gmail.com Fri Jan 6 18:03:51 2012 From: jko170 at gmail.com (Justin Ko) Date: Fri, 6 Jan 2012 16:03:51 -0700 Subject: [rspec-users] where does cucumber.yml live? In-Reply-To: References: <57c63afe0903050645n7d4a580bo2606baef85e6429f@mail.gmail.com> <8d961d900903050855h28dab74bof0f1d0d0d3cade33@mail.gmail.com> <57c63afe0903050927k39e1caabj887df484e67a72e8@mail.gmail.com> Message-ID: <01ACFB5B-71C8-4F73-9805-83B10EE769D2@gmail.com> On Jan 6, 2012, at 3:49 PM, Gayle C. wrote: > David Chelimsky wrote in post #790531: >>> http://wiki.github.com/aslakhellesoy/cucumber/running-features >> >> Since ppl are having a hard time finding this, I added >> http://wiki.github.com/aslakhellesoy/cucumber/cucumberyml, which >> references >> http://wiki.github.com/aslakhellesoy/cucumber/running-features. > > > I know this post is from a few years ago, and so these > links are broken now. Any updated links have the same information? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users All I see is links to Cucumber. Maybe try the Cucumber mailing list? From ash.moran at patchspace.co.uk Fri Jan 6 18:28:11 2012 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Fri, 6 Jan 2012 23:28:11 +0000 Subject: [rspec-users] where does cucumber.yml live? In-Reply-To: <01ACFB5B-71C8-4F73-9805-83B10EE769D2@gmail.com> References: <57c63afe0903050645n7d4a580bo2606baef85e6429f@mail.gmail.com> <8d961d900903050855h28dab74bof0f1d0d0d3cade33@mail.gmail.com> <57c63afe0903050927k39e1caabj887df484e67a72e8@mail.gmail.com> <01ACFB5B-71C8-4F73-9805-83B10EE769D2@gmail.com> Message-ID: On 6 Jan 2012, at 23:03, Justin Ko wrote: > All I see is links to Cucumber. Maybe try the Cucumber mailing list? I'm curious - why after all these years do so many Cucumber-related issues still get posted on the RSpec list? Is there an outdated FAQ lurking somewhere? Ash -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From lists at iDIAcomputing.com Fri Jan 6 19:45:35 2012 From: lists at iDIAcomputing.com (George Dinwiddie) Date: Fri, 06 Jan 2012 19:45:35 -0500 Subject: [rspec-users] where does cucumber.yml live? In-Reply-To: References: <57c63afe0903050645n7d4a580bo2606baef85e6429f@mail.gmail.com> <8d961d900903050855h28dab74bof0f1d0d0d3cade33@mail.gmail.com> <57c63afe0903050927k39e1caabj887df484e67a72e8@mail.gmail.com> Message-ID: <4F0795AF.6030300@iDIAcomputing.com> Gayle, I've set a reply-to pointing to the cucumber list. I'd advise going to http://groups.google.com/group/cukes and joining that list. On 1/6/12 5:49 PM, Gayle C. wrote: > David Chelimsky wrote in post #790531: >>> http://wiki.github.com/aslakhellesoy/cucumber/running-features >> >> Since ppl are having a hard time finding this, I added >> http://wiki.github.com/aslakhellesoy/cucumber/cucumberyml, which >> references >> http://wiki.github.com/aslakhellesoy/cucumber/running-features. > > > I know this post is from a few years ago, and so these > links are broken now. Any updated links have the same information? https://github.com/cucumber/cucumber/wiki/cucumber.yml https://github.com/cucumber/cucumber/wiki/Running-Features - George -- ---------------------------------------------------------------------- * George Dinwiddie * http://blog.gdinwiddie.com Software Development http://www.idiacomputing.com Consultant and Coach http://www.agilemaryland.org ---------------------------------------------------------------------- From josemota.net at gmail.com Sat Jan 7 10:00:51 2012 From: josemota.net at gmail.com (=?iso-8859-1?Q?Jos=E9_Mota?=) Date: Sat, 7 Jan 2012 15:00:51 +0000 Subject: [rspec-users] Design love for rspec.info Message-ID: <31325A32-A095-4C76-87C9-255F0F6281DB@gmail.com> Hi everyone, I would like to help on designing rspec.info. What can I do to begin? Thank you. Best, -- Jos? Mota www.josemota.net From fabricio.foruria at globant.com Fri Jan 6 22:16:24 2012 From: fabricio.foruria at globant.com (Fabricio Foruria) Date: Sat, 7 Jan 2012 00:16:24 -0300 Subject: [rspec-users] Help for a project Message-ID: Hi David, I am reading your book about Rspec because I am starting a framework from scratch for my job for a big client (american express).. and I would like ask you some question regarding some things I would like accomplish but I don`t undestand how could be done. Please let me know if you don`t mind I do those questions.. No problem if you are super busy and cannot reply soon. Cheers, Fabricio Foruria, Argentina -- ** *Fabricio **Foruria** **Globant **- Test Automation** * AR: +54 11 4109 1700 ext 8078 US: +1 877 798 8104 ext. 8078 -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Jan 7 19:13:23 2012 From: lists at ruby-forum.com (Daniel D.) Date: Sun, 08 Jan 2012 01:13:23 +0100 Subject: [rspec-users] warning: toplevel constant XYZ referenced Admin:XYZ In-Reply-To: References: Message-ID: Someone made some sense out of this. http://code.dblock.org/warning-toplevel-constant-xyz-referenced-adminxyz -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Jan 8 15:18:00 2012 From: lists at ruby-forum.com (umair iqbal) Date: Sun, 08 Jan 2012 21:18:00 +0100 Subject: [rspec-users] Rspec for this class Message-ID: <0312b8821838340dd810e65cb9c190a4@ruby-forum.com> Hi All I am new to rspec. How can I write specs for this class Anyone please provide me the detail specs for this class thanks module Sitemap class Job def initialize(country_version, directory, country_host) @country_version = country_version @directory = directory @country_host = country_host @locale = country_version.name end def get_data ::Function.find_each(:conditions => {:country_version_id => @country_version.id}) do |function| ::Job.find_each(:conditions => {:country_version_id => @country_version.id, :function_id => function.id}) do |job| I18n.locale=(@locale) yield entry(job) end end end private def entry(job) { :loc => ActionController::Integration::Session.new.url_for(:controller => 'jobs', :action => 'show', :title_urlified_with_job_ref_id => job.title_urlified + "-" + job.id.to_s, :host => @country_host.value), :changefreq => 0.8, :priority => 'monthly', :lastmod => job.updated_at } end end end -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Sun Jan 8 16:51:41 2012 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 8 Jan 2012 21:51:41 +0000 Subject: [rspec-users] Rspec for this class In-Reply-To: <0312b8821838340dd810e65cb9c190a4@ruby-forum.com> References: <0312b8821838340dd810e65cb9c190a4@ruby-forum.com> Message-ID: On Sun, Jan 8, 2012 at 8:18 PM, umair iqbal wrote: > Hi All > I am new to rspec. How can I write specs for this class > Anyone please provide me the detail specs for this class > thanks > Start by asking yourself what this class does. Then try to come up with an example. Then, think about what the initial state of this example is, what happens and what you expect the end result/state to be. Now, implement that in a spec. If all of this sounds hard, there is a more detailed description in http://pragprog.com/book/achbd/the-rspec-book Aslak > module Sitemap > ?class Job > > ? ?def initialize(country_version, directory, country_host) > ? ? ?@country_version = country_version > ? ? ?@directory = directory > ? ? ?@country_host = country_host > ? ? ?@locale = country_version.name > ? ?end > > ? ?def get_data > ? ? ?::Function.find_each(:conditions => {:country_version_id => > @country_version.id}) do |function| > ? ? ? ?::Job.find_each(:conditions => {:country_version_id => > @country_version.id, :function_id => function.id}) do |job| > ? ? ? ? ?I18n.locale=(@locale) > ? ? ? ? ?yield entry(job) > ? ? ? ?end > ? ? ?end > ? ?end > > ? ?private > ? ?def entry(job) > ? ? ?{ > ? ? ? ?:loc => > ActionController::Integration::Session.new.url_for(:controller => > 'jobs', :action => 'show', :title_urlified_with_job_ref_id => > job.title_urlified + "-" + job.id.to_s, :host => @country_host.value), > ? ? ? ?:changefreq => 0.8, > ? ? ? ?:priority => 'monthly', > ? ? ? ?:lastmod => job.updated_at > ? ? ?} > ? ?end > ?end > end > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From cjunk at voltz.ws Mon Jan 9 10:33:20 2012 From: cjunk at voltz.ws (Christopher Voltz) Date: Mon, 09 Jan 2012 09:33:20 -0600 Subject: [rspec-users] RSpec mock question Message-ID: <4F0B08C0.8070409@voltz.ws> How can I mock the XMLRPC::Client.new3 class method using rspec's mock? I expected this spec: describe Foo do it 'should call new3' do options = {} XMLRPC::Client.any_instance.should_receive(:new3).with(options) Foo.new(options) end end with this class definition: class Foo def new(options) @server = XMLRPC::Client.new3(options) end end to pass but instead I got the error: 1) Foo should call new 3 Failure/Error: Unable to find matching line from backtrace Exactly one instance should have received the following message(s) but didn't: new3 How can I change the spec to make this pass (while verifying that new3 was called)? Thanks, Christopher From patrick at collinatorstudios.com Mon Jan 9 12:46:07 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 9 Jan 2012 09:46:07 -0800 (PST) Subject: [rspec-users] RSpec mock question In-Reply-To: <4F0B08C0.8070409@voltz.ws> References: <4F0B08C0.8070409@voltz.ws> Message-ID: > 1) Foo should call new 3 > Failure/Error: Unable to find matching line from backtrace > Exactly one instance should have received the following > message(s) but didn't: new3 > > How can I change the spec to make this pass (while verifying that new3 > was called)? > This probably isn't working because .new3 is a class method, and you are setting an expectation for an instance method to be called. The way I would do this would be something like: client = stub("XMLRPC::Client", :new3 => true) XMLPRC::Client.should_receive(:new3).with(options).and_return(client) Patrick J. Collins http://collinatorstudios.com From cjunk at voltz.ws Mon Jan 9 14:15:24 2012 From: cjunk at voltz.ws (Christopher Voltz) Date: Mon, 09 Jan 2012 13:15:24 -0600 Subject: [rspec-users] RSpec mock question In-Reply-To: References: <4F0B08C0.8070409@voltz.ws> Message-ID: <4F0B3CCC.2040509@voltz.ws> I knew it was a class method but wasn't sure how to put an expectation on a class method. I tried your suggestion but, unfortunately, it still fails, although with a different error message: 1) Foo should call new 3 Failure/Error: XMLRPC::Client.should_receive(:new3).with(options).and_return(client) ().new3({:host=>"host.com", :path=>"xmlrpc.php", :port=>"80", :user=>"username", :password=>"password"}) expected: 1 time received: 0 times Any other suggestions? Thanks for your help, Christopher On 01/09/2012 11:46 AM, Patrick J. Collins wrote: >> 1) Foo should call new 3 >> Failure/Error: Unable to find matching line from backtrace >> Exactly one instance should have received the following >> message(s) but didn't: new3 >> >> How can I change the spec to make this pass (while verifying that new3 >> was called)? >> > This probably isn't working because .new3 is a class method, and you are > setting an expectation for an instance method to be called. The way I > would do this would be something like: > > client = stub("XMLRPC::Client", :new3 => true) > XMLPRC::Client.should_receive(:new3).with(options).and_return(client) > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjunk at voltz.ws Mon Jan 9 14:45:53 2012 From: cjunk at voltz.ws (Christopher Voltz) Date: Mon, 09 Jan 2012 13:45:53 -0600 Subject: [rspec-users] RSpec mock question In-Reply-To: <4F0B3CCC.2040509@voltz.ws> References: <4F0B08C0.8070409@voltz.ws> <4F0B3CCC.2040509@voltz.ws> Message-ID: <4F0B43F1.1080505@voltz.ws> I got it working. I had defined new on Foo rather than initialize so it was my dumb mistake that prevented your solution from working. Thanks a lot for your help Patrick. Christopher On 01/09/2012 01:15 PM, Christopher Voltz wrote: > I knew it was a class method but wasn't sure how to put an expectation > on a class method. I tried your suggestion but, unfortunately, it > still fails, although with a different error message: > > 1) Foo should call new 3 > Failure/Error: > XMLRPC::Client.should_receive(:new3).with(options).and_return(client) > ().new3({:host=>"host.com", > :path=>"xmlrpc.php", :port=>"80", :user=>"username", > :password=>"password"}) > expected: 1 time > received: 0 times > > Any other suggestions? > > Thanks for your help, > Christopher > > On 01/09/2012 11:46 AM, Patrick J. Collins wrote: >>> 1) Foo should call new 3 >>> Failure/Error: Unable to find matching line from backtrace >>> Exactly one instance should have received the following >>> message(s) but didn't: new3 >>> >>> How can I change the spec to make this pass (while verifying that new3 >>> was called)? >>> >> This probably isn't working because .new3 is a class method, and you are >> setting an expectation for an instance method to be called. The way I >> would do this would be something like: >> >> client = stub("XMLRPC::Client", :new3 => true) >> XMLPRC::Client.should_receive(:new3).with(options).and_return(client) >> >> Patrick J. Collins >> http://collinatorstudios.com >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon Jan 9 18:37:47 2012 From: lists at ruby-forum.com (Benito S.) Date: Tue, 10 Jan 2012 00:37:47 +0100 Subject: [rspec-users] view_context in specs In-Reply-To: References: Message-ID: <862065b793e7e90d1a633a8c7a34ecf7@ruby-forum.com> If you put this on your spec_helper.rb //If you have your spec in the directory "spec/presenters" config.include ActionView::TestCase::Behavior, example_group: {file_path: %r{spec/presenters}} Then you can use a method, :view, that you can use as the view context like this let(:profile) { ProfilePresenter.new(@user, view) } ....... There is a Railscast about it. -- Posted via http://www.ruby-forum.com/. From antsmailinglist at gmail.com Tue Jan 10 08:21:08 2012 From: antsmailinglist at gmail.com (Ants Pants) Date: Tue, 10 Jan 2012 14:21:08 +0100 Subject: [rspec-users] Problems using config.extend(Macro) Message-ID: Happy New Year everyone!! I'm having a painful upgrade from Rails 2.3.11 to Rails 3.1.3 and one of the problems is with the following.... Under Ruby 1.8.7 - Rails 2.3.11 - Rspec 1: I have model_macros.rb under spec/spec_helpers and it runs beautifully. Dir[File.expand_path(File.join(File.dirname(__FILE__), 'spec_helpers', '**', '*.rb'))].each { require f } config.extend(ModelMacros, :type => :model) Exactly the same code under Ruby 1.9.2 - Rails 3.1.3 - Rspec 2 gives me ... uninitialized constant ModelMacros (NameError) Dir[Rails.root.join("spec/spec_helpers/**/*.rb")].each {|f| require f} config.extend(ModelMacros, :type => :model) .... which makes sense as it's missing the namespace (but how did it run under 2.3.11. Is Ruby 1.8.7 more lenient? - I doubt it) So I added the namespace and I got rid of that error config.extend(SpecHelpers::ModelMacros, :type => :model) But sadly the methods that are called from within the model specs are unable to be found...... Exception encountered: # :model) but to no avail. Any help would be great, thank you. -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Jan 10 08:56:34 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 10 Jan 2012 07:56:34 -0600 Subject: [rspec-users] Problems using config.extend(Macro) In-Reply-To: References: Message-ID: <469696E8-5F41-4B79-9790-7A42A6835172@gmail.com> On Jan 10, 2012, at 7:21 AM, Ants Pants wrote: > Under Ruby 1.8.7 - Rails 2.3.11 - Rspec 1: > > I have model_macros.rb under spec/spec_helpers and it runs beautifully. > > Dir[File.expand_path(File.join(File.dirname(__FILE__), 'spec_helpers', '**', '*.rb'))].each { require f } > config.extend(ModelMacros, :type => :model) > > Exactly the same code under Ruby 1.9.2 - Rails 3.1.3 - Rspec 2 gives me ... uninitialized constant ModelMacros (NameError) > > Dir[Rails.root.join("spec/spec_helpers/**/*.rb")].each {|f| require f} > config.extend(ModelMacros, :type => :model) > > .... which makes sense as it's missing the namespace (but how did it run under 2.3.11. Is Ruby 1.8.7 more lenient? - I doubt it) That would make sense if Rails was autoloading (implicit) this, but it's not - spec_helper.rb is loading it explicitly. I think the namespace thing is a red herring. > So I added the namespace and I got rid of that error > > config.extend(SpecHelpers::ModelMacros, :type => :model) > > But sadly the methods that are called from within the model specs are unable to be found...... Exception encountered: # > This is only solved by including extend SpecHelpers::ModelMacros in the model spec file. Not what I want. Which suggests that the config is being silently ignored, even though the loading is working. > Is there something I am missing while migrating all my code? Is there some really basic Ruby thing I have forgotten to do to get this module included? > > I also tried config.include(SpecHelpers::ModelMacros, :type => :model) but to no avail. That would never have worked under any version because "include" exposes methods to the example scope, not the group scope: describe "something" do # methods in modules added using extend are available here it "does something" do # methods in modules added using include are available here end end > Any help would be great, thank you. My best guess is that you don't need the namespace, and you should leave Rails out of loading this. Try this: Dir["spec_helpers/**/*.rb"].each {|f| require f} RSpec.configure do |config| config.extend(ModelMacros, :type => :model) end That should work to load the file, since RSpec adds"./spec" to the $LOAD_PATH. If that doesn't work, it might be that ":type => :model" isn't working correctly, so try "path => /spec\/model/" instead. Please report back and let us know which, if either, works for you. HTH, David From antsmailinglist at gmail.com Tue Jan 10 11:30:37 2012 From: antsmailinglist at gmail.com (Ants Pants) Date: Tue, 10 Jan 2012 17:30:37 +0100 Subject: [rspec-users] Problems using config.extend(Macro) In-Reply-To: <469696E8-5F41-4B79-9790-7A42A6835172@gmail.com> References: <469696E8-5F41-4B79-9790-7A42A6835172@gmail.com> Message-ID: On 10 January 2012 14:56, David Chelimsky wrote: > On Jan 10, 2012, at 7:21 AM, Ants Pants wrote: > > > Under Ruby 1.8.7 - Rails 2.3.11 - Rspec 1: > > > > I have model_macros.rb under spec/spec_helpers and it runs beautifully. > > > > Dir[File.expand_path(File.join(File.dirname(__FILE__), 'spec_helpers', > '**', '*.rb'))].each { require f } > > config.extend(ModelMacros, :type => :model) > > > > Exactly the same code under Ruby 1.9.2 - Rails 3.1.3 - Rspec 2 gives me > ... uninitialized constant ModelMacros (NameError) > > > > Dir[Rails.root.join("spec/spec_helpers/**/*.rb")].each {|f| require f} > > config.extend(ModelMacros, :type => :model) > > > > .... which makes sense as it's missing the namespace (but how did it run > under 2.3.11. Is Ruby 1.8.7 more lenient? - I doubt it) > > That would make sense if Rails was autoloading (implicit) this, but it's > not - spec_helper.rb is loading it explicitly. I think the namespace thing > is a red herring. > > > So I added the namespace and I got rid of that error > > > > config.extend(SpecHelpers::ModelMacros, :type => :model) > > > > But sadly the methods that are called from within the model specs are > unable to be found...... Exception encountered: # method `it_should_require_attributes' > > > > This is only solved by including extend SpecHelpers::ModelMacros in the > model spec file. Not what I want. > > Which suggests that the config is being silently ignored, even though the > loading is working. > > > Is there something I am missing while migrating all my code? Is there > some really basic Ruby thing I have forgotten to do to get this module > included? > > > > I also tried config.include(SpecHelpers::ModelMacros, :type => :model) > but to no avail. > > That would never have worked under any version because "include" exposes > methods to the example scope, not the group scope: > > describe "something" do > # methods in modules added using extend are available here > it "does something" do > # methods in modules added using include are available here > end > end > > > Any help would be great, thank you. > > My best guess is that you don't need the namespace, and you should leave > Rails out of loading this. Try this: > > Dir["spec_helpers/**/*.rb"].each {|f| require f} > RSpec.configure do |config| > config.extend(ModelMacros, :type => :model) > end > > That should work to load the file, since RSpec adds"./spec" to the > $LOAD_PATH. > > If that doesn't work, it might be that ":type => :model" isn't working > correctly, so try "path => /spec\/model/" instead. Please report back and > let us know which, if either, works for you. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hey David, thanks for the reply. Sadly nothing worked and here are my results With .... Dir["spec_helpers/**/*.rb"].each {|f| puts "loading ... #{f}"; require f} I didn't find any file to load and got the following error.... /home/anthony/Development/websites/ruby/GMFT/spec/spec_helper.rb:84:in `block in ': uninitialized constant ModelMacros (NameError) With .... Dir["spec/spec_helpers/**/*.rb"].each {|f| puts "loading ... #{f}"; require f} I found a file to load but require couldn't find it .... loading ... spec/spec_helpers/model_macros.rb /home/anthony/.rvm/gems/ruby-1.9.2-p290 at gmft313/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require': no such file to load -- spec/spec_helpers/model_macros.rb (LoadError) With .... Dir[Rails.root.join("spec/spec_helpers/**/*.rb")].each {|f| puts "loading ... #{f}"; require f} I found a file to load, apparently it loaded it but then the ModelMacros#method could not be found.... loading ... /home/anthony/Development/websites/ruby/GMFT/spec/spec_helpers/model_macros.rb /home/anthony/Development/websites/ruby/GMFT/spec/model/event_group_spec.rb:27:in `block in ': undefined method `it_should_require_attributes' for # (NoMethodError I also tried with :path in the third example but nada. I've also tried all of the above running rspec 2.7.0 and rspec-rails 2.7.0. No joy. It must be something I'm doing wrong. But what?!!! -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Jan 10 12:29:10 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 10 Jan 2012 11:29:10 -0600 Subject: [rspec-users] Problems using config.extend(Macro) In-Reply-To: References: <469696E8-5F41-4B79-9790-7A42A6835172@gmail.com> Message-ID: On Tue, Jan 10, 2012 at 10:30 AM, Ants Pants wrote: > > > On 10 January 2012 14:56, David Chelimsky wrote: >> >> On Jan 10, 2012, at 7:21 AM, Ants Pants wrote: >> >> > Under Ruby 1.8.7 - Rails 2.3.11 - Rspec 1: >> > >> > I have model_macros.rb under spec/spec_helpers and it runs beautifully. >> > >> > Dir[File.expand_path(File.join(File.dirname(__FILE__), 'spec_helpers', >> > '**', '*.rb'))].each { require f } >> > config.extend(ModelMacros, :type => :model) >> > >> > Exactly the same code under Ruby 1.9.2 - Rails 3.1.3 - Rspec 2 gives me >> > ... uninitialized constant ModelMacros (NameError) >> > >> > Dir[Rails.root.join("spec/spec_helpers/**/*.rb")].each {|f| require f} >> > config.extend(ModelMacros, :type => :model) >> > >> > .... which makes sense as it's missing the namespace (but how did it run >> > under 2.3.11. Is Ruby 1.8.7 more lenient? - I doubt it) >> >> That would make sense if Rails was autoloading (implicit) this, but it's >> not - spec_helper.rb is loading it explicitly. I think the namespace thing >> is a red herring. >> >> > So I added the namespace and I got rid of that error >> > >> > config.extend(SpecHelpers::ModelMacros, :type => :model) >> > >> > But sadly the methods that are called from within the model specs are >> > unable to be found...... Exception encountered: #> > method `it_should_require_attributes' >> > >> > This is only solved by including extend SpecHelpers::ModelMacros in the >> > model spec file. Not what I want. >> >> Which suggests that the config is being silently ignored, even though the >> loading is working. >> >> > Is there something I am missing while migrating all my code? Is there >> > some really basic Ruby thing I have forgotten to do to get this module >> > included? >> > >> > I also tried config.include(SpecHelpers::ModelMacros, :type => :model) >> > but to no avail. >> >> That would never have worked under any version because "include" exposes >> methods to the example scope, not the group scope: >> >> describe "something" do >> ?# methods in modules added using extend are available here >> ?it "does something" do >> ? ?# methods in modules added using include are available here >> ?end >> end >> >> > Any help would be great, thank you. >> >> My best guess is that you don't need the namespace, and you should leave >> Rails out of loading this. Try this: >> >> ?Dir["spec_helpers/**/*.rb"].each {|f| require f} >> ?RSpec.configure do |config| >> ? ?config.extend(ModelMacros, :type => :model) >> ?end >> >> That should work to load the file, since RSpec adds"./spec" to the >> $LOAD_PATH. >> >> If that doesn't work, it might be that ":type => :model" isn't working >> correctly, so try "path => /spec\/model/" instead. Please report back and >> let us know which, if either, works for you. >> >> HTH, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > Hey David, thanks for the reply. > > Sadly nothing worked and here are my results > > With .... > Dir["spec_helpers/**/*.rb"].each {|f| puts "loading ... #{f}"; require f} > > I didn't find any file to load and got the following error.... > > /home/anthony/Development/websites/ruby/GMFT/spec/spec_helper.rb:84:in > `block in ': uninitialized constant ModelMacros (NameError) > > With .... > Dir["spec/spec_helpers/**/*.rb"].each {|f| puts "loading ... #{f}"; require > f} > > I found a file to load but require couldn't find it .... > > loading ... spec/spec_helpers/model_macros.rb > /home/anthony/.rvm/gems/ruby-1.9.2-p290 at gmft313/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in > `require': no such file to load -- spec/spec_helpers/model_macros.rb > (LoadError) > > With .... > Dir[Rails.root.join("spec/spec_helpers/**/*.rb")].each {|f| puts "loading > ... #{f}"; require f} > > I found a file to load, apparently it loaded it but then the > ModelMacros#method could not be found.... > > loading ... > /home/anthony/Development/websites/ruby/GMFT/spec/spec_helpers/model_macros.rb > /home/anthony/Development/websites/ruby/GMFT/spec/model/event_group_spec.rb:27:in > `block in ': undefined method `it_should_require_attributes' > for # (NoMethodError > > I also tried with :path in the third example but nada. > > I've also tried all of the above running rspec 2.7.0 and rspec-rails 2.7.0. > No joy. > > It must be something I'm doing wrong. But what?!!! What's in model_macros.rb? From antsmailinglist at gmail.com Tue Jan 10 14:08:35 2012 From: antsmailinglist at gmail.com (Ants Pants) Date: Tue, 10 Jan 2012 20:08:35 +0100 Subject: [rspec-users] Problems using config.extend(Macro) In-Reply-To: References: <469696E8-5F41-4B79-9790-7A42A6835172@gmail.com> Message-ID: On 10 January 2012 18:29, David Chelimsky wrote: > On Tue, Jan 10, 2012 at 10:30 AM, Ants Pants > wrote: > > > > > > On 10 January 2012 14:56, David Chelimsky wrote: > >> > >> On Jan 10, 2012, at 7:21 AM, Ants Pants wrote: > >> > >> > Under Ruby 1.8.7 - Rails 2.3.11 - Rspec 1: > >> > > >> > I have model_macros.rb under spec/spec_helpers and it runs > beautifully. > >> > > >> > Dir[File.expand_path(File.join(File.dirname(__FILE__), 'spec_helpers', > >> > '**', '*.rb'))].each { require f } > >> > config.extend(ModelMacros, :type => :model) > >> > > >> > Exactly the same code under Ruby 1.9.2 - Rails 3.1.3 - Rspec 2 gives > me > >> > ... uninitialized constant ModelMacros (NameError) > >> > > >> > Dir[Rails.root.join("spec/spec_helpers/**/*.rb")].each {|f| require f} > >> > config.extend(ModelMacros, :type => :model) > >> > > >> > .... which makes sense as it's missing the namespace (but how did it > run > >> > under 2.3.11. Is Ruby 1.8.7 more lenient? - I doubt it) > >> > >> That would make sense if Rails was autoloading (implicit) this, but it's > >> not - spec_helper.rb is loading it explicitly. I think the namespace > thing > >> is a red herring. > >> > >> > So I added the namespace and I got rid of that error > >> > > >> > config.extend(SpecHelpers::ModelMacros, :type => :model) > >> > > >> > But sadly the methods that are called from within the model specs are > >> > unable to be found...... Exception encountered: # undefined > >> > method `it_should_require_attributes' > >> > > >> > This is only solved by including extend SpecHelpers::ModelMacros in > the > >> > model spec file. Not what I want. > >> > >> Which suggests that the config is being silently ignored, even though > the > >> loading is working. > >> > >> > Is there something I am missing while migrating all my code? Is there > >> > some really basic Ruby thing I have forgotten to do to get this module > >> > included? > >> > > >> > I also tried config.include(SpecHelpers::ModelMacros, :type => :model) > >> > but to no avail. > >> > >> That would never have worked under any version because "include" exposes > >> methods to the example scope, not the group scope: > >> > >> describe "something" do > >> # methods in modules added using extend are available here > >> it "does something" do > >> # methods in modules added using include are available here > >> end > >> end > >> > >> > Any help would be great, thank you. > >> > >> My best guess is that you don't need the namespace, and you should leave > >> Rails out of loading this. Try this: > >> > >> Dir["spec_helpers/**/*.rb"].each {|f| require f} > >> RSpec.configure do |config| > >> config.extend(ModelMacros, :type => :model) > >> end > >> > >> That should work to load the file, since RSpec adds"./spec" to the > >> $LOAD_PATH. > >> > >> If that doesn't work, it might be that ":type => :model" isn't working > >> correctly, so try "path => /spec\/model/" instead. Please report back > and > >> let us know which, if either, works for you. > >> > >> HTH, > >> David > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > Hey David, thanks for the reply. > > > > Sadly nothing worked and here are my results > > > > With .... > > Dir["spec_helpers/**/*.rb"].each {|f| puts "loading ... #{f}"; require f} > > > > I didn't find any file to load and got the following error.... > > > > /home/anthony/Development/websites/ruby/GMFT/spec/spec_helper.rb:84:in > > `block in ': uninitialized constant ModelMacros > (NameError) > > > > With .... > > Dir["spec/spec_helpers/**/*.rb"].each {|f| puts "loading ... #{f}"; > require > > f} > > > > I found a file to load but require couldn't find it .... > > > > loading ... spec/spec_helpers/model_macros.rb > > /home/anthony/.rvm/gems/ruby-1.9.2-p290 at gmft313 > /gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in > > `require': no such file to load -- spec/spec_helpers/model_macros.rb > > (LoadError) > > > > With .... > > Dir[Rails.root.join("spec/spec_helpers/**/*.rb")].each {|f| puts "loading > > ... #{f}"; require f} > > > > I found a file to load, apparently it loaded it but then the > > ModelMacros#method could not be found.... > > > > loading ... > > > /home/anthony/Development/websites/ruby/GMFT/spec/spec_helpers/model_macros.rb > > > /home/anthony/Development/websites/ruby/GMFT/spec/model/event_group_spec.rb:27:in > > `block in ': undefined method > `it_should_require_attributes' > > for # (NoMethodError > > > > I also tried with :path in the third example but nada. > > > > I've also tried all of the above running rspec 2.7.0 and rspec-rails > 2.7.0. > > No joy. > > > > It must be something I'm doing wrong. But what?!!! > > What's in model_macros.rb? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > David, I set an instance variable @dut (domain under test) in a before block in the spec and use it in the macro. I don't know if this is the best way but I'm not an expert Ruby programmer. before(:each) do @event_group = Factory.build(:event_group) @dut = @event_group end ## and an example call in the spec it_should_require_attributes :name, :created_by Here are just a few methods from the macro ..... module ModelMacros ## dut - Domain Under Test ## aut - Attribute Under Test def it_should_require_attributes(*attrs) attrs.each { |attr| it_should_require_attribute(attr) } end def it_should_not_require_attributes(*attrs) attrs.each { |attr| it_should_not_require_attribute(attr) } end def it_should_require_attribute(aut) it "is not valid with missing #{aut}" do @dut.send("#{aut}=", nil) @dut.should_not be_valid @dut.should have(1).error_on(aut.to_sym) end end def it_should_not_require_attribute(aut) it "is valid with missing #{aut}" do @dut.send("#{aut}=", nil) @dut.should be_valid end end end I hope this helps. I'm really racking my brains but I just can't think of anything. -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Jan 12 19:32:46 2012 From: lists at ruby-forum.com (Fearless Fool) Date: Fri, 13 Jan 2012 01:32:46 +0100 Subject: [rspec-users] stub().and_raise() ain't raising? Message-ID: <6f04f85544442288651fcce5568ec63d@ruby-forum.com> I have two blocks of tests: one for testing positive outcomes and one for testing negative. After poking around, I've concluded that the underlying :verify_credentials method is getting called, despite the stub: describe 'electricity credentials' do before(:each) do @wizard.electricity_service = MeteredService::Base.create!() end it 'with valid credentials should spawn external loader' do @wizard.electricity_service.stub(:verify_credentials).and_return(true) @wizard.electricity_loader.stub(:start) @wizard.electricity_loader.should_receive(:start) @wizard.validate_setting_electricity_credentials end it 'with invalid credentials should not spawn external loader' do @wizard.electricity_service.stub(:verify_credentials).and_raise('no can do') @wizard.electricity_loader.stub(:start) @wizard.electricity_loader.should_not_receive(:start) @wizard.validate_setting_electricity_credentials end end Am I missing something fundamental about .stub()? - ff -- Posted via http://www.ruby-forum.com/. From jko170 at gmail.com Thu Jan 12 21:02:23 2012 From: jko170 at gmail.com (Justin Ko) Date: Thu, 12 Jan 2012 19:02:23 -0700 Subject: [rspec-users] stub().and_raise() ain't raising? In-Reply-To: <6f04f85544442288651fcce5568ec63d@ruby-forum.com> References: <6f04f85544442288651fcce5568ec63d@ruby-forum.com> Message-ID: <04188E39-0D5F-4BB2-B3C9-EC03A961691F@gmail.com> On Jan 12, 2012, at 5:32 PM, Fearless Fool wrote: > I have two blocks of tests: one for testing positive outcomes and one > for testing negative. After poking around, I've concluded that the > underlying :verify_credentials method is getting called, despite the > stub: > > describe 'electricity credentials' do > before(:each) do > @wizard.electricity_service = MeteredService::Base.create!() > end > > it 'with valid credentials should spawn external loader' do > @wizard.electricity_service.stub(:verify_credentials).and_return(true) > @wizard.electricity_loader.stub(:start) > @wizard.electricity_loader.should_receive(:start) > @wizard.validate_setting_electricity_credentials > end > > it 'with invalid credentials should not spawn external loader' do > @wizard.electricity_service.stub(:verify_credentials).and_raise('no > can do') > @wizard.electricity_loader.stub(:start) > @wizard.electricity_loader.should_not_receive(:start) > @wizard.validate_setting_electricity_credentials > end > > end > > Am I missing something fundamental about .stub()? > > - ff > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users What are the failed expectations? Just paste it. Are you sure that @wizard.electricity_service is returning the same object on each call? If a database call is being made, there's a good chance it is returning a different object (which has not mocks). From lists at ruby-forum.com Fri Jan 13 00:18:02 2012 From: lists at ruby-forum.com (Fearless Fool) Date: Fri, 13 Jan 2012 06:18:02 +0100 Subject: [rspec-users] stub().and_raise() ain't raising? In-Reply-To: <04188E39-0D5F-4BB2-B3C9-EC03A961691F@gmail.com> References: <6f04f85544442288651fcce5568ec63d@ruby-forum.com> <04188E39-0D5F-4BB2-B3C9-EC03A961691F@gmail.com> Message-ID: <8f7f5138eb1a35c53658666ed3227fd3@ruby-forum.com> Justin Ko wrote in post #1040632: > What are the failed expectations? Just paste it. You've identified the problem (see below), but to answer your question: 1) Wizard electricity credentials with valid credentials should spawn external loader Failure/Error: @wizard.electricity_loader.should_receive(:start) (#).start(any args) expected: 1 time received: 0 times # ./spec/models/wizard_spec.rb:181:in `block (4 levels) in ' > Are you sure that @wizard.electricity_service is returning the same > object on each call? If a database call is being made, there's a good > chance it is returning a different object (which has not mocks). Ah! I think that's the culprit -- @wizard.electricity_service invokes a db call: class Wizard < ActiveRecord::Base def electricity_service premise.metered_services.where(:natural_resource_id => NaturalResource::ELECTRICITY.id) end end It seems obvious now that you point it out. So in rspec-land, what's the stylistically appropriate way to test this? Stub .any_class()? -- Posted via http://www.ruby-forum.com/. From apremdas at gmail.com Fri Jan 13 02:38:19 2012 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 13 Jan 2012 07:38:19 +0000 Subject: [rspec-users] stub().and_raise() ain't raising? In-Reply-To: <8f7f5138eb1a35c53658666ed3227fd3@ruby-forum.com> References: <6f04f85544442288651fcce5568ec63d@ruby-forum.com> <04188E39-0D5F-4BB2-B3C9-EC03A961691F@gmail.com> <8f7f5138eb1a35c53658666ed3227fd3@ruby-forum.com> Message-ID: On 13 January 2012 05:18, Fearless Fool wrote: > Justin Ko wrote in post #1040632: >> What are the failed expectations? Just paste it. > > You've identified the problem (see below), but to answer your question: > > ?1) Wizard electricity credentials with valid credentials should spawn > external loader > ? ? Failure/Error: @wizard.electricity_loader.should_receive(:start) > ? ? ? (#).start(any args) > ? ? ? ? ? expected: 1 time > ? ? ? ? ? received: 0 times > ? ? # ./spec/models/wizard_spec.rb:181:in `block (4 levels) in (required)>' > >> Are you sure that @wizard.electricity_service is returning the same >> object on each call? If a database call is being made, there's a good >> chance it is returning a different object (which has not mocks). > > Ah! ?I think that's the culprit -- @wizard.electricity_service invokes a > db call: > > class Wizard < ActiveRecord::Base > ?def electricity_service > ? ?premise.metered_services.where(:natural_resource_id => > NaturalResource::ELECTRICITY.id) > ?end > end > I think your tests are telling you to refactor your code. the `premise.metered_services.where` is breaking the law of demeter. This makes it hard to stub/mock. I'd also question the naming of the Wizard class. One thing to consider doing is running the tests with the pretty output and reading it. So why should Wizard#electricity_service spawn an external loader? Why should a Wizard have an electricity service etc. There ia a tendency when writing specs, to focus on getting the spec to pass, and doing complicated things to make this happen. But really its much more important to listen to the tests to make things clear and simple. In this case perhaps there is an ElectricityService class asking to be born. HTH Andrew > It seems obvious now that you point it out. ?So in rspec-land, what's > the stylistically appropriate way to test this? ?Stub .any_class()? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- ------------------------ Andrew Premdas blog.andrew.premdas.org From apnea.diving.deep at gmail.com Sat Jan 14 09:40:57 2012 From: apnea.diving.deep at gmail.com (apneadiving) Date: Sat, 14 Jan 2012 06:40:57 -0800 (PST) Subject: [rspec-users] Testing an API I'm creating, need test server to be running Message-ID: <5485ad72-a21d-4f58-95f5-ccc3f4a8a670@i26g2000vbt.googlegroups.com> Hi, As I am writing a brand new API, I'd like to test it's response. Obviously, controller tests are great and work like a charm but as I expose data which are not really resources, I've to make some DIY to provide responses that ActiveResource can handle properly. Basically, it would be great in my case to test if ActiveResource gets the expected data but it means I have to launch a test server in background for the whole suite. Is there a convenient to handle this? Currently, I launch the test server in console but it would be much better to have this handled programmatically. Thanks in advance, Ben From dchelimsky at gmail.com Sat Jan 14 11:32:58 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Jan 2012 10:32:58 -0600 Subject: [rspec-users] Testing an API I'm creating, need test server to be running In-Reply-To: <5485ad72-a21d-4f58-95f5-ccc3f4a8a670@i26g2000vbt.googlegroups.com> References: <5485ad72-a21d-4f58-95f5-ccc3f4a8a670@i26g2000vbt.googlegroups.com> Message-ID: <19FA37E4-E5B1-4BB4-9EBC-D133429D3E8C@gmail.com> On Jan 14, 2012, at 8:40 AM, apneadiving wrote: > As I am writing a brand new API, I'd like to test it's response. > Basically, it would be great in my case to test if ActiveResource gets > the expected data but it means I have to launch a test server in > background for the whole suite. > Is there a convenient to handle this? Currently, I launch the test > server in console but it would be much better to have this handled > programmatically. I'd recommend you check out https://github.com/brynary/rack-test. It provides access to attributes of the request and the response object, and obviates the need for running a server. Take a look at its specs: https://github.com/brynary/rack-test/blob/master/spec/rack/test_spec.rb. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Jan 14 11:36:03 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Jan 2012 10:36:03 -0600 Subject: [rspec-users] Testing an API I'm creating, need test server to be running In-Reply-To: <19FA37E4-E5B1-4BB4-9EBC-D133429D3E8C@gmail.com> References: <5485ad72-a21d-4f58-95f5-ccc3f4a8a670@i26g2000vbt.googlegroups.com> <19FA37E4-E5B1-4BB4-9EBC-D133429D3E8C@gmail.com> Message-ID: On Jan 14, 2012, at 10:32 AM, David Chelimsky wrote: > On Jan 14, 2012, at 8:40 AM, apneadiving wrote: > >> As I am writing a brand new API, I'd like to test it's response. > >> Basically, it would be great in my case to test if ActiveResource gets >> the expected data but it means I have to launch a test server in >> background for the whole suite. > >> Is there a convenient to handle this? Currently, I launch the test >> server in console but it would be much better to have this handled >> programmatically. > > I'd recommend you check out https://github.com/brynary/rack-test. It provides access to attributes of the request and the response object, and obviates the need for running a server. Take a look at its specs: https://github.com/brynary/rack-test/blob/master/spec/rack/test_spec.rb. Of course, you get rack-test for free if you use request specs (which wrap Rails integration tests, which use rack-test). http://rubydoc.info/gems/rspec-rails/file/README.md#Request_Specs http://guides.rubyonrails.org/testing.html#integration-testing -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedgehogshiatus at gmail.com Sat Jan 14 20:25:34 2012 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Sun, 15 Jan 2012 12:25:34 +1100 Subject: [rspec-users] Testing an API I'm creating, need test server to be running In-Reply-To: References: <5485ad72-a21d-4f58-95f5-ccc3f4a8a670@i26g2000vbt.googlegroups.com> <19FA37E4-E5B1-4BB4-9EBC-D133429D3E8C@gmail.com> Message-ID: On Sun, Jan 15, 2012 at 3:36 AM, David Chelimsky wrote: > > On Jan 14, 2012, at 10:32 AM, David Chelimsky wrote: > > On Jan 14, 2012, at 8:40 AM, apneadiving wrote: > > As I am writing a brand new API, I'd like to test it's response. > > > > Basically, it would be great in my case to test if ActiveResource gets > the expected data but it means I have to launch a test server in > background for the whole suite. > > > > Is there a convenient to handle this? Currently, I launch the test > server in console but it would be much better to have this handled > programmatically. > > > I'd recommend you check out?https://github.com/brynary/rack-test. > It?provides access to attributes of the request and the response object, and > obviates the need for running a server. Take a look at its > specs:?https://github.com/brynary/rack-test/blob/master/spec/rack/test_spec.rb. > > > Of course, you get rack-test for free if you use request specs (which wrap > Rails integration tests, which use rack-test). This could be considered to be off topic, but rack-test was advised.... Some think this issue is a trap for young players, others that it is just a different test philosophy. Nonetheless: After a while you will eventually face the fact that you _have_ to test responses from your whole 'stack', specifically all the interactions of the different components, and rack-test does _not_ do this. Better to bite this bullet early. FWIW I have unit tests that are just that, and integration tests that are, well, integration tests - which precludes (by definition) using rack-test :) To get interagtion tests running (quickly) you'll likely need to use Vagrant+Chef+VCR, or some such toolbox, to launch your test stack (locally, AWS, Rackspace etc.) Again, this is inevitable, so better to bite integration testing early while things are simple - build the complexity incrementally over time. >From someone who years ago wasted too many days trying to isolate issues that rack-test happily passed. Now at least you can't say your weren't forewarned ;) HTH > > http://rubydoc.info/gems/rspec-rails/file/README.md#Request_Specs > http://guides.rubyonrails.org/testing.html#integration-testing > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- ????' ??? ??????, ???' ?????? ?? ???? [The fox knows many things, but the hedgehog knows one big thing.] ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) http://hedgehogshiatus.com From ckponnappa at gmail.com Sat Jan 14 22:00:43 2012 From: ckponnappa at gmail.com (Sidu Ponnappa) Date: Sun, 15 Jan 2012 08:30:43 +0530 Subject: [rspec-users] Testing an API I'm creating, need test server to be running In-Reply-To: References: <5485ad72-a21d-4f58-95f5-ccc3f4a8a670@i26g2000vbt.googlegroups.com> <19FA37E4-E5B1-4BB4-9EBC-D133429D3E8C@gmail.com> Message-ID: Agreed. This is even more a bullet to bite early if your app orchestrates over more than one service, or if services talk to other services or both. Testing this kind of setup is pretty difficult and the tests are typically very brittle. Best, Sidu. http://c42.in http://rubymonk.com Sent from my phone On Jan 15, 2012 7:20 AM, "Hedge Hog" wrote: > On Sun, Jan 15, 2012 at 3:36 AM, David Chelimsky > wrote: > > > > On Jan 14, 2012, at 10:32 AM, David Chelimsky wrote: > > > > On Jan 14, 2012, at 8:40 AM, apneadiving wrote: > > > > As I am writing a brand new API, I'd like to test it's response. > > > > > > > > Basically, it would be great in my case to test if ActiveResource gets > > the expected data but it means I have to launch a test server in > > background for the whole suite. > > > > > > > > Is there a convenient to handle this? Currently, I launch the test > > server in console but it would be much better to have this handled > > programmatically. > > > > > > I'd recommend you check out https://github.com/brynary/rack-test. > > It provides access to attributes of the request and the response object, > and > > obviates the need for running a server. Take a look at its > > specs: > https://github.com/brynary/rack-test/blob/master/spec/rack/test_spec.rb. > > > > > > Of course, you get rack-test for free if you use request specs (which > wrap > > Rails integration tests, which use rack-test). > > This could be considered to be off topic, but rack-test was advised.... > > Some think this issue is a trap for young players, others that it is > just a different test philosophy. Nonetheless: > > After a while you will eventually face the fact that you _have_ to > test responses from your whole 'stack', specifically all the > interactions of the different components, and rack-test does _not_ do > this. > Better to bite this bullet early. > FWIW I have unit tests that are just that, and integration tests that > are, well, integration tests - which precludes (by definition) using > rack-test :) > To get interagtion tests running (quickly) you'll likely need to use > Vagrant+Chef+VCR, or some such toolbox, to launch your test stack > (locally, AWS, Rackspace etc.) > > Again, this is inevitable, so better to bite integration testing early > while things are simple - build the complexity incrementally over > time. > > From someone who years ago wasted too many days trying to isolate > issues that rack-test happily passed. > > Now at least you can't say your weren't forewarned ;) > > HTH > > > > > http://rubydoc.info/gems/rspec-rails/file/README.md#Request_Specs > > http://guides.rubyonrails.org/testing.html#integration-testing > > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > ????' ??? ??????, ???' ?????? ?? ???? > [The fox knows many things, but the hedgehog knows one big thing.] > Archilochus, Greek poet (c. 680 BC ? c. 645 BC) > http://hedgehogshiatus.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From ianrvaughan at gmail.com Sun Jan 15 09:48:58 2012 From: ianrvaughan at gmail.com (Ian Vaughan) Date: Sun, 15 Jan 2012 14:48:58 +0000 Subject: [rspec-users] How to mock out a WEBrick::HTTPServer? Message-ID: partial code : http://pastie.org/3186140 I want to test a HTTP server, I'm using lower level stuff so I can understand whats going on, then I might move onto FakeWeb/WebMock/etc Its a reverse proxy, so it doesn't generate the page content. I want to test a/ methods in the class in isolation b/ test that if a HTTP request sent in generates a HTTP request out (suppose should be just a method to test) c/ and that the HTTP response given to the proxy with body is passed back from the client. Problems I'm running into 1. rpsec creates new instants of my proxy each test, such that multi HTTP servers are running (see rspec implicate-subject) 1.1 This is due to my #initialise creating the HTTPServer, so is that bad code in the init? 1.2 I did that so that starting is neater "Proxy.new.start" 2. I want to mock out the WEBrick::HTTPServer! 2.1 Such that I can test b & c above. Hows best? Thanks in advance! From evgeni.dzhelyov at gmail.com Sun Jan 15 11:49:57 2012 From: evgeni.dzhelyov at gmail.com (Evgeni Dzhelyov) Date: Sun, 15 Jan 2012 18:49:57 +0200 Subject: [rspec-users] How to mock out a WEBrick::HTTPServer? In-Reply-To: References: Message-ID: I read your pastie and your Proxy class is tightly coupled with Webrick, you should decouple it and supply mocked object in the test environment. Some people use approach like this: class A def initialize(server = WEBrick::HTTPServer) end end And in test env initialize the A class like this: A.new(MockedHTTPServer) From anexiole at gmail.com Mon Jan 16 05:59:17 2012 From: anexiole at gmail.com (Gordon) Date: Mon, 16 Jan 2012 02:59:17 -0800 (PST) Subject: [rspec-users] what does 'these' mean in a PUT controller spec? Message-ID: <9f47c7d2-cb8c-464d-ae11-54a749548687@rk3g2000pbb.googlegroups.com> hi, all, the spec above is found in my controller spec for a 'category' resource. It's a generated spec. ----- start extract -------------------------------------------- describe "PUT update" do describe "with valid params" do it "updates the requested category" do category = Category.create! valid_attributes # Assuming there are no other categories in the database, this # specifies that the Category created on the previous line # receives the :update_attributes message with whatever params are # submitted in the request. Category.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) put :update, :id => category.id, :category => {'these' => 'params'} end ----- end extract -------------------------------------------- When the spec is run, it fails with the error below. ----- start extract -------------------------------------------- 1) CategoriesController PUT update with valid params updates the requested category Failure/Error: put :update, :id => category.id, :category => {'these' => 'params'} # received :update_attributes with unexpected arguments expected: ({"these"=>"params"}) got: ({"these"=>"params", "updated_by"=>1}) # /Users/anexiole/projects/try_rails/app/controllers/ categories_controller.rb:72:in `block in update' # /Users/anexiole/projects/try_rails/app/controllers/ categories_controller.rb:71:in `update' # ./categories_controller_spec.rb:92:in `block (4 levels) in ' Finished in 19.15 seconds 16 examples, 1 failure Failed examples: rspec ./categories_controller_spec.rb:85 # CategoriesController PUT update with valid params updates the requested category ----- end extract -------------------------------------------- My 'update' method in the categories controller file itself has one added rule for which I will assign the current user's id to the updated_by attribute before a call to update_attribute is made. ----- start extract -------------------------------------------- # PUT /categories/1 # PUT /categories/1.json def update # Record current user's id as he/she created the part params[:category][:updated_by] = current_user.id @category = Category.find(params[:id]) respond_to do |format| if @category.update_attributes(params[:category]) format.html { redirect_to @category, notice: 'Category was successfully updated.' } format.json { head :ok } else format.html { render action: "edit" } format.json { render json: @category.errors, status: :unprocessable_entity } end end end ----- end extract -------------------------------------------- Can someone please tell me what does 'these' refer to in the spec? Where can I read up more about them? I would like to fix the failing spec example. Thank you Gorodn From dchelimsky at gmail.com Mon Jan 16 08:17:04 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jan 2012 07:17:04 -0600 Subject: [rspec-users] what does 'these' mean in a PUT controller spec? In-Reply-To: <9f47c7d2-cb8c-464d-ae11-54a749548687@rk3g2000pbb.googlegroups.com> References: <9f47c7d2-cb8c-464d-ae11-54a749548687@rk3g2000pbb.googlegroups.com> Message-ID: On Jan 16, 2012, at 4:59 AM, Gordon wrote: > hi, all, > > the spec above is found in my controller spec for a 'category' > resource. > > It's a generated spec. > > ----- start extract -------------------------------------------- > describe "PUT update" do > describe "with valid params" do > it "updates the requested category" do > category = Category.create! valid_attributes > # Assuming there are no other categories in the database, this > # specifies that the Category created on the previous line > # receives the :update_attributes message with whatever params > are > # submitted in the request. > > Category.any_instance.should_receive(:update_attributes).with({'these' > => 'params'}) > put :update, :id => category.id, :category => {'these' => > 'params'} > end > ----- end extract -------------------------------------------- > > When the spec is run, it fails with the error below. > > ----- start extract -------------------------------------------- > > 1) CategoriesController PUT update with valid params updates the > requested category > Failure/Error: put :update, :id => category.id, :category => > {'these' => 'params'} > # received :update_attributes with > unexpected arguments > expected: ({"these"=>"params"}) > got: ({"these"=>"params", "updated_by"=>1}) > # /Users/anexiole/projects/try_rails/app/controllers/ > categories_controller.rb:72:in `block in update' > # /Users/anexiole/projects/try_rails/app/controllers/ > categories_controller.rb:71:in `update' > # ./categories_controller_spec.rb:92:in `block (4 levels) in (required)>' > > Finished in 19.15 seconds > 16 examples, 1 failure > > Failed examples: > > rspec ./categories_controller_spec.rb:85 # CategoriesController PUT > update with valid params updates the requested category > > ----- end extract -------------------------------------------- > > My 'update' method in the categories controller file itself has one > added rule for which > I will assign the current user's id to the updated_by attribute > before a call to update_attribute is made. > > ----- start extract -------------------------------------------- > # PUT /categories/1 > # PUT /categories/1.json > def update > # Record current user's id as he/she created the part > params[:category][:updated_by] = current_user.id > > @category = Category.find(params[:id]) > > respond_to do |format| > if @category.update_attributes(params[:category]) > format.html { redirect_to @category, notice: 'Category was > successfully updated.' } > format.json { head :ok } > else > format.html { render action: "edit" } > format.json { render json: @category.errors, > status: :unprocessable_entity } > end > end > end > > ----- end extract -------------------------------------------- > > > Can someone please tell me what does 'these' refer to in the spec? > Where can I read up more about them? > I would like to fix the failing spec example. What's being specified here is that the contents of params[:category] are passed to update attributes. What they actually contain is not of concern to the controller or the controller spec, since they get passed directly to the model in the generated controller. 'these' => 'params' could just as easily be 'foo' => 'bar'. The important thing is that the same params get received by the model object. The reason the spec is failing now is that the line you added modifies the hash before it gets sent to model object. If you change the spec to this: Category.any_instance.should_receive(:update_attributes).with('these' => 'params', 'updated_by' => 1) then it will pass. If you find 'these' => 'params' to be confusing, feel free to change it to what ever you like. Just make sure you do so in both places in the example. HTH, David From sahmed1020 at gmail.com Mon Jan 16 10:16:43 2012 From: sahmed1020 at gmail.com (S Ahmed) Date: Mon, 16 Jan 2012 10:16:43 -0500 Subject: [rspec-users] rspec and requests, and folders conventions Message-ID: I'm trying to run rspec requests, using jruby, and I set the defaults in a env.rb file, but it doesn't seem to be loaded when I run the specs. My folder setup is: /spec/requests/ /spec/requests/section/section_spec.rb /spec/support/env.rb (where I configured selenium as the driver etc.) I also tried putting support here: /spec/requests/support/env.rb When I run rspec, it says I need a rack test or something. I just want to confirm, will rspec auto load the env.rb with any of the above folder conventions, or do I have to require it manually somewhere? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jan 16 10:42:36 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jan 2012 09:42:36 -0600 Subject: [rspec-users] rspec and requests, and folders conventions In-Reply-To: References: Message-ID: <52F6B981-09CA-4799-9D66-1FEF4AC90731@gmail.com> On Jan 16, 2012, at 9:16 AM, S Ahmed wrote: > I'm trying to run rspec requests, using jruby, and I set the defaults in a env.rb file, but it doesn't seem to be loaded when I run the specs. > > My folder setup is: > > /spec/requests/ > /spec/requests/section/section_spec.rb > /spec/support/env.rb (where I configured selenium as the driver etc.) > > > I also tried putting support here: > > /spec/requests/support/env.rb > > When I run rspec, it says I need a rack test or something. > > I just want to confirm, will rspec auto load the env.rb with any of the above folder conventions, No. > or do I have to require it manually somewhere? Yes. The convention is to do something like this in spec/spec_helper.rb: Dir["spec/support/**/*.rb"].each {|f| require f} This can be found in the spec_helper.rb generated by rspec-rails when you run "rake rspec:install", but that's just a convention/convenience. There's nothing in RSpec that implicitly loads files in spec/support. HTH, David From lists at ruby-forum.com Mon Jan 16 15:41:55 2012 From: lists at ruby-forum.com (Thomas Krebs) Date: Mon, 16 Jan 2012 21:41:55 +0100 Subject: [rspec-users] rspec output on windows Message-ID: I have rails 3.1.3 and rspec 2.8.0 on windows 7 (32bit) installed. When running rspec I receive the following output: ?[32m.?[0m?[32m.?[0m Finished in 0.33 seconds ?[32m2 examples, 0 failures?[0m I have no glue how to get rid of the "special characters". Since I am new to rails I appreciate any help or suggestions. Tom -- Posted via http://www.ruby-forum.com/. From luislavena at gmail.com Mon Jan 16 16:00:14 2012 From: luislavena at gmail.com (Luis Lavena) Date: Mon, 16 Jan 2012 18:00:14 -0300 Subject: [rspec-users] rspec output on windows In-Reply-To: References: Message-ID: On Mon, Jan 16, 2012 at 5:41 PM, Thomas Krebs wrote: > I have rails 3.1.3 and rspec 2.8.0 on windows 7 (32bit) installed. > When running rspec I receive the following output: > > ?[32m.?[0m?[32m.?[0m > > Finished in 0.33 seconds > ?[32m2 examples, 0 failures?[0m > > I have no glue how to get rid of the "special characters". Since I am > new to rails I appreciate any help or suggestions. Remove --color / --colour option from project .rspec file (or rspec.opts file, don't remember the name) -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From lists at ruby-forum.com Mon Jan 16 16:13:36 2012 From: lists at ruby-forum.com (Thomas Krebs) Date: Mon, 16 Jan 2012 22:13:36 +0100 Subject: [rspec-users] rspec output on windows In-Reply-To: References: Message-ID: <621aa1ca606b14c97f257331c9eab845@ruby-forum.com> thanks - that worked! -- Posted via http://www.ruby-forum.com/. From jeremie.horhant at titinux.net Mon Jan 16 18:17:54 2012 From: jeremie.horhant at titinux.net (Titinux) Date: Mon, 16 Jan 2012 15:17:54 -0800 (PST) Subject: [rspec-users] Controller specs and default_url_options Message-ID: <3aee5b9f-6324-442d-93f4-844431cbcde9@r16g2000yqi.googlegroups.com> Hello, I'm using Rails 3.1.3 with rspec-rails 2.8.1. I have a scope ':locale' in routes.rb and I want to run controller and routing specs. I'm aware of the problem with setting default_url_options in application.rb controller so I apply the solution found in the last comment on rspec issue #255 ( https://github.com/rspec/rspec-rails/issues/255 ) #./spec/support/default_locale.rb class ActionView::TestCase::TestController def default_url_options(options={}) { :locale => I18n.default_locale } end end class ActionDispatch::Routing::RouteSet def default_url_options(options={}) { :locale => I18n.default_locale } end end #./spec/controllers/categories_controller_spec.rb require "spec_helper" describe CategoriesController do describe "GET index" do it "assigns all categories as @categories" do category = Factory :category get :index assigns(:categories).to_a.should eq([category]) end end end This test fails with routing error but if I use "get :index, locale: :fr" instead of just "get :index" the test pass. This test is a example of controller spec but I have failing tests for routing and request. (I have no view specs but I'm pretty sure they would also fail) I can't figure out where the problem come from and why the patch doesn't solve it. Is there another thing to do ? (I just put the code in ./spec/support/default_locale.rb and verify that it loads correctly). Thanks in advance. From dchelimsky at gmail.com Mon Jan 16 20:18:52 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jan 2012 19:18:52 -0600 Subject: [rspec-users] Controller specs and default_url_options In-Reply-To: <3aee5b9f-6324-442d-93f4-844431cbcde9@r16g2000yqi.googlegroups.com> References: <3aee5b9f-6324-442d-93f4-844431cbcde9@r16g2000yqi.googlegroups.com> Message-ID: On Jan 16, 2012, at 5:17 PM, Titinux wrote: > Hello, > > I'm using Rails 3.1.3 with rspec-rails 2.8.1. I have a scope ':locale' > in routes.rb and I want to run controller and routing > specs. I'm aware of the problem with setting default_url_options in > application.rb controller so I apply the solution found in the last > comment on rspec issue #255 ( https://github.com/rspec/rspec-rails/issues/255 > ) > > #./spec/support/default_locale.rb > class ActionView::TestCase::TestController > def default_url_options(options={}) > { :locale => I18n.default_locale } > end > end > > class ActionDispatch::Routing::RouteSet > def default_url_options(options={}) > { :locale => I18n.default_locale } > end > end > > #./spec/controllers/categories_controller_spec.rb > require "spec_helper" > > describe CategoriesController do > > describe "GET index" do > it "assigns all categories as @categories" do > category = Factory :category > > get :index > assigns(:categories).to_a.should eq([category]) > end > end > end > > This test fails with routing error but if I use "get :index, > locale: :fr" instead of just "get :index" the test pass. > This test is a example of controller spec but I have failing tests for > routing and request. (I have no view specs but > I'm pretty sure they would also fail) > > I can't figure out where the problem come from and why the patch > doesn't solve it. Is there another thing to do ? (I just put the code > in ./spec/support/default_locale.rb and verify that it loads > correctly). > > Thanks in advance. No guarantees here, but it's possible that ActionView::TestCase::TestController is not loaded yet, in which case its own definition of default_url_options would clobber yours when it does get loaded. Try this instead: ActionView::TestCase::TestController.class_eval do undef_method :default_url_options def default_url_options(options={}) { :locale => I18n.default_locale } end end ActionDispatch::Routing::RouteSet.class_eval do undef_method :default_url_options def default_url_options(options={}) { :locale => I18n.default_locale } end end If those classes aren't loaded yet, Rails will find and load them first (via its autoload strategy) before invoking class_eval on them, thus ensuring that you're replacing the existing methods rather than writing methods that will later be replaced. HTH, David From sahmed1020 at gmail.com Mon Jan 16 21:35:28 2012 From: sahmed1020 at gmail.com (S Ahmed) Date: Mon, 16 Jan 2012 21:35:28 -0500 Subject: [rspec-users] does jruby rspec have to use selenium? Message-ID: With jruby and rspec requests, do you have to use selenium webdriver? I'm confused, with ruby and rubyonrails using cucumber with capybara, I didn't have to set the default driver, what was it using and can i use that with jruby? Things just worked w/o me even having to know about it :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Mon Jan 16 22:51:42 2012 From: jko170 at gmail.com (Justin Ko) Date: Mon, 16 Jan 2012 20:51:42 -0700 Subject: [rspec-users] does jruby rspec have to use selenium? In-Reply-To: References: Message-ID: On Jan 16, 2012, at 7:35 PM, S Ahmed wrote: > With jruby and rspec requests, do you have to use selenium webdriver? > > I'm confused, with ruby and rubyonrails using cucumber with capybara, I didn't have to set the default driver, what was it using and can i use that with jruby? Things just worked w/o me even having to know about it :) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users They capybara build is passing with jRuby: http://travis-ci.org/#!/jnicklas/capybara/jobs/512756 Just check out the README to get it setup with RSpec - it's all there. From sahmed1020 at gmail.com Tue Jan 17 00:42:32 2012 From: sahmed1020 at gmail.com (S Ahmed) Date: Tue, 17 Jan 2012 00:42:32 -0500 Subject: [rspec-users] does jruby rspec have to use selenium? In-Reply-To: References: Message-ID: I'm using jruby and with a java app, so after reading it is clear I can only use selenium since it is not a rack app. selenium is very very slow, sheesh! I was hoping there was a better way. It keeps the firefox browser open also, which is strange (after it completes running). On Mon, Jan 16, 2012 at 10:51 PM, Justin Ko wrote: > > On Jan 16, 2012, at 7:35 PM, S Ahmed wrote: > > > With jruby and rspec requests, do you have to use selenium webdriver? > > > > I'm confused, with ruby and rubyonrails using cucumber with capybara, I > didn't have to set the default driver, what was it using and can i use that > with jruby? Things just worked w/o me even having to know about it :) > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > They capybara build is passing with jRuby: > http://travis-ci.org/#!/jnicklas/capybara/jobs/512756 > > Just check out the README to get it setup with RSpec - it's all there. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeremie.horhant at titinux.net Tue Jan 17 09:23:24 2012 From: jeremie.horhant at titinux.net (Titinux) Date: Tue, 17 Jan 2012 06:23:24 -0800 (PST) Subject: [rspec-users] Controller specs and default_url_options In-Reply-To: References: <3aee5b9f-6324-442d-93f4-844431cbcde9@r16g2000yqi.googlegroups.com> Message-ID: <7d3ec9fd-23a3-4044-b924-00a0e0157b9e@i6g2000vbk.googlegroups.com> Hi, I used your code but it does not work either. To eliminate the possibility of a problem coming from my application I made a new Rails 3.1.3 app from scratch and scaffold Category stuff. And the result is that view specs start working with either issue #255 solution or yours but controller, routing and request specs fails whatever I try. I've set a "binding.pry" just before "get :index" in the controller spec to have a better vision of what's going on ActionView::TestCase::TestController.new.default_url_options => {:locale=>:en} ActionDispatch::Routing::RouteSet.new.default_url_options => {:locale=>:en} So I think the patch does its job but "get :index" takes another path and not use default_url_options from ActionView::TestCase::TestController nor ActionDispatch::Routing::RouteSet On 17 jan, 02:18, David Chelimsky wrote: > On Jan 16, 2012, at 5:17 PM, Titinux wrote: > > > > > > > > > > > Hello, > > > I'm using Rails 3.1.3 with rspec-rails 2.8.1. I have a scope ':locale' > > in routes.rb and I want to run controller and routing > > specs. I'm aware of the problem with setting default_url_options in > > application.rb controller so I apply the solution found in the last > > comment on rspec issue #255 (https://github.com/rspec/rspec-rails/issues/255 > > ) > > > #./spec/support/default_locale.rb > > class ActionView::TestCase::TestController > > ?def default_url_options(options={}) > > ? ?{ :locale => I18n.default_locale } > > ?end > > end > > > class ActionDispatch::Routing::RouteSet > > ?def default_url_options(options={}) > > ? ?{ :locale => I18n.default_locale } > > ?end > > end > > > #./spec/controllers/categories_controller_spec.rb > > require "spec_helper" > > > describe CategoriesController do > > > ?describe "GET index" do > > ? ?it "assigns all categories as @categories" do > > ? ? ?category = Factory :category > > > ? ? ?get :index > > ? ? ?assigns(:categories).to_a.should eq([category]) > > ? ?end > > ?end > > end > > > This test fails with routing error but if I use "get :index, > > locale: :fr" instead of just "get :index" the test pass. > > This test is a example of controller spec but I have failing tests for > > routing and request. (I have no view specs but > > I'm pretty sure they would also fail) > > > I can't figure out where the problem come from and why the patch > > doesn't solve it. Is there another thing to do ? (I just put the code > > in ./spec/support/default_locale.rb and verify that it loads > > correctly). > > > Thanks in advance. > > No guarantees here, but it's possible that ActionView::TestCase::TestController is not loaded yet, in which case its own definition of default_url_options would clobber yours when it does get loaded. Try this instead: > > ActionView::TestCase::TestController.class_eval do > ? undef_method :default_url_options > ? def default_url_options(options={}) > ? ? { :locale => I18n.default_locale } > ? end > end > > ActionDispatch::Routing::RouteSet.class_eval do > ? undef_method :default_url_options > ? def default_url_options(options={}) > ? ? { :locale => I18n.default_locale } > ? end > end > > If those classes aren't loaded yet, Rails will find and load them first (via its autoload strategy) before invoking class_eval on them, thus ensuring that you're replacing the existing methods rather than writing methods that will later be replaced. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From apnea.diving.deep at gmail.com Tue Jan 17 15:10:24 2012 From: apnea.diving.deep at gmail.com (apneadiving) Date: Tue, 17 Jan 2012 12:10:24 -0800 (PST) Subject: [rspec-users] Testing an API I'm creating, need test server to be running In-Reply-To: References: <5485ad72-a21d-4f58-95f5-ccc3f4a8a670@i26g2000vbt.googlegroups.com> <19FA37E4-E5B1-4BB4-9EBC-D133429D3E8C@gmail.com> Message-ID: <1c1a1ea0-dad1-43f4-bfba-721cbe78fc3f@i25g2000vbt.googlegroups.com> Thanks for all your answers, I should have said I'm very used to the workflow of integration specs and capybara. My question is really oriented towards API testing and particularly on the use of Active Resource. Basically, I'd like to: a- create ActiveResource classes in rspec/support b- run my tests for a, I don't really know what URL I should provide for b, according to what you said, this kind of tests should live in rspec/requests Any more enlightenment? :) Ben On Jan 14, 5:36?pm, David Chelimsky wrote: > On Jan 14, 2012, at 10:32 AM, David Chelimsky wrote: > > > On Jan 14, 2012, at 8:40 AM, apneadiving wrote: > > >> As I am writing a brand new API, I'd like to test it's response. > > > >> Basically, it would be great in my case to test if ActiveResource gets > >> the expected data but it means I have to launch a test server in > >> background for the whole suite. > > > >> Is there a convenient to handle this? Currently, I launch the test > >> server in console but it would be much better to have this handled > >> programmatically. > > > I'd recommend you check outhttps://github.com/brynary/rack-test. It provides access to attributes of the request and the response object, and obviates the need for running a server. Take a look at its specs:https://github.com/brynary/rack-test/blob/master/spec/rack/test_spec.rb. > > Of course, you get rack-test for free if you use request specs (which wrap Rails integration tests, which use rack-test). > > http://rubydoc.info/gems/rspec-rails/file/README.md#Request_Specshttp://guides.rubyonrails.org/testing.html#integration-testing > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ianrvaughan at gmail.com Sat Jan 14 16:57:28 2012 From: ianrvaughan at gmail.com (Ian Vaughan) Date: Sat, 14 Jan 2012 13:57:28 -0800 (PST) Subject: [rspec-users] Low level HTTP server mocking Message-ID: <10954938.1595.1326578248639.JavaMail.geo-discussion-forums@vbfy15> Hi, I have a class which creates a WEBrick::HTTPServer, and in my tests I obviously do not want to instantiate/open this server, as (a) its a resource waste (b) would hang the test (c) is not under-test. So :- 1. How can I stub it out? 2. How can I mock the call to #mount_proc, such that, when my dir/route gets hit, the real code runs? Or put another way, I want to test that my mapping/routing is correct, such that if I get "/", my HTTPServer, I get "hello" back. I want to use as least amount of external libs as possible, so to learn whats going on. (ie not yet use webmock/fakeweb/etc) Code : http://pastie.org/3186140 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivan.neverov at gmail.com Tue Jan 17 11:36:35 2012 From: ivan.neverov at gmail.com (=?KOI8-R?B?6dfBziDuxdfF0s/X?=) Date: Tue, 17 Jan 2012 18:36:35 +0200 Subject: [rspec-users] List of examples In-Reply-To: References: Message-ID: Hi all, I want to write a test grid over rspec && spork. For example we have grid with several nodes. Each has spork running on it. Master node accept some filters like --tag tag:value to run It select all examples for this conditions and distribute them through nodes with syntax like rspec path_to_test:line_number Problem is following. I can get exact line for example with (in some method like "list" in lib/rspec/core/world.rb) filtered_examples.collect{|g,es| es}.flatten.uniq.compact.collect{|ex| ex.location} but if example group includes shared examples it get wrong line number Explain on example: 1 shared_examples_for "a" do 2 context "one" do 3 it "shared" do 4 end 5 end 6 context 'two' do 7 it "shared1" do 8 end 9 end 10 end 11 describe "1" do 12 it_should_behave_like "a" 13 end 14 describe "2" do 15 it_should_behave_like "a" 16 it "three" do 17 end 18 it "four" do 19 end 20 end Result is test_spec.rb:3 test_spec.rb:7 But I can get all calling chain for Example (using metadata[:example_group]) Other case of problem we cannot run specific shared example in context of some describe For example for test above, run Example "shared" in context of ExampleGroup "1". Command rspec test_spec.rb:3 execute for all ExampleGroup's "1" and "2" Maybe there is a syntax to run shared example in context of some ExampleGroup, like: rspec test_spec.rb:14:15:2:3 # to run "shared" in context of ExampleGroup "1" rspec test_spec.rb:16,18 # to run Example's "three" and "four" rspec test_spec.rb:14:15:2:3,11:12:6:7 # to run Example "shared" in context of ExampleGroup "2" and Example "shared1" in context of ExampleGroup "1" What do you think about all this. Thanks. Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: From alegomes at gmail.com Sun Jan 15 18:10:17 2012 From: alegomes at gmail.com (Alexandre Gomes) Date: Sun, 15 Jan 2012 21:10:17 -0200 Subject: [rspec-users] NoMethodError: undefined method `expect' Message-ID: Ideas? ruby-1.9.2-p290 :002 > require 'rspec' => true ruby-1.9.2-p290 :003 > RSpec::Version::STRING => "2.8.0" ruby-1.9.2-p290 :004 > describe 'division by zero' do ruby-1.9.2-p290 :005 > expect { 2/0 }.to raise_error ruby-1.9.2-p290 :006?> end NoMethodError: undefined method `expect' for # from (irb):5:in `block in irb_binding' from .../.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:201:in `module_eval' from .../.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:201:in `subclass' from .../.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:187:in `describe' from .../.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/dsl.rb:18:in `describe' from (irb):4 from .../.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `
' ruby-1.9.2-p290 :007 > []s! -------------- next part -------------- An HTML attachment was scrubbed... URL: From transfire at gmail.com Mon Jan 16 17:54:19 2012 From: transfire at gmail.com (TR NS) Date: Mon, 16 Jan 2012 14:54:19 -0800 (PST) Subject: [rspec-users] Custom formatters and capturing $stdout/$stderr Message-ID: <15570360.1435.1326754459116.JavaMail.geo-discussion-forums@yqdj19> In custom formatters, is there a proper way to capture $stdout/$stderr? I have a formally structured output format, so I need to prevent extraneous output that might come from test code. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mguterl at gmail.com Tue Jan 17 18:23:20 2012 From: mguterl at gmail.com (Michael Guterl) Date: Tue, 17 Jan 2012 18:23:20 -0500 Subject: [rspec-users] NoMethodError: undefined method `expect' In-Reply-To: References: Message-ID: On Sun, Jan 15, 2012 at 6:10 PM, Alexandre Gomes wrote: > Ideas? > > > ruby-1.9.2-p290 :002 > require 'rspec' > ?=> true > ruby-1.9.2-p290 :003 > RSpec::Version::STRING > ?=> "2.8.0" > ruby-1.9.2-p290 :004 > describe 'division by zero' do > ruby-1.9.2-p290 :005 > ? ? expect { 2/0 }.to raise_error > ruby-1.9.2-p290 :006?> ? end > NoMethodError: undefined method `expect' for # > from (irb):5:in `block in irb_binding' > from > .../.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:201:in > `module_eval' > from?.../.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:201:in > `subclass' > from?.../.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:187:in > `describe' > from?.../.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/dsl.rb:18:in > `describe' > from (irb):4 > from?.../.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `
' > ruby-1.9.2-p290 :007 > > > []s! > You need to put your expectations in an it block. describe 'division by zero' do ? it { expect { 2/0 }.to raise_error } end Best, Michael Guterl From lists at ruby-forum.com Thu Jan 19 11:45:00 2012 From: lists at ruby-forum.com (Martin C.) Date: Thu, 19 Jan 2012 17:45:00 +0100 Subject: [rspec-users] Controller specs and default_url_options In-Reply-To: <3aee5b9f-6324-442d-93f4-844431cbcde9@r16g2000yqi.googlegroups.com> References: <3aee5b9f-6324-442d-93f4-844431cbcde9@r16g2000yqi.googlegroups.com> Message-ID: <5a7830a735e29bfbb04929cfae1a8490@ruby-forum.com> Hi Jeremie, I'm also using Rails 3.1.3 and rspec-rails 2.8.1 and I was in the same situation as you: neither the rspec issue #255 or the proposed solutions in this email thread solved my problems. But now I have something working for me (and hopefully it will work for you too). As I recently posted on Stackoverflow (http://stackoverflow.com/questions/1987354/how-to-set-locale-default-url-options-for-functional-tests-rails/8920258#8920258 ), here is the code I use to inject the locale in the controller's params (which makes all my controller specs pass without explicitly specifying the locale in each controller spec): class ActionController::TestCase module Behavior def process_with_default_locale(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') parameters = { :locale => I18n.default_locale }.merge( parameters || {} ) process_without_default_locale(action, parameters, session, flash, http_method) end alias_method_chain :process, :default_locale end end And here is the "cheat" I use to inject the locale in Rails's assert_recognizes method (which makes all my routing specs pass without explicitly specifying the locale in each routing spec): module ActionDispatch::Assertions::RoutingAssertions def assert_recognizes_with_default_locale(expected_options, path, extras={}, message=nil) expected_options = { :locale => I18n.default_locale.to_s }.merge(expected_options || {} ) assert_recognizes_without_default_locale(expected_options, path, extras, message) end alias_method_chain :assert_recognizes, :default_locale end Stucking those two code snippets in my spec helper class means that I do not need to change all my previous controller/routing specs during the implementation of supporting multiple locales for my app. Hope this helps, Martin -- Posted via http://www.ruby-forum.com/. From harmaarts at gmail.com Thu Jan 19 09:08:03 2012 From: harmaarts at gmail.com (haarts) Date: Thu, 19 Jan 2012 06:08:03 -0800 (PST) Subject: [rspec-users] Speccing Rack middleware rack-cors Message-ID: <24216704.2801.1326982083809.JavaMail.geo-discussion-forums@vbbfd4> Dear all, I'd love to spec a piece of Rack middleware I'm using a project. It's middleware providing CORS functionality (https://github.com/cyu/rack-cors , 0.2.4). The middleware seems to work when I'm cURLing but I can't seem to get it to work with Rspec (2.8.0) and Rails (3.1.3). It looks like the middleware is bypassed entirely. I tried setting the headers via 'request.env["Origin"] = "*"' and sending it as a third argument to 'get'. See Gist, https://gist.github.com/1640182, for the nicely formatted code. Nothing seems to work. What am I doing wrong? With kind regards, -------------- next part -------------- An HTML attachment was scrubbed... URL: From harmaarts at gmail.com Thu Jan 19 10:36:43 2012 From: harmaarts at gmail.com (haarts) Date: Thu, 19 Jan 2012 07:36:43 -0800 (PST) Subject: [rspec-users] Speccing Rack middleware rack-cors In-Reply-To: <24216704.2801.1326982083809.JavaMail.geo-discussion-forums@vbbfd4> References: <24216704.2801.1326982083809.JavaMail.geo-discussion-forums@vbbfd4> Message-ID: <22602906.4324.1326987403258.JavaMail.geo-discussion-forums@vbhn11> I'm now confident the Rack middleware is _not_ bypassed. Awesome! Only now I really don't know what is amiss. -------------- next part -------------- An HTML attachment was scrubbed... URL: From anexiole at gmail.com Mon Jan 23 05:35:14 2012 From: anexiole at gmail.com (Gordon) Date: Mon, 23 Jan 2012 02:35:14 -0800 (PST) Subject: [rspec-users] Nested resource view spec seems to be referring to a non-existent route Message-ID: <38ec5cf1-40c8-46f3-b42b-2bee17c6d6ec@ih8g2000pbc.googlegroups.com> Hi all, In a view spec for a nested resource, do I need to instantiate/stub the parent resource before I stub the nested resource? I am asking this because all my view specs are failing for a new nested resource I have introduced in my application. The nested resource works as expected when I manually test it though :( Here's how my edit view spec looks like. ----------- "./spec/views/sub_categories/edit.html.erb_spec.rb" - start -------- require 'spec_helper' describe "sub_categories/edit.html.erb" do before(:each) do @sub_category = assign(:sub_category, stub_model(SubCategory, :name => 'International interest rates', :description => 'Comprehensive rates covering Australia, NZ, Malaysia and Singapore', :category_id => 3, :created_by => 1, :updated_by => 1 )) end it "renders the edit sub category form" do render # Run the generator again with the --webrat flag if you want to use webrat matchers assert_select "form", :action => category_sub_categories(@sub_category), :method => "post" do assert_select "input#sub_category_name", :name => "sub_category[name]" assert_select "textarea#sub_category_description", :name => "sub_category[description]" end end end ----------- "./spec/views/sub_categories/edit.html.erb_spec.rb" - end -------- Here's an extract of the failure: ----------- extract start ------------------------- 1) sub_categories/edit.html.erb renders the edit sub category form Failure/Error: render ActionView::Template::Error: undefined method `sub_category_path' for #<#:0x000001016e2380> # ./app/views/sub_categories/_form.html.erb:1:in `_app_views_sub_categories__form_html_erb__4092631658606598204_2155519360' # ./app/views/sub_categories/edit.html.erb:3:in `_app_views_sub_categories_edit_html_erb___3853358586184509671_2155544160' # ./spec/views/sub_categories/edit.html.erb_spec.rb:15:in `block (2 levels) in ' ----------- extract end ------------------------- Here's what my form partial looks like ----- app/views/sub_categories/_form.html.erb start --------------------- <%= form_for [@category, @sub_category] do |f| %> <% if @sub_category.errors.any? %>

<%= pluralize(@sub_category.errors.count, "error") %> prohibited this sub_category from being saved:

    <% @sub_category.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
<% end %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :description %>
<%= f.text_area :description %>
<%= f.submit %>
<% end %> ----- app/views/sub_categories/_form.html.erb end --------------------- Here's what I see when I run 'rake routes': ------- routes start --------------------------- category_sub_categories GET /categories/:category_id/ sub_categories(.:format) {:action=>"index", :controller=>"sub_categories"} POST /categories/:category_id/ sub_categories(.:format) {:action=>"create", :controller=>"sub_categories"} new_category_sub_category GET /categories/:category_id/ sub_categories/new(.:format) {:action=>"new", :controller=>"sub_categories"} edit_category_sub_category GET /categories/:category_id/ sub_categories/:id/edit(.:format) {:action=>"edit", :controller=>"sub_categories"} category_sub_category GET /categories/:category_id/ sub_categories/:id(.:format) {:action=>"show", :controller=>"sub_categories"} PUT /categories/:category_id/ sub_categories/:id(.:format) {:action=>"update", :controller=>"sub_categories"} DELETE /categories/:category_id/ sub_categories/:id(.:format) {:action=>"destroy", :controller=>"sub_categories"} categories GET / categories(.:format) {:action=>"index", :controller=>"categories"} POST / categories(.:format) {:action=>"create", :controller=>"categories"} new_category GET /categories/ new(.:format) {:action=>"new", :controller=>"categories"} edit_category GET /categories/:id/ edit(.:format) {:action=>"edit", :controller=>"categories"} category GET / categories/:id(.:format) {:action=>"show", :controller=>"categories"} PUT / categories/:id(.:format) {:action=>"update", :controller=>"categories"} DELETE / categories/:id(.:format) {:action=>"destroy", :controller=>"categories"} root / ------- routes end --------------------------- The form partial has been properly fitted with the parent resource and the nested resource (ie. "form_for [@category, @sub_category]" ). It seems that it's calling a route, sub_category_path which I have never specified. The error comes up when an edit/create form is to be created where a form partial is called. I am really puzzled on why this is happening and have consulted the search results I had via google for 'nested resources with rspec' , 'Rails in Action 3' by Yehuda Katz, and the Rspec book :( If anyone knows what I am missing, I would love to hear your thoughts. thank you :) Gordon From gisborne at emailuser.net Wed Jan 25 01:24:59 2012 From: gisborne at emailuser.net (Guyren G Howe) Date: Tue, 24 Jan 2012 22:24:59 -0800 Subject: [rspec-users] id getting overwritten with 0 when testing Message-ID: My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. But when I run it under a model rspec, the ids are getting set to 0. I?ve traced it through to where I do: .create where I can see that the id is what I want to set it to in params. Same problem with rspec 2.6 and 2.8. Don?t make me switch to Test::Unit. Anyone? From gisborne at emailuser.net Wed Jan 25 02:43:53 2012 From: gisborne at emailuser.net (Guyren G Howe) Date: Tue, 24 Jan 2012 23:43:53 -0800 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> Message-ID: <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> On Jan 24, 2012, at 11:27 PM, Julian Leviston wrote: > On 25/01/2012, at 5:24 PM, Guyren G Howe wrote: > >> My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. >> >> But when I run it under a model rspec, the ids are getting set to 0. I?ve traced it through to where I do: >> >> .create >> >> where I can see that the id is what I want to set it to in params. >> >> Same problem with rspec 2.6 and 2.8. >> >> Don?t make me switch to Test::Unit. Anyone? > It'd be nice to have a bit of context for this issue. > > It's most likely an issue with your model's validation? Not sure what else to tell you. I?ve a complex bit of logic I want to exercise that?s accepting a hierarchy of objects submitted to the application as JSON. The controller pulls it apart into a hierarchical key-value hash. I?ve a recursive operation that walks this structure, pulling out individual objects and saving them. Everything works fine when I test it manually (e.g. in console). When I run the same sequence of operations with the same values in console (i.e. I tested it by copying the values and operations out of the spec into the console), it all works fine. But it all fails horribly in rspec because the ids are getting overwritten with 0s. I can get to the point in my code where I hand things over to ActiveRecord, and the hash I?m giving to create is exactly what I?m after including the id value. FWIW, the ids I?m trying to use are UUIDs. Since I?m entirely sure the hash I?m handing to create is correct, I?m left with trying to grub around inside ActiveRecord, which I don?t look forward to. So: in what way does RSpec modify the behavior of ActiveRecord that might bear on this? From julian at leviston.net Wed Jan 25 02:27:11 2012 From: julian at leviston.net (Julian Leviston) Date: Wed, 25 Jan 2012 18:27:11 +1100 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: References: Message-ID: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> It'd be nice to have a bit of context for this issue. It's most likely an issue with your model's validation... Julian On 25/01/2012, at 5:24 PM, Guyren G Howe wrote: > My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. > > But when I run it under a model rspec, the ids are getting set to 0. I?ve traced it through to where I do: > > .create > > where I can see that the id is what I want to set it to in params. > > Same problem with rspec 2.6 and 2.8. > > Don?t make me switch to Test::Unit. Anyone? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jko170 at gmail.com Wed Jan 25 03:28:38 2012 From: jko170 at gmail.com (Justin Ko) Date: Wed, 25 Jan 2012 01:28:38 -0700 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> Message-ID: On Jan 25, 2012, at 12:43 AM, Guyren G Howe wrote: > > On Jan 24, 2012, at 11:27 PM, Julian Leviston wrote: > >> On 25/01/2012, at 5:24 PM, Guyren G Howe wrote: >> >>> My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. >>> >>> But when I run it under a model rspec, the ids are getting set to 0. I?ve traced it through to where I do: >>> >>> .create >>> >>> where I can see that the id is what I want to set it to in params. >>> >>> Same problem with rspec 2.6 and 2.8. >>> >>> Don?t make me switch to Test::Unit. Anyone? >> It'd be nice to have a bit of context for this issue. >> >> It's most likely an issue with your model's validation? > > Not sure what else to tell you. I?ve a complex bit of logic I want to exercise that?s accepting a hierarchy of objects submitted to the application as JSON. The controller pulls it apart into a hierarchical key-value hash. I?ve a recursive operation that walks this structure, pulling out individual objects and saving them. > > Everything works fine when I test it manually (e.g. in console). When I run the same sequence of operations with the same values in console (i.e. I tested it by copying the values and operations out of the spec into the console), it all works fine. > > But it all fails horribly in rspec because the ids are getting overwritten with 0s. I can get to the point in my code where I hand things over to ActiveRecord, and the hash I?m giving to create is exactly what I?m after including the id value. > > FWIW, the ids I?m trying to use are UUIDs. > > Since I?m entirely sure the hash I?m handing to create is correct, I?m left with trying to grub around inside ActiveRecord, which I don?t look forward to. So: in what way does RSpec modify the behavior of ActiveRecord that might bear on this? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users http://ariejan.net/2008/08/12/ruby-on-rails-uuid-as-your-activerecord-primary-key Make sure the column is 16-byte binary From patrick at collinatorstudios.com Wed Jan 25 03:42:05 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 25 Jan 2012 00:42:05 -0800 (PST) Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> Message-ID: On Wed, 25 Jan 2012, Justin Ko wrote: > > http://ariejan.net/2008/08/12/ruby-on-rails-uuid-as-your-activerecord-primary-key > > Make sure the column is 16-byte binary > And be sure to update your test database's schema so that it behaves the same as your other environments: rake db:test:clone_structure Patrick J. Collins http://collinatorstudios.com From jko170 at gmail.com Wed Jan 25 03:57:39 2012 From: jko170 at gmail.com (Justin Ko) Date: Wed, 25 Jan 2012 01:57:39 -0700 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> Message-ID: On Jan 25, 2012, at 1:42 AM, Patrick J. Collins wrote: > On Wed, 25 Jan 2012, Justin Ko wrote: > >> >> http://ariejan.net/2008/08/12/ruby-on-rails-uuid-as-your-activerecord-primary-key >> >> Make sure the column is 16-byte binary >> > > And be sure to update your test database's schema so that it behaves the > same as your other environments: > > rake db:test:clone_structure You actually want to use "rake db:test:prepare". It does the same thing as "clone_structure" but doesn't create the nasty structure.sql file. http://stackoverflow.com/questions/7693365/whats-the-difference-between-dbtestclone-dbtestclone-structure-dbtestlo > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From julian at leviston.net Wed Jan 25 06:44:38 2012 From: julian at leviston.net (Julian Leviston) Date: Wed, 25 Jan 2012 22:44:38 +1100 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> Message-ID: <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> See that's HEAPS better! More information. Pffft ... not sure what else to tell us! Okay so NOW to me it sounds a lot like you're using a non-integer as a primary key which I wouldn't do... And also, could it not be a string coersion issue? (ie params coersion) Julian On 25/01/2012, at 6:43 PM, Guyren G Howe wrote: > > On Jan 24, 2012, at 11:27 PM, Julian Leviston wrote: > >> On 25/01/2012, at 5:24 PM, Guyren G Howe wrote: >> >>> My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. >>> >>> But when I run it under a model rspec, the ids are getting set to 0. I?ve traced it through to where I do: >>> >>> .create >>> >>> where I can see that the id is what I want to set it to in params. >>> >>> Same problem with rspec 2.6 and 2.8. >>> >>> Don?t make me switch to Test::Unit. Anyone? >> It'd be nice to have a bit of context for this issue. >> >> It's most likely an issue with your model's validation? > > Not sure what else to tell you. I?ve a complex bit of logic I want to exercise that?s accepting a hierarchy of objects submitted to the application as JSON. The controller pulls it apart into a hierarchical key-value hash. I?ve a recursive operation that walks this structure, pulling out individual objects and saving them. > > Everything works fine when I test it manually (e.g. in console). When I run the same sequence of operations with the same values in console (i.e. I tested it by copying the values and operations out of the spec into the console), it all works fine. > > But it all fails horribly in rspec because the ids are getting overwritten with 0s. I can get to the point in my code where I hand things over to ActiveRecord, and the hash I?m giving to create is exactly what I?m after including the id value. > > FWIW, the ids I?m trying to use are UUIDs. > > Since I?m entirely sure the hash I?m handing to create is correct, I?m left with trying to grub around inside ActiveRecord, which I don?t look forward to. So: in what way does RSpec modify the behavior of ActiveRecord that might bear on this? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From gisborne at emailuser.net Wed Jan 25 16:29:54 2012 From: gisborne at emailuser.net (Guyren G Howe) Date: Wed, 25 Jan 2012 13:29:54 -0800 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> Message-ID: <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> On Jan 25, 2012, at 3:44 AM, Julian Leviston wrote: > Okay so NOW to me it sounds a lot like you're using a non-integer as a primary key which I wouldn't do... I don?t think you?ve tried to write a server app that synchronizes with handheld apps over an unreliable internet connection. UUIDs make things *so* much easier. The decision about the pks is made. Am I understanding from folks here that rspec *won?t work* without integer primary keys? That is a major design flaw, if true. From dchelimsky at gmail.com Wed Jan 25 16:37:40 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 25 Jan 2012 15:37:40 -0600 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> Message-ID: On Wed, Jan 25, 2012 at 3:29 PM, Guyren G Howe wrote: > On Jan 25, 2012, at 3:44 AM, Julian Leviston wrote: > >> Okay so NOW to me it sounds a lot like you're using a non-integer as a primary key which I wouldn't do... > > I don?t think you?ve tried to write a server app that synchronizes with handheld apps over an unreliable internet connection. UUIDs make things *so* much easier. > > The decision about the pks is made. Am I understanding from folks here that rspec *won?t work* without integer primary keys? That is a major design flaw, if true. RSpec provides a thin wrapper around the testing framework that ships with Rails and extends T/U. I'm not sure I understand the problem yet, but I'd be really surprised if it's anything RSpec is doing or failing to do. What versions of RSpec and Rails are you using? From dchelimsky at gmail.com Wed Jan 25 16:45:59 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 25 Jan 2012 15:45:59 -0600 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> Message-ID: On Wed, Jan 25, 2012 at 3:37 PM, David Chelimsky wrote: > On Wed, Jan 25, 2012 at 3:29 PM, Guyren G Howe wrote: >> On Jan 25, 2012, at 3:44 AM, Julian Leviston wrote: >> >>> Okay so NOW to me it sounds a lot like you're using a non-integer as a primary key which I wouldn't do... >> >> I don?t think you?ve tried to write a server app that synchronizes with handheld apps over an unreliable internet connection. UUIDs make things *so* much easier. >> >> The decision about the pks is made. Am I understanding from folks here that rspec *won?t work* without integer primary keys? That is a major design flaw, if true. > > RSpec provides a thin wrapper around the testing framework that ships > with Rails and extends T/U. I'm not sure I understand the problem yet, > but I'd be really surprised if it's anything RSpec is doing or failing > to do. > > What versions of RSpec and Rails are you using? Just looked back at your initial email and see you cited rspec-2.8, but the way Rails handles incoming params in tests changed in either 3.1 or 3.2 (I have to check). Which rails version specifically? From gisborne at emailuser.net Wed Jan 25 16:49:29 2012 From: gisborne at emailuser.net (Guyren G Howe) Date: Wed, 25 Jan 2012 13:49:29 -0800 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> Message-ID: On Jan 25, 2012, at 1:45 PM, David Chelimsky wrote: > Just looked back at your initial email and see you cited rspec-2.8, > but the way Rails handles incoming params in tests changed in either > 3.1 or 3.2 (I have to check). Which rails version specifically? 3.1. Since I was *always* going to be providing a UUID for the pk, I didn?t even bother changing the default value for the pk in the schema. I?m going to try fixing that and see if it?s any better. From dchelimsky at gmail.com Wed Jan 25 16:56:33 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 25 Jan 2012 15:56:33 -0600 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> Message-ID: On Wed, Jan 25, 2012 at 3:49 PM, Guyren G Howe wrote: > On Jan 25, 2012, at 1:45 PM, David Chelimsky wrote: > >> Just looked back at your initial email and see you cited rspec-2.8, >> but the way Rails handles incoming params in tests changed in either >> 3.1 or 3.2 (I have to check). Which rails version specifically? > > 3.1. > > Since I was *always* going to be providing a UUID for the pk, I didn?t even bother changing the default value for the pk in the schema. I?m going to try fixing that and see if it?s any better. I'd start by debugging to see where the wheels fall off. Are you familiar/comfortable with Ruby's debugger? From gisborne at emailuser.net Wed Jan 25 19:50:35 2012 From: gisborne at emailuser.net (Guyren G Howe) Date: Wed, 25 Jan 2012 16:50:35 -0800 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> Message-ID: On Jan 25, 2012, at 1:56 PM, David Chelimsky wrote: > I'd start by debugging to see where the wheels fall off. Are you > familiar/comfortable with Ruby's debugger? Sure. What?s happening is that during the save process, I get to field_changed? in dirty.rb, which does value = column.type_cast(value) when I look at column here, it believes @sql_type = ?integer?. Which seems weird. So at this point, it occurs to me to check this against my test database, and the columns in the test database are indeed integers! How does this come to be? From guyren at mac.com Wed Jan 25 20:20:02 2012 From: guyren at mac.com (Guyren Howe) Date: Wed, 25 Jan 2012 17:20:02 -0800 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> Message-ID: <7770EA80-D112-43DA-A0FE-BBD854BC3C56@mac.com> On Jan 25, 2012, at 4:50 PM, Guyren G Howe wrote: > On Jan 25, 2012, at 1:56 PM, David Chelimsky wrote: > >> I'd start by debugging to see where the wheels fall off. Are you >> familiar/comfortable with Ruby's debugger? > > Sure. > > What?s happening is that during the save process, I get to field_changed? in dirty.rb, which does > > value = column.type_cast(value) > > when I look at column here, it believes @sql_type = ?integer?. Which seems weird. > > So at this point, it occurs to me to check this against my test database, and the columns in the test database are indeed integers! How does this come to be? And note that rake db:test:load doesn?t change anything. From jko170 at gmail.com Wed Jan 25 22:44:22 2012 From: jko170 at gmail.com (Justin Ko) Date: Wed, 25 Jan 2012 20:44:22 -0700 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: <7770EA80-D112-43DA-A0FE-BBD854BC3C56@mac.com> References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> <7770EA80-D112-43DA-A0FE-BBD854BC3C56@mac.com> Message-ID: <867D72A5-793C-430B-8920-AD1692437A9F@gmail.com> On Jan 25, 2012, at 6:20 PM, Guyren Howe wrote: > On Jan 25, 2012, at 4:50 PM, Guyren G Howe wrote: > >> On Jan 25, 2012, at 1:56 PM, David Chelimsky wrote: >> >>> I'd start by debugging to see where the wheels fall off. Are you >>> familiar/comfortable with Ruby's debugger? >> >> Sure. >> >> What?s happening is that during the save process, I get to field_changed? in dirty.rb, which does >> >> value = column.type_cast(value) >> >> when I look at column here, it believes @sql_type = ?integer?. Which seems weird. >> >> So at this point, it occurs to me to check this against my test database, and the columns in the test database are indeed integers! How does this come to be? > > And note that > > rake db:test:load > > doesn?t change anything. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Please paste the table from your schema.rb file. From dchelimsky at gmail.com Wed Jan 25 22:45:09 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 25 Jan 2012 21:45:09 -0600 Subject: [rspec-users] id getting overwritten with 0 when testing In-Reply-To: <7770EA80-D112-43DA-A0FE-BBD854BC3C56@mac.com> References: <2081F0E8-7F40-423D-AB2F-B81ED1F93E3D@leviston.net> <5954F850-A5AF-4A20-95A8-0ADE801089BC@emailuser.net> <040AF088-0CE3-4A0F-B880-D6DFF0D4C670@leviston.net> <2667C6F5-2029-4D72-88B2-802E35E84696@emailuser.net> <7770EA80-D112-43DA-A0FE-BBD854BC3C56@mac.com> Message-ID: On Wed, Jan 25, 2012 at 7:20 PM, Guyren Howe wrote: > On Jan 25, 2012, at 4:50 PM, Guyren G Howe wrote: > >> On Jan 25, 2012, at 1:56 PM, David Chelimsky wrote: >> >>> I'd start by debugging to see where the wheels fall off. Are you >>> familiar/comfortable with Ruby's debugger? >> >> Sure. >> >> What?s happening is that during the save process, I get to field_changed? in dirty.rb, which does >> >> ? ? ? value = column.type_cast(value) >> >> when I look at column here, it believes @sql_type = ?integer?. Which seems weird. >> >> So at this point, it occurs to me to check this against my test database, and the columns in the test database are indeed integers! How does this come to be? > > And note that > > ? ? ? ?rake db:test:load > > doesn?t change anything. I'm not sure what rake db:test:load actually does, but `RAILS_ENV=test rake db:reset` should probably do the trick. What db are you using, btw? From hayafirst at gmail.com Thu Jan 26 10:44:58 2012 From: hayafirst at gmail.com (Yi Wen) Date: Thu, 26 Jan 2012 07:44:58 -0800 (PST) Subject: [rspec-users] What is the pattern for testing a time argument using argument matcher Message-ID: Say I do: ```ruby object.method 5.days.ago ``` In the test I want to test using should_receive like: ```ruby object.should_receive(:method).with(5.days.ago) ``` This will fail since two time objects aren't exact the same. What is the general pattern for testing this in rspec? Thanks From mortenmoellerriis at gmail.com Thu Jan 26 10:54:28 2012 From: mortenmoellerriis at gmail.com (=?iso-8859-1?Q?Morten_M=F8ller_Riis?=) Date: Thu, 26 Jan 2012 16:54:28 +0100 Subject: [rspec-users] What is the pattern for testing a time argument using argument matcher In-Reply-To: References: Message-ID: <9B75D095-879A-4A18-9E1E-2310049E4866@gmail.com> You can use things like Timecop. I prefer to just stub Time.now: timestamp = Time.now.to_i Time.stub(:now).returns(Time.at(timestamp)) Best regards Morten M?ller Riis On Jan 26, 2012, at 4:44 PM, Yi Wen wrote: > Say I do: > > ```ruby > object.method 5.days.ago > ``` > > In the test I want to test using should_receive like: > > ```ruby > object.should_receive(:method).with(5.days.ago) > ``` > > This will fail since two time objects aren't exact the same. > > What is the general pattern for testing this in rspec? > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Thu Jan 26 11:04:00 2012 From: jko170 at gmail.com (Justin Ko) Date: Thu, 26 Jan 2012 09:04:00 -0700 Subject: [rspec-users] What is the pattern for testing a time argument using argument matcher In-Reply-To: References: Message-ID: <29590F15-90F4-4CDC-B22F-86AF85750B23@gmail.com> On Jan 26, 2012, at 8:44 AM, Yi Wen wrote: > Say I do: > > ```ruby > object.method 5.days.ago > ``` > > In the test I want to test using should_receive like: > > ```ruby > object.should_receive(:method).with(5.days.ago) > ``` > > This will fail since two time objects aren't exact the same. > > What is the general pattern for testing this in rspec? > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users In general, it's a good idea not to "hard code" time within the code that uses it. There are many ways to avoid doing this: 1.) Pass in the time. def method_that_uses_time(time) do_something_with_time(time) end it '...' do time = double('time') object.should_receive(:do_something_with_time).with(time) object.method_that_uses_time(time) end 2.) Put the time in it's own method, and stub it. def method_that_uses_time do_something_with_time(the_time) end def the_time; 5.days.ago end it '...' do time = double('time') object.should_receive(:the_time).and_return(time) object.method_that_uses_time end And then there are gems like delorean and timecop, which "freeze" time. From apnea.diving.deep at gmail.com Fri Jan 27 11:14:20 2012 From: apnea.diving.deep at gmail.com (apneadiving) Date: Fri, 27 Jan 2012 08:14:20 -0800 (PST) Subject: [rspec-users] method calls count weirdness... Message-ID: <785e2f07-7b75-49a5-ba47-f4a83d8ac503@b18g2000vbz.googlegroups.com> Hi, I see a really weird behavior there, the following test passes: it "test", :focus do doc = Factory.build(:document) doc.should_receive(:update_project!).exactly(2).times doc.save end But when I do: def update_project! binding.pry #some stuff end I enter the method 3 times through pry... 3 vs 2, who is right? From apnea.diving.deep at gmail.com Fri Jan 27 12:29:39 2012 From: apnea.diving.deep at gmail.com (apneadiving) Date: Fri, 27 Jan 2012 09:29:39 -0800 (PST) Subject: [rspec-users] method calls count weirdness... In-Reply-To: <785e2f07-7b75-49a5-ba47-f4a83d8ac503@b18g2000vbz.googlegroups.com> References: <785e2f07-7b75-49a5-ba47-f4a83d8ac503@b18g2000vbz.googlegroups.com> Message-ID: Sorry, the mistake came from the factory itself. Indeed, the Factory call I really make is slightly different and for a still unknown reason (asked on factory girl google's group), the build method actually created the object... On Jan 27, 5:14?pm, apneadiving wrote: > Hi, > > I see a really weird behavior there, the following test passes: > > ? it "test", :focus do > ? ? doc = Factory.build(:document) > ? ? doc.should_receive(:update_project!).exactly(2).times > ? ? doc.save > ? end > > But when I do: > > def update_project! > ? binding.pry > ? #some stuff > end > I enter the method 3 times through pry... > > 3 vs 2, who is right? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From zach.dennis at gmail.com Fri Jan 27 21:56:23 2012 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 27 Jan 2012 21:56:23 -0500 Subject: [rspec-users] RSpec Requestable Examples Message-ID: I would be interested to hear any thoughts from the community about the ability to request specific examples from a shared example group as expressed in the rspec-requestable-examples gem. Here's the post that introduces them: http://mutuallyhuman.com/blog/2012/01/27/rspec-requestable-examples Git repository: https://github.com/mhs/rspec-requestable-examples -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com @zachdennis (twitter) From info at stupidtuesday.com Sat Jan 28 09:14:29 2012 From: info at stupidtuesday.com (Larry) Date: Sat, 28 Jan 2012 06:14:29 -0800 (PST) Subject: [rspec-users] Rails 3.2.1 breaks stub ? Message-ID: <1e9bcd3c-0cc8-4f91-94b1-a10cdbf297a5@c6g2000vbk.googlegroups.com> Hi, First things first: Thanks for the GREAT gem and all of the work that you and others put into this - it is much appreciated! I read on David Chelimsky's blog that Rails 3.2 broke "stub_model" and that upgrading to rspec-rails-2.8.1 would fix the problem. I have a bunch of specs that ran fine using rspec-rails-2.8.1 and Rails 3.1.3, but when I upgraded to Rails 3.2.1 the following line choked for the following reason (which I believe is the same problem that occurred with "stub_model"): Code: act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError) Error: ArgumentError: wrong number of arguments (0 for 2) Has anyone else seen this? Is there a fix? Am I barking up the wrong tree? Thanks, Larry From dchelimsky at gmail.com Sat Jan 28 17:28:36 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 28 Jan 2012 16:28:36 -0600 Subject: [rspec-users] Rails 3.2.1 breaks stub ? In-Reply-To: <1e9bcd3c-0cc8-4f91-94b1-a10cdbf297a5@c6g2000vbk.googlegroups.com> References: <1e9bcd3c-0cc8-4f91-94b1-a10cdbf297a5@c6g2000vbk.googlegroups.com> Message-ID: On Sat, Jan 28, 2012 at 8:14 AM, Larry wrote: > I have a bunch of specs that ran fine using rspec-rails-2.8.1 and > Rails 3.1.3, but when I upgraded to Rails 3.2.1 the following line > choked for the following reason (which I believe is the same problem > that occurred with "stub_model"): > > Code: > act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError) > > Error: ArgumentError: wrong number of arguments (0 for 2) Please run with the --backtrace flag and post the backtrace so we can see where that error is coming from. From dchelimsky at gmail.com Sat Jan 28 17:56:50 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 28 Jan 2012 16:56:50 -0600 Subject: [rspec-users] RSpec Requestable Examples In-Reply-To: References: Message-ID: On Fri, Jan 27, 2012 at 8:56 PM, Zach Dennis wrote: > I would be interested to hear any thoughts from the community about > the ability to request specific examples from a shared example group > as expressed in the rspec-requestable-examples gem. I love the service it provides, and the consuming API (i.e. :examples => [...]). It clearly communicates to the spec reader what is going on. As for the setup API, how about "requestable_example" instead of "requestable_it". In fact, I think "selectable" would be a more accurate descriptor than "requestable", so "selectable_examples_for" and "selectable_example" would read better for me. I haven't looked at the implementation yet, but I wonder if you could implement the same feature using metadata. Something like this, using "selectable" rather than "requestable" (seems better aligned with what it's doing IMO): shared_examples_for "variable things", :selectable do it "does one thing sometimes", :selectable do # ... end it "does another thing sometimes", :selectable do # ... end it "does one other thing all the time" do # ... end end That way we don't need a new method name to worry about and my issue with the name "requestable_it" goes away. WDYT? > Here's the post that introduces them: > http://mutuallyhuman.com/blog/2012/01/27/rspec-requestable-examples > > Git repository: https://github.com/mhs/rspec-requestable-examples > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com > @zachdennis (twitter) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From zach.dennis at gmail.com Sat Jan 28 23:27:53 2012 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 28 Jan 2012 23:27:53 -0500 Subject: [rspec-users] RSpec Requestable Examples In-Reply-To: References: Message-ID: On Sat, Jan 28, 2012 at 5:56 PM, David Chelimsky wrote: > On Fri, Jan 27, 2012 at 8:56 PM, Zach Dennis wrote: >> I would be interested to hear any thoughts from the community about >> the ability to request specific examples from a shared example group >> as expressed in the rspec-requestable-examples gem. > > I love the service it provides, and the consuming API (i.e. :examples > => [...]). It clearly communicates to the spec reader what is going > on. > > As for the setup API, how about "requestable_example" instead of > "requestable_it". In fact, I think "selectable" would be a more > accurate descriptor than "requestable", so "selectable_examples_for" > and "selectable_example" would read better for me. I agree with you, "selectable" seems like a better fit, but this may not apply in its entirety given your next suggestion... > > I haven't looked at the implementation yet, but I wonder if you could > implement the same feature using metadata. Something like this, using > "selectable" rather than "requestable" (seems better aligned with what > it's doing IMO): > > shared_examples_for "variable things", :selectable do > ?it "does one thing sometimes", :selectable do > ? ?# ... > ?end > > ?it "does another thing sometimes", :selectable do > ? ?# ... > ?end > > ?it "does one other thing all the time" do > ? ?# ... > ?end > end > > That way we don't need a new method name to worry about and my issue > with the name "requestable_it" goes away. > > WDYT? I like what you're suggesting here as well. One reason I had went with a new method name for this was to not conflict with RSpec itself, but given your feedback I will investigate what you propose above. Thanks for taking the time to review and to respond, Zach > >> Here's the post that introduces them: >> http://mutuallyhuman.com/blog/2012/01/27/rspec-requestable-examples >> >> Git repository: https://github.com/mhs/rspec-requestable-examples >> >> -- >> Zach Dennis >> http://www.continuousthinking.com >> http://www.mutuallyhuman.com >> @zachdennis (twitter) >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users -- -- @zachdennis http://www.continuousthinking.com http://www.mutuallyhuman.com From info at stupidtuesday.com Sun Jan 29 08:53:54 2012 From: info at stupidtuesday.com (Larry) Date: Sun, 29 Jan 2012 05:53:54 -0800 (PST) Subject: [rspec-users] Rails 3.2.1 breaks stub ? In-Reply-To: References: <1e9bcd3c-0cc8-4f91-94b1-a10cdbf297a5@c6g2000vbk.googlegroups.com> Message-ID: <257dcf11-793b-4537-a63f-bbffc637efcd@w4g2000vbc.googlegroups.com> Hi David, The trace is below. Like I said, the line in the spec that causes the error (at least I think it does; it works when I comment it out; plus, it fails in all 3 specs where I have a similar line) is: act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError) The line in the controller that bombs out (about 7 lines down in the trace) is: if @act.update_attributes params[:act] flash.now.notice = "Act was updated. (Refresh the list to see changes in the table.)" end Thanks, Larry ArgumentError: wrong number of arguments (0 for 2) /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activerecord-3.2.1/ lib/active_record/errors.rb:104:in `initialize' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ lib/rspec/mocks/message_expectation.rb:181:in `exception' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ lib/rspec/mocks/message_expectation.rb:181:in `raise' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ lib/rspec/mocks/message_expectation.rb:181:in `invoke' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ lib/rspec/mocks/proxy.rb:123:in `message_received' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ lib/rspec/mocks/method_double.rb:92:in `update_attributes' /home/larry/RubyMineProjects/StupidTuesday/app/controllers/act/ acts_controller.rb:49:in `update' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/implicit_render.rb:4:in `send_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ abstract_controller/base.rb:167:in `process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/rendering.rb:10:in `process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ abstract_controller/callbacks.rb:18:in `block in process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ lib/active_support/callbacks.rb:458:in `_run__4120759382721975549__process_action__1657552574701998049__callbacks' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ lib/active_support/callbacks.rb:405:in `__run_callback' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ lib/active_support/callbacks.rb:81:in `run_callbacks' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ abstract_controller/callbacks.rb:17:in `process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/rescue.rb:29:in `process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/instrumentation.rb:30:in `block in process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ lib/active_support/notifications.rb:123:in `block in instrument' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ lib/active_support/notifications/instrumenter.rb:20:in `instrument' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ lib/active_support/notifications.rb:123:in `instrument' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/instrumentation.rb:29:in `process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/params_wrapper.rb:205:in `process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activerecord-3.2.1/ lib/active_record/railties/controller_runtime.rb:18:in `process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ abstract_controller/base.rb:121:in `process' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ abstract_controller/rendering.rb:45:in `process' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/testing.rb:17:in `process_with_new_base_test' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/test_case.rb:464:in `process' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/test_case.rb:49:in `process' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/devise-2.0.0/lib/ devise/test_helpers.rb:19:in `block in process' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/devise-2.0.0/lib/ devise/test_helpers.rb:70:in `catch' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/devise-2.0.0/lib/ devise/test_helpers.rb:70:in `_catch_warden' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/devise-2.0.0/lib/ devise/test_helpers.rb:19:in `process' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ action_controller/test_case.rb:390:in `put' /home/larry/RubyMineProjects/StupidTuesday/spec/controllers/act/ acts_controller_spec.rb:38:in `block (3 levels) in ' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example.rb:80:in `instance_eval' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example.rb:80:in `block in run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example.rb:173:in `with_around_hooks' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example.rb:77:in `run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:355:in `block in run_examples' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:351:in `map' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:351:in `run_examples' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:337:in `run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:338:in `block in run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:338:in `map' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:338:in `run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/command_line.rb:28:in `block (2 levels) in run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/command_line.rb:28:in `map' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/command_line.rb:28:in `block in run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/reporter.rb:34:in `report' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/command_line.rb:25:in `run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/runner.rb:80:in `run_in_process' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/runner.rb:69:in `run' /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/runner.rb:10:in `block in autorun' From dchelimsky at gmail.com Sun Jan 29 10:02:07 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jan 2012 09:02:07 -0600 Subject: [rspec-users] Rails 3.2.1 breaks stub ? In-Reply-To: <257dcf11-793b-4537-a63f-bbffc637efcd@w4g2000vbc.googlegroups.com> References: <1e9bcd3c-0cc8-4f91-94b1-a10cdbf297a5@c6g2000vbk.googlegroups.com> <257dcf11-793b-4537-a63f-bbffc637efcd@w4g2000vbc.googlegroups.com> Message-ID: <68B10F9C-96CA-44E2-8631-E15E9B11D470@gmail.com> On Jan 29, 2012, at 7:53 AM, Larry wrote: > Hi David, > > The trace is below. > > Like I said, the line in the spec that causes the error (at least I > think it does; it works when I comment it out; plus, it fails in all 3 > specs where I have a similar line) is: > > act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError) I didn't notice this before, but the first two lines of the backtrace reveal the problem. The `and_raise` method only works with an error class if that class has a 0-arg initializer [1]. ActiveRecord::StaleObjectError's initializer requires two arguments [2]. This changed between 3.1 and 3.2 [3,4]. I added a placeholder for a feature request to improve the error messaging in rspec-mocks [5]. To fix the problem (with or without helpful error messages from rspec), it's up to you to change act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError) to something like act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError.new(act, :update)) HTH, David [1] http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method [2] https://github.com/rails/rails/blob/master/activerecord/lib/active_record/errors.rb#L101-112 [3] https://github.com/rails/rails/commit/410fa4cf [4] https://github.com/rails/rails/commit/c6f0461 [5] https://github.com/rspec/rspec-mocks/issues/99 > > The line in the controller that bombs out (about 7 lines down in the > trace) is: > > if @act.update_attributes params[:act] > flash.now.notice = "Act was updated. (Refresh the list to see > changes in the table.)" > end > > Thanks, > Larry > > > ArgumentError: wrong number of arguments (0 for 2) > > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activerecord-3.2.1/ > lib/active_record/errors.rb:104:in `initialize' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ > lib/rspec/mocks/message_expectation.rb:181:in `exception' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ > lib/rspec/mocks/message_expectation.rb:181:in `raise' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ > lib/rspec/mocks/message_expectation.rb:181:in `invoke' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ > lib/rspec/mocks/proxy.rb:123:in `message_received' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-mocks-2.8.0/ > lib/rspec/mocks/method_double.rb:92:in `update_attributes' > /home/larry/RubyMineProjects/StupidTuesday/app/controllers/act/ > acts_controller.rb:49:in `update' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/metal/implicit_render.rb:4:in `send_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > abstract_controller/base.rb:167:in `process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/metal/rendering.rb:10:in `process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > abstract_controller/callbacks.rb:18:in `block in process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ > lib/active_support/callbacks.rb:458:in > `_run__4120759382721975549__process_action__1657552574701998049__callbacks' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ > lib/active_support/callbacks.rb:405:in `__run_callback' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ > lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ > lib/active_support/callbacks.rb:81:in `run_callbacks' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > abstract_controller/callbacks.rb:17:in `process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/metal/rescue.rb:29:in `process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/metal/instrumentation.rb:30:in `block in > process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ > lib/active_support/notifications.rb:123:in `block in instrument' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ > lib/active_support/notifications/instrumenter.rb:20:in `instrument' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activesupport-3.2.1/ > lib/active_support/notifications.rb:123:in `instrument' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/metal/instrumentation.rb:29:in `process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/metal/params_wrapper.rb:205:in `process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/activerecord-3.2.1/ > lib/active_record/railties/controller_runtime.rb:18:in > `process_action' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > abstract_controller/base.rb:121:in `process' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > abstract_controller/rendering.rb:45:in `process' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/metal/testing.rb:17:in `process_with_new_base_test' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/test_case.rb:464:in `process' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/test_case.rb:49:in `process' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/devise-2.0.0/lib/ > devise/test_helpers.rb:19:in `block in process' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/devise-2.0.0/lib/ > devise/test_helpers.rb:70:in `catch' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/devise-2.0.0/lib/ > devise/test_helpers.rb:70:in `_catch_warden' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/devise-2.0.0/lib/ > devise/test_helpers.rb:19:in `process' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/actionpack-3.2.1/lib/ > action_controller/test_case.rb:390:in `put' > /home/larry/RubyMineProjects/StupidTuesday/spec/controllers/act/ > acts_controller_spec.rb:38:in `block (3 levels) in ' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example.rb:80:in `instance_eval' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example.rb:80:in `block in run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example.rb:173:in `with_around_hooks' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example.rb:77:in `run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example_group.rb:355:in `block in run_examples' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example_group.rb:351:in `map' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example_group.rb:351:in `run_examples' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example_group.rb:337:in `run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example_group.rb:338:in `block in run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example_group.rb:338:in `map' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/example_group.rb:338:in `run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/command_line.rb:28:in `block (2 levels) in run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/command_line.rb:28:in `map' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/command_line.rb:28:in `block in run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/reporter.rb:34:in `report' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/command_line.rb:25:in `run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/runner.rb:80:in `run_in_process' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/runner.rb:69:in `run' > /home/larry/.rvm/gems/ruby-1.9.3-p0 at stuptues/gems/rspec-core-2.8.0/lib/ > rspec/core/runner.rb:10:in `block in autorun' > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lenny at aps.org Sun Jan 29 15:04:17 2012 From: lenny at aps.org (Lenny Marks) Date: Sun, 29 Jan 2012 15:04:17 -0500 Subject: [rspec-users] RSpec Requestable Examples In-Reply-To: References: Message-ID: <1E98839D-1E79-472A-9EF9-46D69319B83B@aps.org> On Jan 27, 2012, at 9:56 PM, Zach Dennis wrote: > I would be interested to hear any thoughts from the community about > the ability to request specific examples from a shared example group > as expressed in the rspec-requestable-examples gem. > > Here's the post that introduces them: > http://mutuallyhuman.com/blog/2012/01/27/rspec-requestable-examples > > Git repository: https://github.com/mhs/rspec-requestable-examples I've successfully used macros to get similar results, like in the gist below: # macros approach to requestable examples https://gist.github.com/1700352 Curious if you see any big advantages over the macros approach. -lenny > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com > @zachdennis (twitter) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sun Jan 29 16:18:57 2012 From: lists at ruby-forum.com (red line) Date: Sun, 29 Jan 2012 22:18:57 +0100 Subject: [rspec-users] watch Chara vs Alfredsson Live Online Stream online nhl all star 2012 Message-ID: watch Chara vs Alfredsson Live Online Stream online nhl all star 2012 Watch Chara vs Alfredsson Live strea m online espb3 hd tv nhl 2012 http://onlinefoxtv.com/hockey/ ALL Star NHL Sunday Online HD Comcast 29th January|News, Match Replay, Video, photo, Prize ceremony, Watch Team Chara vs Team Alfredsson Live St ream.Watch Team Chara vs Team Alfredsson Live St ream NHL Sunday Online HD Comcast 29th January|News, Match Replay, Video, photo, Prize ceremonyWatch Team Chara vs Team Alfredsson Live St ream NHL Sunday Online HD Comcast 29th January|News, Match Replay.Watch Chara vs Alfredsson Live strea m online espb3 hd tv nhl 2012 click here to watch live http://onlinefoxtv.com/hockey/ NHL Team Chara vs Team Alfredsson 4:00 PM ET Sunday, January 29 NBCSN TV click here to watch live There?s a solid chance you already voted for Team Alfredsson or Team Chara in these polls. Still, if you?re mulling it over or just want to soak in waves and waves of information, then this post should be your tonic. Starting things off, NHL.com has this splendid ?Tale of the Tape? for both teams. Check out the screen shot below. source: (click to enlarge) click here to watch live A few takeaways from that: * Despite Chara?s presence, both teams average the same height and about the same weight. * Alf is the older captain but Chara?s team is almost two years their senior on average. * Team Chara boasts a roster of players who?ve been selected to the All-Star Game far more often. Moving on, if you?re wondering how much each team would cost if they actually played a full season, the wonderful number crunchers at Cap Geek have those answers. Team Alfredsson (via Cap Geek): $90.4 million overall cap hits; $86.8 million in salary this season. Team Chara (via Cap Geek): $106.3 million overall cap hits; $107.5 million in salary this season. So Team Chara is older, slightly bigger, far more expensive and more decorated. Does that make them better? Vote in the polls in this post to share your thoughts ? and let us know in the comments if this post changed your mind at all. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Jan 29 17:11:09 2012 From: lists at ruby-forum.com (jhon pfi) Date: Sun, 29 Jan 2012 23:11:09 +0100 Subject: [rspec-users] 2012 PRO BOWL Livestream Watch Sunday, 29 January fox hq hd tv video 2012 Message-ID: 2012 PRO BOWL Livestream Watch Sunday, 29 January fox hq hd tv video 2012 copy n paste to watch live http://exstreamcoverage.info/252/ Hi NFL fans! You Are Most Well Come To Here To Watch Live Streaming Between NFC vs AFC Live NFL PRO BOWL 2012 On Your PC . It Will Be A Great Fighting Match Because Both Teams Are Strong. So Today?s Match Is Very Important For Both Teams. The NFL PRO BOWL Presenting NFC vs AFC Live Stream Match Will Be A Very Exciting And Surprising Game; You Will See Attractive And Wonderful Play From Showing Link. Though It?s Difficult To Say Who Will Be The Winner Of This Match, We Hope Yours Will Be The Winner In This Game. If You Agree To See The Match Live Free, You Should Keep And Touch With Us. copy n paste to watch live http://exstreamcoverage.info/252/ NFL PRO BOWL 2012 NFC vs AFC LIVE Match : NFL PRO BOWL Date: Sunday, 29 January 2012 Kick-Off: 7:00 PM ET Location : Aloha Stadium, Honolulu, Hawaii We Provided High Quality Software To Watch Live Streaming Match. You Should Not Do Any Tension To Watch Live Match. Watch here 100% HD TV. Please Join With Us Immediately And Enjoy Yourself. I Think It Will Give You Much Pleasure And Amusement. So Why Will You Waste Your Time Elsewhere? Click The Following Link And You Will Get The Way To Watch NFL Live Streaming Online Match . !!! CLICK HERE TO WATCH NFL PRO BOWL LIVE !!! Enjoy Live Stream Online Free NFL Game Today. Don?t Miss To Watch Live The great Match. This Match Will Be Very Enjoyable & You Can Watch Live On FOX,CBS,NBC,ESPN TV. Get The Best Online Sports Coverage On The Net Directly On Your PC. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Jan 29 17:12:39 2012 From: lists at ruby-forum.com (jhon pfi) Date: Sun, 29 Jan 2012 23:12:39 +0100 Subject: [rspec-users] watch NFC vs AFC LIVE stream online pro bowl 2012 nfl football fox hq hd tv Message-ID: watch NFC vs AFC LIVE stream online pro bowl 2012 nfl football fox hq hd tv copy n paste to watch http://exstreamcoverage.info/252/ Hi NFL fans! You Are Most Well Come To Here To Watch Live Streaming Between NFC vs AFC Live NFL PRO BOWL 2012 On Your PC . It Will Be A Great Fighting Match Because Both Teams Are Strong. So Today?s Match Is Very Important For Both Teams. The NFL PRO BOWL Presenting NFC vs AFC Live Stream Match Will Be A Very Exciting And Surprising Game; You Will See Attractive And Wonderful Play From Showing Link. Though It?s Difficult To Say Who Will Be The Winner Of This Match, We Hope Yours Will Be The Winner In This Game. If You Agree To See The Match Live Free, You Should Keep And Touch With Us. copy n paste to watch http://exstreamcoverage.info/252/ NFL PRO BOWL 2012 NFC vs AFC LIVE Match : NFL PRO BOWL Date: Sunday, 29 January 2012 Kick-Off: 7:00 PM ET Location : Aloha Stadium, Honolulu, Hawaii We Provided High Quality Software To Watch Live Streaming Match. You Should Not Do Any Tension To Watch Live Match. Watch here 100% HD TV. Please Join With Us Immediately And Enjoy Yourself. I Think It Will Give You Much Pleasure And Amusement. So Why Will You Waste Your Time Elsewhere? Click The Following Link And You Will Get The Way To Watch NFL Live Streaming Online Match . !!! CLICK HERE TO WATCH NFL PRO BOWL LIVE !!! Enjoy Live Stream Online Free NFL Game Today. Don?t Miss To Watch Live The great Match. This Match Will Be Very Enjoyable & You Can Watch Live On FOX,CBS,NBC,ESPN TV. Get The Best Online Sports Coverage On The Net Directly On Your PC. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Jan 29 17:13:24 2012 From: lists at ruby-forum.com (jhon pfi) Date: Sun, 29 Jan 2012 23:13:24 +0100 Subject: [rspec-users] watch AFC vs NFC LIVE stream online pro bowl 2012 nfl football espn3 hq hd tv Message-ID: watch AFC vs NFC LIVE stream online pro bowl 2012 nfl football espn3 hq hd tv copy n paste to watch http://exstreamcoverage.info/252/ Hi NFL fans! You Are Most Well Come To Here To Watch Live Streaming Between NFC vs AFC Live NFL PRO BOWL 2012 On Your PC . It Will Be A Great Fighting Match Because Both Teams Are Strong. So Today?s Match Is Very Important For Both Teams. The NFL PRO BOWL Presenting NFC vs AFC Live Stream Match Will Be A Very Exciting And Surprising Game; You Will See Attractive And Wonderful Play From Showing Link. Though It?s Difficult To Say Who Will Be The Winner Of This Match, We Hope Yours Will Be The Winner In This Game. If You Agree To See The Match Live Free, You Should Keep And Touch With Us. copy n paste to watch http://exstreamcoverage.info/252/ NFL PRO BOWL 2012 NFC vs AFC LIVE Match : NFL PRO BOWL Date: Sunday, 29 January 2012 Kick-Off: 7:00 PM ET Location : Aloha Stadium, Honolulu, Hawaii We Provided High Quality Software To Watch Live Streaming Match. You Should Not Do Any Tension To Watch Live Match. Watch here 100% HD TV. Please Join With Us Immediately And Enjoy Yourself. I Think It Will Give You Much Pleasure And Amusement. So Why Will You Waste Your Time Elsewhere? Click The Following Link And You Will Get The Way To Watch NFL Live Streaming Online Match . !!! CLICK HERE TO WATCH NFL PRO BOWL LIVE !!! Enjoy Live Stream Online Free NFL Game Today. Don?t Miss To Watch Live The great Match. This Match Will Be Very Enjoyable & You Can Watch Live On FOX,CBS,NBC,ESPN TV. Get The Best Online Sports Coverage On The Net Directly On Your PC. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Jan 29 17:22:03 2012 From: lists at ruby-forum.com (Adam S.) Date: Sun, 29 Jan 2012 23:22:03 +0100 Subject: [rspec-users] render_template on create and update action - unexpected result with namespaced controllers In-Reply-To: References: <65faf8fb-df22-495c-97cb-3efaba40c011@l19g2000yqc.googlegroups.com> Message-ID: <1b9e1e9bd42676cb78a8dacc454a0c0e@ruby-forum.com> Hi Justin, Thanks for your reply. I agree with your suggestions, however the response is fine. Response code == 200 and nothing unusual in the logs. Note that my non-namespaced controllers with similar tests behave as they should. This weird issue only happens for my namespaced controllers. -Adam Justin Ko wrote in post #1037818: > On Dec 12, 2011, at 10:16 AM, astjohn wrote: > >> >> expecting <"edit"> but rendering with <""> >> Any help is greatly appreciated. I've been ignoring these for a while >> and it's time to fix them. >> >> Cheers, >> Adam >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > An empty response body tells me it's redirecting. Couple ways to check > that: > > 1.) Use "puts" and "raise" to see if it even gets to the `respond_with` > 2.) Look at the test logs to see what it's responding with. > 3.) Use `response.response_code.should eq(200)` -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Jan 29 17:43:09 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jan 2012 16:43:09 -0600 Subject: [rspec-users] Sorry for the sports-related distraction In-Reply-To: References: Message-ID: Hey all, Apologies for the sports-related spam we got this afternoon. It was coming through lists at ruby-forum.com, which I've now banned from this list. Cheers, David From info at stupidtuesday.com Mon Jan 30 07:45:41 2012 From: info at stupidtuesday.com (Larry) Date: Mon, 30 Jan 2012 04:45:41 -0800 (PST) Subject: [rspec-users] Rails 3.2.1 breaks stub ? In-Reply-To: <68B10F9C-96CA-44E2-8631-E15E9B11D470@gmail.com> References: <1e9bcd3c-0cc8-4f91-94b1-a10cdbf297a5@c6g2000vbk.googlegroups.com> <257dcf11-793b-4537-a63f-bbffc637efcd@w4g2000vbc.googlegroups.com> <68B10F9C-96CA-44E2-8631-E15E9B11D470@gmail.com> Message-ID: <71da93f6-d2cc-4253-9997-ce33f8ce0fa2@z31g2000vbt.googlegroups.com> Hi David, You were right, and your fix worked like a charm! Thanks for taking the time to reply. And thanks again for what you've done and meant to the Rails community. -- Larry On Jan 29, 10:02?am, David Chelimsky wrote: > On Jan 29, 2012, at 7:53 AM, Larry wrote: > > > Hi David, > > > The trace is below. > > > Like I said, the line in the spec that causes the error (at least I > > think it does; it works when I comment it out; plus, it fails in all 3 > > specs where I have a similar line) is: > > > act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError) > > I didn't notice this before, but the first two lines of the backtrace reveal the problem. > > The `and_raise` method only works with an error class if that class has a 0-arg initializer [1]. ActiveRecord::StaleObjectError's initializer requires two arguments [2]. This changed between 3.1 and 3.2 [3,4]. > > I added a placeholder for a feature request to improve the error messaging in rspec-mocks [5]. > > To fix the problem (with or without helpful error messages from rspec), it's up to you to change > > ? act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError) > > to something like > > ? act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError.new(act, :update)) > > HTH, > David > > [1]http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#a... > [2]https://github.com/rails/rails/blob/master/activerecord/lib/active_re... > [3]https://github.com/rails/rails/commit/410fa4cf > [4]https://github.com/rails/rails/commit/c6f0461 > [5]https://github.com/rspec/rspec-mocks/issues/99 > > From zach.dennis at gmail.com Mon Jan 30 23:46:03 2012 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 30 Jan 2012 23:46:03 -0500 Subject: [rspec-users] RSpec Requestable Examples In-Reply-To: <1E98839D-1E79-472A-9EF9-46D69319B83B@aps.org> References: <1E98839D-1E79-472A-9EF9-46D69319B83B@aps.org> Message-ID: On Sun, Jan 29, 2012 at 3:04 PM, Lenny Marks wrote: > > On Jan 27, 2012, at 9:56 PM, Zach Dennis wrote: > >> I would be interested to hear any thoughts from the community about >> the ability to request specific examples from a shared example group >> as expressed in the rspec-requestable-examples gem. >> >> Here's the post that introduces them: >> http://mutuallyhuman.com/blog/2012/01/27/rspec-requestable-examples >> >> Git repository: https://github.com/mhs/rspec-requestable-examples > > I've successfully used macros to get similar results, like in the gist below: > > # macros approach to requestable examples > https://gist.github.com/1700352 > > Curious if you see any big advantages over the macros approach. > Both approaches can get the job done technically speaking. Here were some goals of rspec-requestable-examples: 1. allowing individual examples to be selected from a shared set of examples 2. when a user selects a non-existent example communicate that to them so they can implement the example or fix their typo 3. be consistent and complementary with RSpec's forms 4. be consistent with RSpec method of delivery (communication) With these goals macros let's you technically do #1 and #2: * modules allow you to create shared sets of methods which can be shared * when referring to a non-existent method Ruby will yell at you But it fails for #3 and #4: * RSpec has a shared example group form already. Modules are not needed at this level because RSpec provides a higher level concept which provides the utility of sharing examples (it just didn't have baked in the ability to select individual examples). Plain old Ruby modules breaks away from this form and does not complement what RSpec is doing. * RSpec communicates to the user in terms of nice spec output for passing, failing, and pending examples. It is less work for a user to stub out an example which is not yet implemented as they write their spec and to move on, then to have to see low-level Ruby undefined method errors and have to go stub it out right then and there. I would rather have an unknown example be pending so the user could take care of it at the time they were ready. And even though using "extend ..." and ruby methods are easy to do (and they do technically work) I find it complicates my specs because they exist at a different level of language and communication than all of the other components in my specs. I prefer the language and forms I use to be as consistent as I can make them in my specs. For me, this helps my rhythm of creating software. There is a level of consistency and continuity I want my code to have and in the rspec-requestable-examples approach I try to find that with what RSpec already provides and how it is already being used. I feel like the macro approach attempts to shoehorn in a solution and that's what I've done that in the past, but I think the requestable/selectable examples is better now for reasons above mentioned. In the original blog post it may have sounded like we hit problem A and then in 5 minutes we came up with a solution. When really that's not the case. I've done the macro approach a number of times in the past and never felt comfortable with it, but it worked and we didn't have a better way. But this time, we finally found a way to make do it a little better (at least in our opinion). -- @zachdennis http://www.continuousthinking.com http://www.mutuallyhuman.com From zach.dennis at gmail.com Tue Jan 31 00:16:22 2012 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 31 Jan 2012 00:16:22 -0500 Subject: [rspec-users] RSpec Requestable Examples In-Reply-To: References: <1E98839D-1E79-472A-9EF9-46D69319B83B@aps.org> Message-ID: I forgot to answer your question more directly. I see things in the requestable/selectable approach which I would like to continue to explore and see if it pans out. So far I like the requestable/selectable approach for the reasons I mentioned in the other email. In short term practical use there are no giant reasons why you should avoid using macros. They provide a valuable utility. As mentioned in the other email I think there are benefits (both short and long term) of not using them in favor of an approach that integrates more consistently and at the same communication level as RSpec. Currently, I think the requestable/selectable has the potential to be that (or maybe help lead a discussion and exploration which becomes that). But it's an experiment that so far has worked a few times. I would hardly say it's time tested or community tested at this point. And if macros are working well for you and my thinking is persuasive, then so be it, just keep on doing what helps you craft good software. Zach On Mon, Jan 30, 2012 at 11:46 PM, Zach Dennis wrote: > On Sun, Jan 29, 2012 at 3:04 PM, Lenny Marks wrote: >> >> On Jan 27, 2012, at 9:56 PM, Zach Dennis wrote: >> >>> I would be interested to hear any thoughts from the community about >>> the ability to request specific examples from a shared example group >>> as expressed in the rspec-requestable-examples gem. >>> >>> Here's the post that introduces them: >>> http://mutuallyhuman.com/blog/2012/01/27/rspec-requestable-examples >>> >>> Git repository: https://github.com/mhs/rspec-requestable-examples >> >> I've successfully used macros to get similar results, like in the gist below: >> >> # macros approach to requestable examples >> https://gist.github.com/1700352 >> >> Curious if you see any big advantages over the macros approach. >> > > Both approaches can get the job done technically speaking. Here were > some goals of rspec-requestable-examples: > > 1. allowing individual examples to be selected from a shared set of examples > 2. when a user selects a non-existent example communicate that to them > so they can implement the example or fix their typo > 3. be consistent and complementary with RSpec's forms > 4. be consistent with RSpec method of delivery (communication) > > With these goals macros let's you technically do #1 and #2: > > * modules allow you to create shared sets of methods which can be shared > * when referring to a non-existent method Ruby will yell at you > > But it fails for #3 and #4: > > * RSpec has a shared example group form already. Modules are not > needed at this level because RSpec provides a higher level concept > which provides the utility of sharing examples (it just didn't have > baked in the ability to select individual examples). Plain old Ruby > modules breaks away from this form and does not complement what RSpec > is doing. > > * RSpec communicates to the user in terms of nice spec output for > passing, failing, and pending examples. It is less work for a user to > stub out an example which is not yet implemented as they write their > spec and to move on, then to have to see low-level Ruby undefined > method errors and have to go stub it out right then and there. I would > rather have an unknown example be pending so the user could take care > of it at the time they were ready. > > And even though using "extend ..." and ruby methods are easy to do > (and they do technically work) I find it complicates my specs because > they exist at a different level of language and communication than all > of the other components in my specs. I prefer the language and forms I > use to be as consistent as I can make them in my specs. For me, this > helps my rhythm of creating software. > > There is a level of consistency and continuity I want my code to have > and in the rspec-requestable-examples approach I try to find that with > what RSpec already provides and how it is already being used. I feel > like the macro approach attempts to shoehorn in a solution and that's > what I've done that in the past, but I think the > requestable/selectable examples is better now for reasons above > mentioned. > > In the original blog post it may have sounded like we hit problem A > and then in 5 minutes we came up with a solution. When really that's > not the case. I've done the macro approach a number of times in the > past and never felt comfortable with it, but it worked and we didn't > have a better way. But this time, we finally found a way to make do it > a little better (at least in our opinion). > > -- > @zachdennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com -- -- @zachdennis http://www.continuousthinking.com http://www.mutuallyhuman.com