From apremdas at gmail.com Thu Sep 1 02:18:28 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Thu, 1 Sep 2011 07:18:28 +0100 Subject: [rspec-users] Better visualizations of spec running time besides --profile? In-Reply-To: References: Message-ID: On 31 August 2011 23:06, John Feminella wrote: > We have about 2,000 specs in a Rails app that take roughly 80 seconds > to run, and I'm trying to improve the performance of things a bit. > > While the profile mode has proven useful so far, it only shows the top > ten slowest specs. Unfortunately, we have lot of specs, and we've > picked off all the low-hanging fruit -- the ones remaining are all < > ~0.1 sec or less. I'd like to streamline things further by seeing if > there's a way to get information about slow spec *files* (not just > individual specs), because I suspect that slower specs will be next to > other slow specs. > > Any ideas about how I can get this information, or do I need to roll > my own benchmarker? > > ~ jf This might be useful http://opinionated-programmer.com/2011/02/profiling-spork-for-faster-start-up-time/ > -- > John Feminella > Principal Consultant, BitsBuilder > LI: http://www.linkedin.com/in/johnxf > SO: http://stackoverflow.com/users/75170/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- ------------------------ Andrew Premdas blog.andrew.premdas.org From ash.moran at patchspace.co.uk Thu Sep 1 04:07:00 2011 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Thu, 1 Sep 2011 09:07:00 +0100 Subject: [rspec-users] Better visualizations of spec running time besides --profile? In-Reply-To: References: Message-ID: <61DAFA20-AC9A-4844-A4A9-6B0F8EB9BD51@patchspace.co.uk> On 31 Aug 2011, at 23:06, John Feminella wrote: > We have about 2,000 specs in a Rails app that take roughly 80 seconds > to run, and I'm trying to improve the performance of things a bit. > > While the profile mode has proven useful so far, it only shows the top > ten slowest specs. Unfortunately, we have lot of specs, and we've > picked off all the low-hanging fruit -- the ones remaining are all < > ~0.1 sec or less. I'd like to streamline things further by seeing if > there's a way to get information about slow spec *files* (not just > individual specs), because I suspect that slower specs will be next to > other slow specs. > > Any ideas about how I can get this information, or do I need to roll > my own benchmarked? Hi John While not an answer to your question, you might like this post "Why I don?t use spork" as an alternative perspective. Kevin's argument is that "Spork solves the wrong problem". After Nikolay taught me that you can have multiple RSpec guards in a Guardfile, having a Rails-independent lib with continuous development testing seems pretty feasible. (I haven't tried it, but I'm tangentially involved in a project where we may be able to give it a go.) BTW there's also the Destroy All Software screencast "Fast Tests With and Without Rails"[2] which I found yesterday, sounds to describe the same idea. I haven't watched it yet though (maybe somebody else here has?) - $9 is a lot of money to spend on a whim you know :) HTH in some way Cheers Ash [1] http://silkandspinach.net/2011/08/08/why-i-dont-use-spork/ [2] https://www.destroyallsoftware.com/screencasts/catalog/fast-tests-with-and-without-rails -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From wolfmanjm at gmail.com Thu Sep 1 05:03:49 2011 From: wolfmanjm at gmail.com (Jim Morris) Date: Thu, 1 Sep 2011 02:03:49 -0700 (PDT) Subject: [rspec-users] How to remove this deprecation warning Message-ID: <2068988.5231.1314867829408.JavaMail.geo-discussion-forums@prcm24> Hi, After upgrading to rails 3.1 and rspec-rails 2.6.1 I get the following deprecation warning, however as far as I can tell I am not defining any examples before it is called. I am using the default spec_helper generated with rails g rspec:install so why this warning? Thanks ***************************************************************** DEPRECATION WARNING: you are using deprecated behaviour that will be removed from RSpec 3. You have set some configuration options after an example group has already been defined. In RSpec 3, this will not be allowed. All configuration should happen before the first example group is defined. The configuration is happening at: .../spec/spec_helper.rb:10 ***************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From timgremore at gmail.com Thu Sep 1 10:58:18 2011 From: timgremore at gmail.com (Tim Gremore) Date: Thu, 1 Sep 2011 09:58:18 -0500 Subject: [rspec-users] rails 3.1 with guard, not detecting changes In-Reply-To: <3426375.1065.1314585399537.JavaMail.geo-discussion-forums@yqgn17> References: <3426375.1065.1314585399537.JavaMail.geo-discussion-forums@yqgn17> Message-ID: Have you added any of the available Guards (guard-rails) to your project? https://github.com/guard/guard/wiki/List-of-available-Guards On Sun, Aug 28, 2011 at 9:36 PM, Chris Habgood wrote: > I am using guard to detect changes and run rspec automatically. It doe > snot seem to see my changes in a model when guard is run. When I run "rake > spec" from the cli rspec runs fine. Does anyone know why this might be > happening? > > _______________________________________________ > 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 Thu Sep 1 11:16:47 2011 From: lenny at aps.org (Lenny Marks) Date: Thu, 1 Sep 2011 11:16:47 -0400 Subject: [rspec-users] How to remove this deprecation warning In-Reply-To: <2068988.5231.1314867829408.JavaMail.geo-discussion-forums@prcm24> References: <2068988.5231.1314867829408.JavaMail.geo-discussion-forums@prcm24> Message-ID: On Sep 1, 2011, at 5:03 AM, Jim Morris wrote: > Hi, > > After upgrading to rails 3.1 and rspec-rails 2.6.1 I get the following deprecation warning, however as far as I can tell I am not defining any examples before it is called. > > I am using the default spec_helper generated with rails g rspec:install so why this warning? > > Thanks > > ***************************************************************** > DEPRECATION WARNING: you are using deprecated behaviour that will > be removed from RSpec 3. > > You have set some configuration options after an example group has > already been defined. In RSpec 3, this will not be allowed. All > configuration should happen before the first example group is > defined. The configuration is happening at: > > .../spec/spec_helper.rb:10 > ***************************************************************** > https://github.com/rspec/rspec-rails/issues/371 From dchelimsky at gmail.com Thu Sep 1 11:29:33 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Sep 2011 10:29:33 -0500 Subject: [rspec-users] Redirect App for RSpec 2 In-Reply-To: References: Message-ID: On Aug 29, 2011, at 6:16 PM, rahul baxi wrote: > Hi, > > My name is Rahul and I'm an RoR developer. > I would like to volunteer and write an app to manage redirects on the rspec.info site. > > Please let me know if anyone else hasn't taken this up already. > > Thanks, > Rahul Thank you for volunteering! You are the first to volunteer, and your help would be welcome. I'll email you off-list with some details in the next day or so. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From chabgood at gmail.com Thu Sep 1 12:35:04 2011 From: chabgood at gmail.com (Chris Habgood) Date: Thu, 1 Sep 2011 11:35:04 -0500 Subject: [rspec-users] rails 3.1 with guard, not detecting changes In-Reply-To: References: <3426375.1065.1314585399537.JavaMail.geo-discussion-forums@yqgn17> Message-ID: Yes I needed to run the guard with bundle exec. On Thu, Sep 1, 2011 at 09:58, Tim Gremore wrote: > Have you added any of the available Guards (guard-rails) to your project? > https://github.com/guard/guard/wiki/List-of-available-Guards > > On Sun, Aug 28, 2011 at 9:36 PM, Chris Habgood wrote: > >> I am using guard to detect changes and run rspec automatically. It doe >> snot seem to see my changes in a model when guard is run. When I run "rake >> spec" from the cli rspec runs fine. Does anyone know why this might be >> happening? >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- *"In matters of style, swim with the current; in matters of principle, stand like a rock." Thomas Jefferson * -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfmanjm at gmail.com Thu Sep 1 16:39:22 2011 From: wolfmanjm at gmail.com (Jim Morris) Date: Thu, 1 Sep 2011 13:39:22 -0700 (PDT) Subject: [rspec-users] How to remove this deprecation warning In-Reply-To: References: <2068988.5231.1314867829408.JavaMail.geo-discussion-forums@prcm24> Message-ID: <18731711.3829.1314909562179.JavaMail.geo-discussion-forums@prfq4> I didn't think of looking in closed bugs :) I guess the fix has not made into the current release. I think this gives me enough clues as to what I need to do to fix it though, thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikerin.slava at gmail.com Fri Sep 2 05:12:24 2011 From: mikerin.slava at gmail.com (slavix) Date: Fri, 2 Sep 2011 02:12:24 -0700 (PDT) Subject: [rspec-users] rspec and shoulda have_indices Message-ID: Hello, I am developing a rails 3.1 app. My Gemfile has shoulda gems Gemfile .. gem "shoulda" gem "shoulda-matchers" In a model spec I have spec file it { should have_indices([:user, :currency]) } And I get this error... NoMethodError: undefined method `has_indices?' for # From dchelimsky at gmail.com Fri Sep 2 09:17:37 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Sep 2011 08:17:37 -0500 Subject: [rspec-users] rspec and shoulda have_indices In-Reply-To: References: Message-ID: <2777D894-7A83-4E82-BEA5-6C33E1B83721@gmail.com> On Sep 2, 2011, at 4:12 AM, slavix wrote: > Hello, > I am developing a rails 3.1 app. My Gemfile has shoulda gems > Gemfile > .. > gem "shoulda" > gem "shoulda-matchers" You only need shoulda-matchers if you're using rspec. > In a model spec I have > spec file > it { should have_indices([:user, :currency]) } > > And I get this error... > > NoMethodError: > undefined method `has_indices?' for # When there is no have_xxx method defined, rspec-expectations implements method_missing such that it assumes you want to send the object the has_xxx? predicate. What your experiencing suggests that there is no have_indices method. Looking at http://rdoc.info/github/thoughtbot/shoulda-matchers/master/Shoulda/Matchers/ActiveRecord, I see a singular have_db_index matcher, but I don't see a pluralized one, so perhaps this method doesn't exist. If it does, then something is wrong with your configuration, as it is not being made available. HTH, David From lists at ruby-forum.com Fri Sep 2 11:57:24 2011 From: lists at ruby-forum.com (Bhavin P.) Date: Fri, 02 Sep 2011 17:57:24 +0200 Subject: [rspec-users] Can we use Cucumber for bakend testing ? Message-ID: <7080e51be3dba7d898ee09d7c3341a86@ruby-forum.com> Hi guys, I am interested in getting information regarding using Cucumber for backend testing? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Sep 2 12:23:27 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Sep 2011 11:23:27 -0500 Subject: [rspec-users] Can we use Cucumber for bakend testing ? In-Reply-To: <7080e51be3dba7d898ee09d7c3341a86@ruby-forum.com> References: <7080e51be3dba7d898ee09d7c3341a86@ruby-forum.com> Message-ID: <6C0DFB33-88F8-45DB-B008-9994C24FBA4E@gmail.com> On Sep 2, 2011, at 10:57 AM, Bhavin P. wrote: > Hi guys, > I am interested in getting information regarding using Cucumber for > backend testing? The Cucumber list is at http://groups.google.com/group/cukes. Cheers, David From mikerin.slava at gmail.com Fri Sep 2 18:58:12 2011 From: mikerin.slava at gmail.com (slavix) Date: Fri, 2 Sep 2011 15:58:12 -0700 (PDT) Subject: [rspec-users] rspec and shoulda have_indices In-Reply-To: <2777D894-7A83-4E82-BEA5-6C33E1B83721@gmail.com> References: <2777D894-7A83-4E82-BEA5-6C33E1B83721@gmail.com> Message-ID: Thanks, I updated spec with correct statements it { should have_db_index([:user, :currency, :tradable]) } ---------- and my db (dev and test) has the indexes Indexes: Action Keyname Type Unique Packed Field Cardinality Collation Null Comment Edit Drop PRIMARY BTREE Yes No id 0 A Edit Drop index_balances_on_currency_id BTREE No No currency_id 0 A YES Edit Drop index_balances_on_tradable_id BTREE No No tradable_id 0 A YES Edit Drop index_balances_on_user_id BTREE No No user_id 0 but I get an error running rspec 2) Balance shoulda validations Failure/Error: it { should have_db_index([:user, :currency, :tradable]) } Expected Balance to have a index on columns user and currency and tradable () On Sep 2, 6:17?am, David Chelimsky wrote: > On Sep 2, 2011, at 4:12 AM, slavix wrote: > > > Hello, > > I am developing a rails 3.1 app. My Gemfile has shoulda gems > > Gemfile > > .. > > gem "shoulda" > > gem "shoulda-matchers" > > You only need shoulda-matchers if you're using rspec. > > > In a model spec I have > > spec file > > ?it { should have_indices([:user, :currency]) } > > > And I get this error... > > > NoMethodError: > > ? ? ? undefined method `has_indices?' for # > > When there is no have_xxx method defined, rspec-expectations implements method_missing such that it assumes you want to send the object the has_xxx? predicate. What your experiencing suggests that there is no have_indices method. Looking athttp://rdoc.info/github/thoughtbot/shoulda-matchers/master/Shoulda/Ma..., I see a singular have_db_index matcher, but I don't see a pluralized one, so perhaps this method doesn't exist. If it does, then something is wrong with your configuration, as it is not being made available. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From mikerin.slava at gmail.com Fri Sep 2 19:07:39 2011 From: mikerin.slava at gmail.com (slavix) Date: Fri, 2 Sep 2011 16:07:39 -0700 (PDT) Subject: [rspec-users] rspec and shoulda have_indices In-Reply-To: <2777D894-7A83-4E82-BEA5-6C33E1B83721@gmail.com> References: <2777D894-7A83-4E82-BEA5-6C33E1B83721@gmail.com> Message-ID: <2ab450ad-67b4-4f03-a93c-1cf435e52758@z1g2000prf.googlegroups.com> now getting Failure/Error: it { should have_db_index([:user, :currency, :tradable]) } Expected Balance to have a index on columns user and currency and tradable () but the indexes are in the db.. (dev and test) Indexes: Action Keyname Type Unique Packed Field Cardinality Collation Null Comment Edit Drop PRIMARY BTREE Yes No id 0 A Edit Drop index_balances_on_currency_id BTREE No No currency_id 0 A YES Edit Drop index_balances_on_tradable_id BTREE No No tradable_id 0 A YES Edit Drop index_balances_on_user_id BTREE No No user_id 0 A YES my migration has def self.up create_table :balances do |t| t.belongs_to :user, :nil => false t.belongs_to :currency, :nil => false t.belongs_to :tradable, :nil => false t.decimal :amount, :precision => 16, :scale => 8, :default => 0.0 t.timestamps end add_index :balances, :user_id add_index :balances, :currency_id add_index :balances, :tradable_id end On Sep 2, 6:17?am, David Chelimsky wrote: > On Sep 2, 2011, at 4:12 AM, slavix wrote: > > > Hello, > > I am developing a rails 3.1 app. My Gemfile has shoulda gems > > Gemfile > > .. > > gem "shoulda" > > gem "shoulda-matchers" > > You only need shoulda-matchers if you're using rspec. > > > In a model spec I have > > spec file > > ?it { should have_indices([:user, :currency]) } > > > And I get this error... > > > NoMethodError: > > ? ? ? undefined method `has_indices?' for # > > When there is no have_xxx method defined, rspec-expectations implements method_missing such that it assumes you want to send the object the has_xxx? predicate. What your experiencing suggests that there is no have_indices method. Looking athttp://rdoc.info/github/thoughtbot/shoulda-matchers/master/Shoulda/Ma..., I see a singular have_db_index matcher, but I don't see a pluralized one, so perhaps this method doesn't exist. If it does, then something is wrong with your configuration, as it is not being made available. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Sep 2 19:20:03 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Sep 2011 18:20:03 -0500 Subject: [rspec-users] rspec and shoulda have_indices In-Reply-To: References: <2777D894-7A83-4E82-BEA5-6C33E1B83721@gmail.com> Message-ID: <48AC68D8-F6D0-433D-AFA2-0095989BA983@gmail.com> I moved your post to the bottom. Please read http://idallen.com/topposting.html On Sep 2, 2011, at 5:58 PM, slavix wrote: > On Sep 2, 6:17 am, David Chelimsky wrote: >> On Sep 2, 2011, at 4:12 AM, slavix wrote: >> >>> Hello, >>> I am developing a rails 3.1 app. My Gemfile has shoulda gems >>> Gemfile >>> .. >>> gem "shoulda" >>> gem "shoulda-matchers" >> >> You only need shoulda-matchers if you're using rspec. >> >>> In a model spec I have >>> spec file >>> it { should have_indices([:user, :currency]) } >> >>> And I get this error... >> >>> NoMethodError: >>> undefined method `has_indices?' for # >> >> When there is no have_xxx method defined, rspec-expectations implements method_missing such that it assumes you want to send the object the has_xxx? predicate. What your experiencing suggests that there is no have_indices method. Looking athttp://rdoc.info/github/thoughtbot/shoulda-matchers/master/Shoulda/Ma..., I see a singular have_db_index matcher, but I don't see a pluralized one, so perhaps this method doesn't exist. If it does, then something is wrong with your configuration, as it is not being made available. > Thanks, > I updated spec with correct statements > > it { should have_db_index([:user, :currency, :tradable]) } > ---------- > and my db (dev and test) has the indexes > > Indexes: > Action Keyname Type Unique Packed Field Cardinality Collation Null > Comment > Edit Drop PRIMARY BTREE Yes No id 0 A > Edit Drop index_balances_on_currency_id BTREE No No currency_id 0 A > YES > Edit Drop index_balances_on_tradable_id BTREE No No tradable_id 0 A > YES > Edit Drop index_balances_on_user_id BTREE No No user_id 0 > > but I get an error running rspec > 2) Balance shoulda validations > Failure/Error: it { should > have_db_index([:user, :currency, :tradable]) } > Expected Balance to have a index on columns user and currency > and tradable () The indexes are on xxx_id. Try { should have_db_index([:user_id, :currency_id, :tradable_id]) } From mguterl at gmail.com Sat Sep 3 08:38:41 2011 From: mguterl at gmail.com (Michael Guterl) Date: Sat, 3 Sep 2011 08:38:41 -0400 Subject: [rspec-users] rspec and shoulda have_indices In-Reply-To: <2ab450ad-67b4-4f03-a93c-1cf435e52758@z1g2000prf.googlegroups.com> References: <2777D894-7A83-4E82-BEA5-6C33E1B83721@gmail.com> <2ab450ad-67b4-4f03-a93c-1cf435e52758@z1g2000prf.googlegroups.com> Message-ID: My guess is that it is checking for an compound index on all of those fields. Try specifying them individually and not in an array. On Fri, Sep 2, 2011 at 7:07 PM, slavix wrote: > now getting > Failure/Error: it { should > have_db_index([:user, :currency, :tradable]) } > ? ? ? Expected Balance to have a ?index on columns user and currency > and tradable () > > but the indexes are in the db.. (dev and test) > Indexes: > Action ? ? ? ? ?Keyname ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Type > Unique ?Packed ?Field ? Cardinality ? ? Collation ? ? ? Null ? ?Comment > Edit ? ?Drop ? ?PRIMARY ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? BTREE ? Yes ? ? No ? ? ?id ? ? ?0 > A > Edit ? ?Drop ? ?index_balances_on_currency_id ? BTREE ? No ? ? ?No ? ? ?currency_id ? ? 0 ? ? ? A > YES > Edit ? ?Drop ? ?index_balances_on_tradable_id ? BTREE ? No ? ? ?No ? ? ?tradable_id ? ? 0 ? ? ? A > YES > Edit ? ?Drop ? ?index_balances_on_user_id ? ? ? ? ? ? ? BTREE ? No ? ? ?No ? ? ?user_id 0 ? ? ? A > YES > > my migration has > def self.up > ? ?create_table :balances do |t| > ? ? ?t.belongs_to :user, :nil => false > ? ? ?t.belongs_to :currency, :nil => false > ? ? ?t.belongs_to :tradable, :nil => false > ? ? ?t.decimal :amount, :precision => 16, :scale => 8, :default => > 0.0 > > ? ? ?t.timestamps > ? ?end > ? ?add_index :balances, :user_id > ? ?add_index :balances, :currency_id > ? ?add_index :balances, :tradable_id > ?end > > > On Sep 2, 6:17?am, David Chelimsky wrote: >> On Sep 2, 2011, at 4:12 AM, slavix wrote: >> >> > Hello, >> > I am developing a rails 3.1 app. My Gemfile has shoulda gems >> > Gemfile >> > .. >> > gem "shoulda" >> > gem "shoulda-matchers" >> >> You only need shoulda-matchers if you're using rspec. >> >> > In a model spec I have >> > spec file >> > ?it { should have_indices([:user, :currency]) } >> >> > And I get this error... >> >> > NoMethodError: >> > ? ? ? undefined method `has_indices?' for # >> >> When there is no have_xxx method defined, rspec-expectations implements method_missing such that it assumes you want to send the object the has_xxx? predicate. What your experiencing suggests that there is no have_indices method. Looking athttp://rdoc.info/github/thoughtbot/shoulda-matchers/master/Shoulda/Ma..., I see a singular have_db_index matcher, but I don't see a pluralized one, so perhaps this method doesn't exist. If it does, then something is wrong with your configuration, as it is not being made available. >> >> HTH, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Sep 3 09:25:29 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 3 Sep 2011 08:25:29 -0500 Subject: [rspec-users] What causes "undefined method `each_pair'"? In-Reply-To: References: <1220926.5683.1314631996267.JavaMail.geo-discussion-forums@yqah42> Message-ID: On Sep 3, 2011, at 5:29 AM, Katrina Owen wrote: > Hi, > > On Mon, Aug 29, 2011 at 5:33 PM, Nick wrote: >> Hey folks. I've been running into this problem a lot lately, and haven't >> been able to figure out what's causing it, nor how to fix it: >> Failure/Error: @importer = SpreadsheetImporter.new @catalog, @excel, >> @photos_dir >> NoMethodError: >> undefined method `each_pair' for # >> # ./app/models/spreadsheet_importer.rb:15:in `initialize' >> # ./spec/models/spreadsheet_importer_spec.rb:25:in `new' >> # ./spec/models/spreadsheet_importer_spec.rb:25:in `block (2 levels) in > (required)>' >> Line 15 of spreadsheet_importer.rb is: >> @products_importer = SpreadsheetImporter::Products.new catalog, spreadsheet >> >> Line 25 of spreadsheet_importer_spec.rb is: >> @importer = SpreadsheetImporter.new @catalog, @excel, @photos_dir >> >> What perplexes me is that I've stubbed out the call to >> SpreadsheetImporter::Products.new , so the class' initializer isn't being >> called. >> Here're some more complete code snippets: >> https://gist.github.com/1178636 > > > In your gist, the describe block doesn't contain an "it" or "specify" > block. Only a before(:each). @Katrina - actually it does contain an example ("it") in the nested group ("describe"). There's just no example in the outer group, but that's a red herring vis a vis this issue. @Nick - the backtrace tells you the whole story. You just have to look at it. The problem is that caused when rspec-mocks is asking the incoming Catalog object if it is == to the expected @catalog (as declared in the 'with' clause). rspec-mocks has a feature that allows you to check against a matcher object (i.e. foo.should_receive(:bar).with(hash_including(:a => 'b'))). This is implemented in https://github.com/rspec/rspec-mocks/blob/v2.5.0/lib/rspec/mocks/argument_expectation.rb. rspec-mocks incorrectly thinks the @catalog is a matcher because it responds to :matches? and :description (see https://github.com/rspec/rspec-mocks/blob/v2.5.0/lib/rspec/mocks/argument_expectation.rb#L29), and therefore wraps it in a MatcherMatcher (https://github.com/rspec/rspec-mocks/blob/v2.5.0/lib/rspec/mocks/argument_matchers.rb#L101-109), which asks the @catalog if it matches? the incoming catalog, which mixes in the Mongoid::Matchers module (https://github.com/mongoid/mongoid/blob/c4675a987925a831dc93ab5c525c99dedf46c841/lib/mongoid/matchers.rb#L19-30). That's how we get to `each_pair` on the Catalog. So the bug is that rspec's definition of what a matcher is is too loose in this case. The problem is that this is RSpec's API for argument matching. If we were to make it more strict now, we'd break unknown numbers of existing specs. To get around this, you can do this: SpreadsheetImporter::Products.stub(:new) do |catalog, excel| catalog.should eq(@catalog) excel.should eq(@excel) @products_importer end This has the same effect as what you are trying to do (stub SpreadsheetImporter::Products returning @products_importer, and verify the arguments are the right ones). HTH, David > Not sure if that's what's causing it, but it would be a place to start. > > Katrina > >> Any help would be greatly appreciated. Thanks! >> Nick > > -- > You received this message because you are subscribed to the Google Groups "rspec" group. > To post to this group, send email to rspec at googlegroups.com. > To unsubscribe from this group, send email to rspec+unsubscribe at googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rspec?hl=en. > From mikerin.slava at gmail.com Sat Sep 3 20:30:00 2011 From: mikerin.slava at gmail.com (slavix) Date: Sat, 3 Sep 2011 17:30:00 -0700 (PDT) Subject: [rspec-users] rspec assert inclusion in.. Message-ID: hello, I would like to assert that an attribute of a model has value among those in an array. How would I do it in rspec? Something like this... describe OptionType do context "shoulda validations" do it { assert_contains :type, ['Type1', 'Type1']} end end From mikerin.slava at gmail.com Sat Sep 3 20:48:46 2011 From: mikerin.slava at gmail.com (slavix) Date: Sat, 3 Sep 2011 17:48:46 -0700 (PDT) Subject: [rspec-users] rspec and shoulda have_indices In-Reply-To: References: <2777D894-7A83-4E82-BEA5-6C33E1B83721@gmail.com> <2ab450ad-67b4-4f03-a93c-1cf435e52758@z1g2000prf.googlegroups.com> Message-ID: <32e5b1aa-2604-4bd4-a34f-59f38c53262e@n19g2000prh.googlegroups.com> Yes. Thank you. I changed the code to list indices one at a time and it worked. it { should have_db_index(:currency_id) } it { should have_db_index(:user_id) } On Sep 3, 5:38?am, Michael Guterl wrote: > My guess is that it is checking for an compound index on all of those > fields. ?Try specifying them individually and not in an array. > > > > > > > > > > On Fri, Sep 2, 2011 at 7:07 PM, slavix wrote: > > now getting > > Failure/Error: it { should > > have_db_index([:user, :currency, :tradable]) } > > ? ? ? Expected Balance to have a ?index on columns user and currency > > and tradable () > > > but the indexes are in the db.. (dev and test) > > Indexes: > > Action ? ? ? ? ?Keyname ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Type > > Unique ?Packed ?Field ? Cardinality ? ? Collation ? ? ? Null ? ?Comment > > Edit ? ?Drop ? ?PRIMARY ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? BTREE ? Yes ? ? No ? ? ?id ? ? ?0 > > A > > Edit ? ?Drop ? ?index_balances_on_currency_id ? BTREE ? No ? ? ?No ? ? ?currency_id ? ? 0 ? ? ? A > > YES > > Edit ? ?Drop ? ?index_balances_on_tradable_id ? BTREE ? No ? ? ?No ? ? ?tradable_id ? ? 0 ? ? ? A > > YES > > Edit ? ?Drop ? ?index_balances_on_user_id ? ? ? ? ? ? ? BTREE ? No ? ? ?No ? ? ?user_id 0 ? ? ? A > > YES > > > my migration has > > def self.up > > ? ?create_table :balances do |t| > > ? ? ?t.belongs_to :user, :nil => false > > ? ? ?t.belongs_to :currency, :nil => false > > ? ? ?t.belongs_to :tradable, :nil => false > > ? ? ?t.decimal :amount, :precision => 16, :scale => 8, :default => > > 0.0 > > > ? ? ?t.timestamps > > ? ?end > > ? ?add_index :balances, :user_id > > ? ?add_index :balances, :currency_id > > ? ?add_index :balances, :tradable_id > > ?end > > > On Sep 2, 6:17?am, David Chelimsky wrote: > >> On Sep 2, 2011, at 4:12 AM, slavix wrote: > > >> > Hello, > >> > I am developing a rails 3.1 app. My Gemfile has shoulda gems > >> > Gemfile > >> > .. > >> > gem "shoulda" > >> > gem "shoulda-matchers" > > >> You only need shoulda-matchers if you're using rspec. > > >> > In a model spec I have > >> > spec file > >> > ?it { should have_indices([:user, :currency]) } > > >> > And I get this error... > > >> > NoMethodError: > >> > ? ? ? undefined method `has_indices?' for # > > >> When there is no have_xxx method defined, rspec-expectations implements method_missing such that it assumes you want to send the object the has_xxx? predicate. What your experiencing suggests that there is no have_indices method. Looking athttp://rdoc.info/github/thoughtbot/shoulda-matchers/master/Shoulda/Ma..., I see a singular have_db_index matcher, but I don't see a pluralized one, so perhaps this method doesn't exist. If it does, then something is wrong with your configuration, as it is not being made available. > > >> HTH, > >> David > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > 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 nick at deadorange.com Sat Sep 3 21:42:58 2011 From: nick at deadorange.com (Nick) Date: Sat, 3 Sep 2011 18:42:58 -0700 (PDT) Subject: [rspec-users] rspec assert inclusion in.. In-Reply-To: References: Message-ID: <26551762.2746.1315100578424.JavaMail.geo-discussion-forums@yqmv39> Hey Slavix. How about this: it 'has a valid "attribute_x" value' do valid_values = %w(some values here) valid_values.should include subject.attribute_x end -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikerin.slava at gmail.com Sat Sep 3 22:03:47 2011 From: mikerin.slava at gmail.com (slavix) Date: Sat, 3 Sep 2011 19:03:47 -0700 (PDT) Subject: [rspec-users] rspec assert inclusion in.. In-Reply-To: <26551762.2746.1315100578424.JavaMail.geo-discussion-forums@yqmv39> References: <26551762.2746.1315100578424.JavaMail.geo-discussion-forums@yqmv39> Message-ID: <04f41af6-ee96-4236-ba34-5cad7e375bbd@14g2000prv.googlegroups.com> Thanks. I wanted to test it as part of model validation like it { should validate_presence_of(:some_attribute).among(['value1', 'value2']) } it { should validate_that(:some_attribute) >= 0 } On Sep 3, 6:42?pm, Nick wrote: > Hey Slavix. How about this: > > it 'has a valid "attribute_x" value' do > ? valid_values = %w(some values here) > ? valid_values.should include subject.attribute_x > end > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From mikerin.slava at gmail.com Sat Sep 3 23:41:17 2011 From: mikerin.slava at gmail.com (slavix) Date: Sat, 3 Sep 2011 20:41:17 -0700 (PDT) Subject: [rspec-users] rspec assert inclusion in.. In-Reply-To: <26551762.2746.1315100578424.JavaMail.geo-discussion-forums@yqmv39> References: <26551762.2746.1315100578424.JavaMail.geo-discussion-forums@yqmv39> Message-ID: this seems to be the way to do it. it { should_validate_numericality_of :amount, :greater_than_or_equal_to => 0 } it { should_validate_inclusion_of :gender, :in => %w( m f ) On Sep 3, 6:42?pm, Nick wrote: > Hey Slavix. How about this: > > it 'has a valid "attribute_x" value' do > ? valid_values = %w(some values here) > ? valid_values.should include subject.attribute_x > end > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From mikerin.slava at gmail.com Sun Sep 4 01:01:35 2011 From: mikerin.slava at gmail.com (slavix) Date: Sat, 3 Sep 2011 22:01:35 -0700 (PDT) Subject: [rspec-users] should validate_numericality_of with greater_than_or_equal_to Message-ID: Hello, I have this in my spec it { should validate_numericality_of(:amount).greater_than_or_equal_to(0) } but I get error: Failure/Error: it { should validate_numericality_of(:amount).greater_than_or_equal_to(0) } NoMethodError: undefined method `greater_than_or_equal_to' for # this page http://remarkable.rubyforge.org/activerecord/classes/Remarkable/ActiveRecord/Matchers.html has method it { should validate_numericality_of(:age).only_integer } and :less_than_or_equal_to is a valid option.. I am confused. How do I spec this? thanks. From chabgood at gmail.com Sat Sep 3 17:17:24 2011 From: chabgood at gmail.com (Chris Habgood) Date: Sat, 3 Sep 2011 14:17:24 -0700 (PDT) Subject: [rspec-users] mongo_mapper validations, rpsec Message-ID: <12366665.943.1315084644109.JavaMail.geo-discussion-forums@yqav15> I have a basic user class and doing rspec validations. When I do a factory create to produce validations it blows up before I can get to the second line to check for errors. Ideas how to get this to perform like AR Validations? MongoMapper::DocumentNotValid: Validation failed: Password can't be blank, Email can't be blank, Password digest can't be blank class User include MongoMapper::Document include ActiveModel::SecurePassword attr_accessible :email, :password key :password_digest, String key :password, String, :required => true key :email, String, :required => true has_secure_password end it "should not authenticate with incorrect password" do user = Factory(:user, :email=> '', :password => '').should have(2).errors #user.should have(2).errors #_on(:name) end -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Sat Sep 3 21:41:03 2011 From: nick at deadorange.com (Nick) Date: Sat, 3 Sep 2011 18:41:03 -0700 (PDT) Subject: [rspec-users] mongo_mapper validations, rpsec In-Reply-To: <12366665.943.1315084644109.JavaMail.geo-discussion-forums@yqav15> References: <12366665.943.1315084644109.JavaMail.geo-discussion-forums@yqav15> Message-ID: <26137414.4305.1315100463370.JavaMail.geo-discussion-forums@yqcd38> Hey Chris. Could you be more specific than "it blows up"? If there's a stack trace, that'd be helpful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chabgood at gmail.com Sun Sep 4 19:06:13 2011 From: chabgood at gmail.com (Chris Habgood) Date: Sun, 4 Sep 2011 18:06:13 -0500 Subject: [rspec-users] mongo_mapper validations, rpsec In-Reply-To: <26137414.4305.1315100463370.JavaMail.geo-discussion-forums@yqcd38> References: <12366665.943.1315084644109.JavaMail.geo-discussion-forums@yqav15> <26137414.4305.1315100463370.JavaMail.geo-discussion-forums@yqcd38> Message-ID: Sorry, it fails validation which it should but it errors out in the cli as opposed to going along and checking, it does not get past the inital factory new line: Failure/Error: user = Factory(:user, :email=> '', :password => '') MongoMapper::DocumentNotValid: Validation failed: Password can't be blank, Email can't be blank, Password digest can't be blank On Sat, Sep 3, 2011 at 20:41, Nick wrote: > Hey Chris. Could you be more specific than "it blows up"? If there's a > stack trace, that'd be helpful. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- *"In matters of style, swim with the current; in matters of principle, stand like a rock." Thomas Jefferson * -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Sun Sep 4 20:06:13 2011 From: nick at deadorange.com (Nick) Date: Sun, 4 Sep 2011 17:06:13 -0700 (PDT) Subject: [rspec-users] mongo_mapper validations, rpsec In-Reply-To: References: <12366665.943.1315084644109.JavaMail.geo-discussion-forums@yqav15> <26137414.4305.1315100463370.JavaMail.geo-discussion-forums@yqcd38> Message-ID: <8869616.1039.1315181173326.JavaMail.geo-discussion-forums@yqja21> What does the backtrace say? -------------- next part -------------- An HTML attachment was scrubbed... URL: From chabgood at gmail.com Sun Sep 4 21:11:19 2011 From: chabgood at gmail.com (Chris Habgood) Date: Sun, 4 Sep 2011 20:11:19 -0500 Subject: [rspec-users] mongo_mapper validations, rpsec In-Reply-To: <8869616.1039.1315181173326.JavaMail.geo-discussion-forums@yqja21> References: <12366665.943.1315084644109.JavaMail.geo-discussion-forums@yqav15> <26137414.4305.1315100463370.JavaMail.geo-discussion-forums@yqcd38> <8869616.1039.1315181173326.JavaMail.geo-discussion-forums@yqja21> Message-ID: MongoMapper::DocumentNotValid: Validation failed: Password can't be blank, Email can't be blank, Password digest can't be blank On Sun, Sep 4, 2011 at 19:06, Nick wrote: > What does the backtrace say? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- *"In matters of style, swim with the current; in matters of principle, stand like a rock." Thomas Jefferson * -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikerin.slava at gmail.com Mon Sep 5 01:36:05 2011 From: mikerin.slava at gmail.com (slavix) Date: Sun, 4 Sep 2011 22:36:05 -0700 (PDT) Subject: [rspec-users] undefined method `dependent' - rspec and shoulda Message-ID: <31fc8029-adb6-499e-bc3d-d3402bf36814@x21g2000prd.googlegroups.com> hello, Getting this error when using shoulda and rspec for model tests. my gemfile ... gem "shoulda-matchers" .. spec file .. it { should have_many(:balances).dependent(:destroy) } error: User shoulda validations Failure/Error: it { should have_many(:balances).dependent(:destroy) } NoMethodError: undefined method `dependent' for # From mikerin.slava at gmail.com Mon Sep 5 21:10:58 2011 From: mikerin.slava at gmail.com (slavix) Date: Mon, 5 Sep 2011 18:10:58 -0700 (PDT) Subject: [rspec-users] rspec and should eql Message-ID: Having troubles with rspec and should eql.. in a rails 3.1 app spec has this User.first.name.should eql('admin') get this error .rvm/gems/ruby-1.9.2-p290/gems/remarkable-4.0.0.alpha4/lib/remarkable/ core/macros.rb:15:in `method_missing': undefined method `eql' for # (NoMethodError) btw, I am using gem "rspec" gem "rspec-rails" gem "remarkable_activerecord", "~> 4.0.0.alpha4" gem 'rspec-rails-ext' gem 'rspec-rails-matchers' gem "cucumber-rails" gem "webrat" gem "capybara" gem "mocha" gem "rcov" gem "faker" gem "shoulda-matchers" From nick at deadorange.com Mon Sep 5 22:08:20 2011 From: nick at deadorange.com (Nick) Date: Mon, 5 Sep 2011 19:08:20 -0700 (PDT) Subject: [rspec-users] rspec and should eql In-Reply-To: References: Message-ID: <3192368.2794.1315274900729.JavaMail.geo-discussion-forums@yqja21> Try "eq" or "equal". -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikerin.slava at gmail.com Mon Sep 5 22:34:36 2011 From: mikerin.slava at gmail.com (slavix) Date: Mon, 5 Sep 2011 19:34:36 -0700 (PDT) Subject: [rspec-users] rspec and should eql In-Reply-To: <3192368.2794.1315274900729.JavaMail.geo-discussion-forums@yqja21> References: <3192368.2794.1315274900729.JavaMail.geo-discussion-forums@yqja21> Message-ID: thanks. tried both with same result. btw documentation says to use eql 5.should eql(5) http://rspec.rubyforge.org/rspec/1.1.9/classes/Spec/Matchers.html#M000429 On Sep 5, 7:08?pm, Nick wrote: > Try "eq" or "equal". From dchelimsky at gmail.com Mon Sep 5 22:50:42 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 5 Sep 2011 21:50:42 -0500 Subject: [rspec-users] rspec and should eql In-Reply-To: References: Message-ID: <6D936F4D-C247-411C-8333-9370CD8E5161@gmail.com> On Sep 5, 2011, at 8:10 PM, slavix wrote: > Having troubles with rspec and should eql.. in a rails 3.1 app > > spec has this > User.first.name.should eql('admin') > > get this error > .rvm/gems/ruby-1.9.2-p290/gems/remarkable-4.0.0.alpha4/lib/remarkable/ > core/macros.rb:15:in `method_missing': undefined method `eql' for > # (NoMethodError) Please post the example that is failing and the full error message. From mikerin.slava at gmail.com Tue Sep 6 00:27:39 2011 From: mikerin.slava at gmail.com (slavix) Date: Mon, 5 Sep 2011 21:27:39 -0700 (PDT) Subject: [rspec-users] rspec and should eql In-Reply-To: <6D936F4D-C247-411C-8333-9370CD8E5161@gmail.com> References: <6D936F4D-C247-411C-8333-9370CD8E5161@gmail.com> Message-ID: <291510a5-60bb-46bc-8eb3-007e116cf5d4@u7g2000pro.googlegroups.com> Here is another example that is failing due to same problem.. class Currency < ActiveRecord::Base end class Bitcoin < Currency include ActiveRecord::Singleton default_scope where(:char_code => 'BTC') end spec: describe Bitcoin do .. Bitcoin.instance.char_code.should eql('BTC') .. end error: /home/slava/.rvm/gems/ruby-1.9.2-p290/gems/remarkable-4.0.0.alpha4/lib/ remarkable/core/macros.rb:15:in `method_missing': undefined method `eql' for # (NoMethodError) from /home/slava/dev/projects/bitcoin-derivatives/spec/models/ bitcoin_spec.rb:4:in `block in ' from /home/slava/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/example_group.rb:142:in `module_eval' from /home/slava/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/example_group.rb:142:in `subclass' from /home/slava/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/example_group.rb:129:in `describe' from /home/slava/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/dsl.rb:5:in `describe' from /home/slava/dev/projects/bitcoin-derivatives/spec/models/ bitcoin_spec.rb:3:in `' From dchelimsky at gmail.com Tue Sep 6 06:40:02 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Sep 2011 05:40:02 -0500 Subject: [rspec-users] rspec and should eql In-Reply-To: References: <3192368.2794.1315274900729.JavaMail.geo-discussion-forums@yqja21> Message-ID: On Sep 5, 2011, at 9:34 PM, slavix wrote: > thanks. tried both with same result. > btw documentation says to use eql > > 5.should eql(5) > http://rspec.rubyforge.org/rspec/1.1.9/classes/Spec/Matchers.html#M000429 This is not why you're having trouble, but rspec-1.1.9 is nearly three years old: http://rubygems.org/gems/rspec/versions/1.1.9. See http://relishapp.com/rspec and http://rubydoc.info/gems/rspec/frames for the latest. Cheers, David From dchelimsky at gmail.com Tue Sep 6 06:44:23 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Sep 2011 05:44:23 -0500 Subject: [rspec-users] rspec and should eql In-Reply-To: <291510a5-60bb-46bc-8eb3-007e116cf5d4@u7g2000pro.googlegroups.com> References: <6D936F4D-C247-411C-8333-9370CD8E5161@gmail.com> <291510a5-60bb-46bc-8eb3-007e116cf5d4@u7g2000pro.googlegroups.com> Message-ID: <8F71DFDC-B7C5-4C69-AB13-08C8C0B0BB7D@gmail.com> On Sep 5, 2011, at 11:27 PM, slavix wrote: > Here is another example that is failing due to same problem.. > > class Currency < ActiveRecord::Base > end > > class Bitcoin < Currency > include ActiveRecord::Singleton > default_scope where(:char_code => 'BTC') > end > > > spec: > describe Bitcoin do > .. > Bitcoin.instance.char_code.should eql('BTC') The describe() method creates an example group, and the it() method creates an example. This ^^ line needs to be in an example: describe Bitcoin do it "defaults to BTC for char_code" do Bitcoin.instance.char_code.should eq('BTC') end end re: whether to use eq, eql, or equal, see http://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/equality-matchers HTH, David > .. > end > > error: > /home/slava/.rvm/gems/ruby-1.9.2-p290/gems/remarkable-4.0.0.alpha4/lib/ > remarkable/core/macros.rb:15:in `method_missing': undefined method > `eql' for # (NoMethodError) From mikerin.slava at gmail.com Tue Sep 6 23:40:12 2011 From: mikerin.slava at gmail.com (slavix) Date: Tue, 6 Sep 2011 20:40:12 -0700 (PDT) Subject: [rspec-users] rspec testing inheritance Message-ID: Hello, Is there any way to test model inheritance in spec? something like.. it { ChildModel.should < ParentModel } thanks. From jko170 at gmail.com Wed Sep 7 01:39:25 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 6 Sep 2011 23:39:25 -0600 Subject: [rspec-users] rspec testing inheritance In-Reply-To: References: Message-ID: On Tue, Sep 6, 2011 at 9:40 PM, slavix wrote: > Hello, > Is there any way to test model inheritance in spec? > > something like.. > it { ChildModel.should < ParentModel } > > thanks. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > specify { ChildModel.should be < ParentModel } -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckponnappa at gmail.com Wed Sep 7 02:53:04 2011 From: ckponnappa at gmail.com (Sidu Ponnappa) Date: Wed, 7 Sep 2011 12:23:04 +0530 Subject: [rspec-users] rspec testing inheritance In-Reply-To: References: Message-ID: Wouldn't this be an implementation bound spec? Best, Sidu. http://c42.in On 7 September 2011 11:09, Justin Ko wrote: > > > On Tue, Sep 6, 2011 at 9:40 PM, slavix wrote: >> >> Hello, >> Is there any way to test model inheritance in spec? >> >> something like.. >> ?it { ChildModel.should < ParentModel } >> >> thanks. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > specify { ChildModel.should be < ParentModel } > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From johnf at bitsbuilder.com Wed Sep 7 07:50:59 2011 From: johnf at bitsbuilder.com (John Feminella) Date: Wed, 7 Sep 2011 07:50:59 -0400 Subject: [rspec-users] Is there a way to get an "around" hook for each spec file? Message-ID: Is there a way to run an `around` block once for every spec *file* (not spec)? (I want to measure which files take the longest amount of time, count the number of specs in each file, and then report the average spec running time for that file.) ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ From matt at mattwynne.net Wed Sep 7 08:03:07 2011 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 7 Sep 2011 13:03:07 +0100 Subject: [rspec-users] rspec testing inheritance In-Reply-To: References: Message-ID: On 7 Sep 2011, at 07:53, Sidu Ponnappa wrote: > > On 7 September 2011 11:09, Justin Ko wrote: >> >> >> On Tue, Sep 6, 2011 at 9:40 PM, slavix wrote: >>> >>> Hello, >>> Is there any way to test model inheritance in spec? >>> >>> something like.. >>> it { ChildModel.should < ParentModel } >>> >>> thanks. > Wouldn't this be an implementation bound spec? +1 Test the behaviour, not the implementation. You could look at using a shared example group if you want to specify that the subclass shared behaviour with the superclass. -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne From johnf at bitsbuilder.com Wed Sep 7 08:08:10 2011 From: johnf at bitsbuilder.com (John Feminella) Date: Wed, 7 Sep 2011 08:08:10 -0400 Subject: [rspec-users] Warning (but not failing) if a method wasn't called? Message-ID: Is there a way to warn but not fail if a particular method wasn't called? That is, I'm looking for something that's halfway between obj.stub(...) and obj.should_receive(...). I'm trying to do something like this: shared_context "with a stubbed geocoder" do before(:each) do @geocoding_client = Geocoding::FakeGeoClient.new # generate warning if the spec doesn't cause a hit to Geocoding.client Geocoding.warn_if_not_received(:client).and_return(@geocoding_client) end end ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ From dchelimsky at gmail.com Wed Sep 7 08:52:24 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Sep 2011 07:52:24 -0500 Subject: [rspec-users] Is there a way to get an "around" hook for each spec file? In-Reply-To: References: Message-ID: <345A372E-BD41-457F-A552-9010607BB868@gmail.com> On Sep 7, 2011, at 6:50 AM, John Feminella wrote: > Is there a way to run an `around` block once for every spec *file* > (not spec)? Not at this point, and I don't think it would be a slam dunk to add. > (I want to measure which files take the longest amount of > time, count the number of specs in each file, and then report the > average spec running time for that file.) You can use before/after all in the outermost group: describe "thing" do before(:all) { set_up_measurements } after(:all) { report_measurements } end HTH, David > > ~ jf > -- > John Feminella > Principal Consultant, BitsBuilder > LI: http://www.linkedin.com/in/johnxf > SO: http://stackoverflow.com/users/75170/ From jko170 at gmail.com Wed Sep 7 09:00:25 2011 From: jko170 at gmail.com (Justin Ko) Date: Wed, 7 Sep 2011 07:00:25 -0600 Subject: [rspec-users] Is there a way to get an "around" hook for each spec file? In-Reply-To: References: Message-ID: On Wed, Sep 7, 2011 at 5:50 AM, John Feminella wrote: > Is there a way to run an `around` block once for every spec *file* > (not spec)? (I want to measure which files take the longest amount of > time, count the number of specs in each file, and then report the > average spec running time for that file.) > > ~ jf > -- > John Feminella > Principal Consultant, BitsBuilder > LI: http://www.linkedin.com/in/johnxf > SO: http://stackoverflow.com/users/75170/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Why not just use the --profile option? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Sep 7 09:06:55 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Sep 2011 08:06:55 -0500 Subject: [rspec-users] rspec testing inheritance In-Reply-To: References: Message-ID: <14652E29-5A22-443F-9E38-FCAB37661F3D@gmail.com> On Sep 7, 2011, at 7:03 AM, Matt Wynne wrote: > On 7 Sep 2011, at 07:53, Sidu Ponnappa wrote: > >> On 7 September 2011 11:09, Justin Ko wrote: >>> >>> On Tue, Sep 6, 2011 at 9:40 PM, slavix wrote: >>>> >>>> Hello, >>>> Is there any way to test model inheritance in spec? >>>> >>>> something like.. >>>> it { ChildModel.should < ParentModel } >>>> >>>> thanks. > >> Wouldn't this be an implementation bound spec? > > +1 > > Test the behaviour, not the implementation. You could look at using a shared example group if you want to specify that the subclass shared behaviour with the superclass. +1 It might not surprise you that I prefer to focus on behavior over implementation (though it might surprise some people who think I like to mock too much! ;)), however ... -1 ... there are absolutely valid cases for focusing on type. In rspec-rails, for example, mock_models need to lie about their type to Rails' internals in order for things to run smoothly. There are, therefore, examples like: mock_model("User").should be_a(User) Any sort of factory that might generate objects of different types in different contexts would warrant this as well. That said, I'll guess that @slavix's motivation here is that there are ParentModel specs and he doesn't want to duplicate them for ChildModel. If that's true, then a shared group is definitely a better option for a number of reasons. The most obvious one is that ChildModel is free to override behavior defined in ParentModel, so the fact that ChildModel < ParentModel is no guarantee that they behave the same way. HTH, David From jko170 at gmail.com Wed Sep 7 09:34:04 2011 From: jko170 at gmail.com (Justin Ko) Date: Wed, 7 Sep 2011 07:34:04 -0600 Subject: [rspec-users] Warning (but not failing) if a method wasn't called? In-Reply-To: References: Message-ID: On Wed, Sep 7, 2011 at 6:08 AM, John Feminella wrote: > Is there a way to warn but not fail if a particular method wasn't > called? That is, I'm looking for something that's halfway between > obj.stub(...) and obj.should_receive(...). I'm trying to do something > like this: > > shared_context "with a stubbed geocoder" do > before(:each) do > @geocoding_client = Geocoding::FakeGeoClient.new > > # generate warning if the spec doesn't cause a hit to Geocoding.client > Geocoding.warn_if_not_received(:client).and_return(@geocoding_client) > end > end > > ~ jf > -- > John Feminella > Principal Consultant, BitsBuilder > LI: http://www.linkedin.com/in/johnxf > SO: http://stackoverflow.com/users/75170/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Why would you want a warn? I can't get my head around this. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Sep 7 09:51:03 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Sep 2011 08:51:03 -0500 Subject: [rspec-users] Warning (but not failing) if a method wasn't called? In-Reply-To: References: Message-ID: On Sep 7, 2011, at 7:08 AM, John Feminella wrote: > Is there a way to warn but not fail if a particular method wasn't > called? That is, I'm looking for something that's halfway between > obj.stub(...) and obj.should_receive(...). I'm trying to do something > like this: > > shared_context "with a stubbed geocoder" do > before(:each) do > @geocoding_client = Geocoding::FakeGeoClient.new > > # generate warning if the spec doesn't cause a hit to Geocoding.client > Geocoding.warn_if_not_received(:client).and_return(@geocoding_client) > end > end There's no support for this in rspec-mocks. You can do the following, but I would not recommend it: before do @geocoding_received_client = false Geocoding.stub(:client) do @geocoding_received_client = true @geocoding_client end end after do warn "Geocoding did not receive :client" unless @@geocoding_received_client end Cheers, David From johnf at bitsbuilder.com Wed Sep 7 10:13:42 2011 From: johnf at bitsbuilder.com (John Feminella) Date: Wed, 7 Sep 2011 10:13:42 -0400 Subject: [rspec-users] Is there a way to get an "around" hook for each spec file? In-Reply-To: References: Message-ID: > Why not just use the --profile option? Doesn't --profile only return the ten slowest examples? I have thousands of specs, so I need a little more data than that. ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Wed, Sep 7, 2011 at 09:00, Justin Ko wrote: > > > On Wed, Sep 7, 2011 at 5:50 AM, John Feminella > wrote: >> >> Is there a way to run an `around` block once for every spec *file* >> (not spec)? (I want to measure which files take the longest amount of >> time, count the number of specs in each file, and then report the >> average spec running time for that file.) >> >> ~ jf >> -- >> John Feminella >> Principal Consultant, BitsBuilder >> LI: http://www.linkedin.com/in/johnxf >> SO: http://stackoverflow.com/users/75170/ >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > Why not just use the --profile option? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From justinbeck at mac.com Thu Sep 8 17:03:50 2011 From: justinbeck at mac.com (Justin Beck) Date: Thu, 08 Sep 2011 17:03:50 -0400 Subject: [rspec-users] rspec and testing IO Message-ID: <50E4D18C-3F36-4707-82F1-6166AFB77000@mac.com> I have a class that expects some input via 'gets'. I found that, when testing, I can do something as simple as this: @foo.stub!(:gets) { "stuff\n" } However that only works in the most simple case. In my case the class asks a series of questions that require a yes/no answer culminating in some end state. The class then asks if the user would like to go through the questions again and waits for a response of yes/no. If I want to test a single run through the questions (answering 'yes' to all of them) and I stub 'gets' to always reply with 'yes' then I have no way of breaking out of the loop. The test I'm running dies and complains of the stack being too deep. So, my question is this: How do folks typically go about testing classes that take input from stdin? I can post more code if necessary but this is a pretty simple question to which, I'm sure, there is a reasonable solution. Thanks! Justin From jko170 at gmail.com Thu Sep 8 19:37:42 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 8 Sep 2011 17:37:42 -0600 Subject: [rspec-users] rspec and testing IO In-Reply-To: <50E4D18C-3F36-4707-82F1-6166AFB77000@mac.com> References: <50E4D18C-3F36-4707-82F1-6166AFB77000@mac.com> Message-ID: On Thu, Sep 8, 2011 at 3:03 PM, Justin Beck wrote: > I have a class that expects some input via 'gets'. I found that, when > testing, I can do something as simple as this: > > @foo.stub!(:gets) { "stuff\n" } > > However that only works in the most simple case. In my case the class asks > a series of questions that require a yes/no answer culminating in some end > state. The class then asks if the user would like to go through the > questions again and waits for a response of yes/no. If I want to test a > single run through the questions (answering 'yes' to all of them) and I stub > 'gets' to always reply with 'yes' then I have no way of breaking out of the > loop. The test I'm running dies and complains of the stack being too deep. > > So, my question is this: > > How do folks typically go about testing classes that take input from stdin? > I can post more code if necessary but this is a pretty simple question to > which, I'm sure, there is a reasonable solution. > > Thanks! > > Justin > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Two ways to approach this. On the unit level, you can stub "gets" and return a different value each time: stubs(:gets).and_return('yes', 'no', 'yes', 'yes', 'no') Each time "gets" is called it will return the next value. On a more high level, I would recommend using the aruba gem with RSpec. Here is how I've done it in my own code: https://github.com/justinko/reverse-polish-calculator/tree/master/spec/acceptance Let us know if any of that works. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephen.bannasch at deanbrook.org Thu Sep 8 21:52:01 2011 From: stephen.bannasch at deanbrook.org (Stephen Bannasch) Date: Thu, 8 Sep 2011 21:52:01 -0400 Subject: [rspec-users] rendering xml with haml through render_template is invalid Message-ID: I have some controller tests for validity of restful XML responses. I'm using haml to generate the xml. When I test externally with curl the response is well-formed XML. However when I test the controllers with rspec2 the response is invalid XML. The following code is part of an rspec shared_example: it "renders the requested #{model_ivar_name_lambda.call} as otml without error" do @model_class.stub!(:find).with("37").and_return(@model_ivar) get :show, :id => "37", :format => 'otml' response.should render_template(:show) The response body includes both well formed and invalid XML: For example running this test: bin/rspec spec/controllers/embeddable/open_responses_controller_spec.rb I've extracted part of the response below to show the element is not closed and is invalid XML Haml normally uses the Rails 3 default format of :html5 for rendering which will render complete elements without a '/>' ending. However it seems that when going through the whole stack the fact that we've registered 'otml' as a 'text/xml' mime_type causes Haml to use the :xhtml format. Mime::Type.register "text/xml", :otml However if I specifically set the Haml format to :xhtml in the spec test like this: it "renders the requested #{model_ivar_name_lambda.call} as otml without error" do Haml::Template.options[:format] = :xhtml @model_class.stub!(:find).with("37").and_return(@model_ivar) get :show, :id => "37", :format => 'otml' assigns[@model_ivar_name].should equal(@model_ivar) response.should render_template(:show) Now the response is well-formed XML. But this is disturbing because I am not doing that in the application. It may be a problem with rspec, rspec-rails, haml or the ActionController::TestResponse rspec delegates to ... ??? From justinbeck at mac.com Thu Sep 8 22:10:17 2011 From: justinbeck at mac.com (Justin Beck) Date: Thu, 08 Sep 2011 22:10:17 -0400 Subject: [rspec-users] rspec and testing IO In-Reply-To: References: Message-ID: <56315B22-9C2A-4766-83DC-C26A7E27F809@mac.com> Thanks Justin, that'll work just fine for my simple case and, in the mean time, I'll look in to aruba also. Much appreciated! Justin On Sep 8, 2011, at 7:38 PM, rspec-users-request at rubyforge.org wrote: > > ------------------------------ > > Message: 8 > Date: Thu, 08 Sep 2011 17:03:50 -0400 > From: Justin Beck > To: rspec-users at rubyforge.org > Subject: [rspec-users] rspec and testing IO > Message-ID: <50E4D18C-3F36-4707-82F1-6166AFB77000 at mac.com> > Content-Type: text/plain; CHARSET=US-ASCII > > I have a class that expects some input via 'gets'. I found that, when testing, I can do something as simple as this: > > @foo.stub!(:gets) { "stuff\n" } > > However that only works in the most simple case. In my case the class asks a series of questions that require a yes/no answer culminating in some end state. The class then asks if the user would like to go through the questions again and waits for a response of yes/no. If I want to test a single run through the questions (answering 'yes' to all of them) and I stub 'gets' to always reply with 'yes' then I have no way of breaking out of the loop. The test I'm running dies and complains of the stack being too deep. > > So, my question is this: > > How do folks typically go about testing classes that take input from stdin? I can post more code if necessary but this is a pretty simple question to which, I'm sure, there is a reasonable solution. > > Thanks! > > Justin > > > ------------------------------ > > Message: 9 > Date: Thu, 8 Sep 2011 17:37:42 -0600 > From: Justin Ko > To: rspec-users > Subject: Re: [rspec-users] rspec and testing IO > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > On Thu, Sep 8, 2011 at 3:03 PM, Justin Beck wrote: > >> I have a class that expects some input via 'gets'. I found that, when >> testing, I can do something as simple as this: >> >> @foo.stub!(:gets) { "stuff\n" } >> >> However that only works in the most simple case. In my case the class asks >> a series of questions that require a yes/no answer culminating in some end >> state. The class then asks if the user would like to go through the >> questions again and waits for a response of yes/no. If I want to test a >> single run through the questions (answering 'yes' to all of them) and I stub >> 'gets' to always reply with 'yes' then I have no way of breaking out of the >> loop. The test I'm running dies and complains of the stack being too deep. >> >> So, my question is this: >> >> How do folks typically go about testing classes that take input from stdin? >> I can post more code if necessary but this is a pretty simple question to >> which, I'm sure, there is a reasonable solution. >> >> Thanks! >> >> Justin >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > Two ways to approach this. On the unit level, you can stub "gets" and return > a different value each time: > > stubs(:gets).and_return('yes', 'no', 'yes', 'yes', 'no') > > Each time "gets" is called it will return the next value. > > On a more high level, I would recommend using the aruba gem with RSpec. Here > is how I've done it in my own code: > > https://github.com/justinko/reverse-polish-calculator/tree/master/spec/acceptance > > Let us know if any of that works. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > End of rspec-users Digest, Vol 63, Issue 6 > ****************************************** From dchelimsky at gmail.com Fri Sep 9 00:51:31 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 8 Sep 2011 23:51:31 -0500 Subject: [rspec-users] rendering xml with haml through render_template is invalid In-Reply-To: References: Message-ID: <103ADC0A-2A54-48EC-87B2-09AA3A03B96E@gmail.com> On Sep 8, 2011, at 8:52 PM, Stephen Bannasch wrote: > I have some controller tests for validity of restful XML responses. > > I'm using haml to generate the xml. > > When I test externally with curl the response is well-formed XML. > > However when I test the controllers with rspec2 the response is invalid XML. > > The following code is part of an rspec shared_example: > > it "renders the requested #{model_ivar_name_lambda.call} as otml without error" do > @model_class.stub!(:find).with("37").and_return(@model_ivar) > get :show, :id => "37", :format => 'otml' > response.should render_template(:show) > > The response body includes both well formed and invalid XML: > > For example running this test: > > bin/rspec spec/controllers/embeddable/open_responses_controller_spec.rb > > I've extracted part of the response below to show the element is not closed and is invalid XML > > > > > Here's the same extract showing valid XML when the request travels through the entire app: > > curl http://localhost:3000/embeddable/open_responses/3.otml > > > > > > Haml normally uses the Rails 3 default format of :html5 for rendering which will render complete elements without a '/>' ending. > > However it seems that when going through the whole stack the fact that we've registered 'otml' as a 'text/xml' mime_type causes Haml to use the :xhtml format. > > Mime::Type.register "text/xml", :otml > > However if I specifically set the Haml format to :xhtml in the spec test like this: > > it "renders the requested #{model_ivar_name_lambda.call} as otml without error" do > Haml::Template.options[:format] = :xhtml > @model_class.stub!(:find).with("37").and_return(@model_ivar) > get :show, :id => "37", :format => 'otml' > assigns[@model_ivar_name].should equal(@model_ivar) > response.should render_template(:show) > > Now the response is well-formed XML. > > But this is disturbing because I am not doing that in the application. > > It may be a problem with rspec, rspec-rails, haml or the ActionController::TestResponse rspec delegates to ... ??? Are you using a mock model or a real one? If mock, try a real one and see what happens. rspec-rails acts as a thin wrapper over the Rails testing framework, which does a lot of things to simulate the runtime environment for you. It's doubtful that rspec is the culprit, but we can rule that out definitively by writing a similar test in the Rails testing framework: class ThingControllerTest < ActionController::TestCase test "...." do # create a real model get :show, :id => "37", :format => 'otml' assert_template "show" end end Does that fail the same way? From ash.moran at patchspace.co.uk Fri Sep 9 08:09:08 2011 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Fri, 9 Sep 2011 13:09:08 +0100 Subject: [rspec-users] Skipping slow specs in Guard but running them from that file In-Reply-To: <20110830134537.GB3208@erisiandiscord.de> References: <20110830060127.GA3208@erisiandiscord.de> <97DA81BD-A160-4EA8-A437-C7BCD1642557@patchspace.co.uk> <20110830134537.GB3208@erisiandiscord.de> Message-ID: <1FFC734D-CC83-40BA-B0B4-07163265E734@patchspace.co.uk> On 30 Aug 2011, at 14:45, Nikolay Sturm wrote: > * Ash Moran [2011-08-30]: >> I never thought of that! Yes, that could also work, probably better in >> fact. It just involves running multiple Guard processes, although >> there's Terminitor[1] for that! > > A single guard process is enough, it will start all guards defined in > your Guardfile. This just came in really handy. I'm helping out now and again with a new Rails project using Spork and Guard. We moved some code out into lib/ and set up a separate `guard 'rspec'` to only monitor lib/ and spec/lib/. Took a bit of jiggery-pokery to make it not use Spork and Rails but it works now, and is as fast as RSpec runs get. I'm probably late to the party with Guard, as I used AutoTest for years. But for the benefit of anyone new to either: if you're not doing continuous testing, _you should be_*, and if you are, you should never be happy with how fast they run. They can always be faster. Always. Guard makes it much easier than AutoTest to tune the test runs, and does other cool stuff too. *It was David Chelimsky who said the exact same thing to me on this list, what- 5 or 6 years ago? One of the best pieces of advice I ever got. Funny how for all the new fangled technology we've had in the mean time (and for all I've learnt since), I'm still using the same basic development process I used back then? Ash -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From dchelimsky at gmail.com Fri Sep 9 08:51:04 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 9 Sep 2011 07:51:04 -0500 Subject: [rspec-users] rspec rake task + bundler: feedback requested Message-ID: <5B24ADDF-1EB8-4EF8-9F0A-205C91A6ED7D@gmail.com> Hey folks, RSpec's assumption that the existence of a Gemfile means you want to use Bundler to configure runtime environment is flawed. We added a skip_bundler option to the rake task, but that was a temporary hack to get us through a release without breaking existing suites. This still presents a problem for anyone who doesn't have Bundler installed, and is contributing to an open source project that does use Bundler for installing gems as a convenience, but doesn't need it for the runtime environment. I'm sure there are other cases. If this topic interests you, please take a look at https://github.com/rspec/rspec-core/issues/454 and my proposed fix at https://github.com/rspec/rspec-core/commit/f90b9f5c6ce5efdfb5cf18efbe27adf87d0fa848. I think this is a good solution to the problem, but I want to get some feedback before merging this to master. Please comment in the issue and/or the commit on http://github.com/ rather than here. I'd like to keep the conversation in one place. Thanks, David From lists at ruby-forum.com Sun Sep 11 20:48:30 2011 From: lists at ruby-forum.com (wolf volpi) Date: Mon, 12 Sep 2011 02:48:30 +0200 Subject: [rspec-users] generate user-readable tests from Rspec tests? Message-ID: <7a19a93e4713c6abd0cd235bbede07f4@ruby-forum.com> I have been writing manual tests and dabbled in Cucumber. I like that end users can read the Cucumber tests. Is there a way to generate user-readable tests from Rspec tests or Watir tests? Thank you. -- Posted via http://www.ruby-forum.com/. From ckponnappa at gmail.com Mon Sep 12 03:37:45 2011 From: ckponnappa at gmail.com (Sidu Ponnappa) Date: Mon, 12 Sep 2011 13:07:45 +0530 Subject: [rspec-users] generate user-readable tests from Rspec tests? In-Reply-To: <7a19a93e4713c6abd0cd235bbede07f4@ruby-forum.com> References: <7a19a93e4713c6abd0cd235bbede07f4@ruby-forum.com> Message-ID: You can write your own Formatter[1] if the existing ones don't work for you. The default RSpec document format is already available[2] - just pass `--format doc` as a param when running the specs. Best, Sidu. http://c42.in http://blog.sidu.in [1] http://cheat.errtheblog.com/s/rspec/ [2] https://github.com/jeffkreeftmeijer/fuubar On 12 September 2011 06:18, wolf volpi wrote: > I have been writing manual tests and dabbled in Cucumber. I like that > end users can read the Cucumber tests. Is there a way to generate > user-readable tests from Rspec tests or Watir tests? > > Thank you. > > -- > Posted via http://www.ruby-forum.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 chandu.shenoy at gmail.com Mon Sep 12 08:44:58 2011 From: chandu.shenoy at gmail.com (Chandu80) Date: Mon, 12 Sep 2011 05:44:58 -0700 (PDT) Subject: [rspec-users] Rspec error while running jruby -S rake spec Message-ID: <538e9228-5231-4904-bf80-378fc52f3332@i14g2000prd.googlegroups.com> Hello All, I followed steps to install Rspec as in the link pasted below. http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-factory-girl/ I have jRuby on Rails installed on my machine.Hence all commands need to be run with jruby -S extension. However when I run the jruby -S rake spec command,I get the following error as shown below. ************************************************************************************************************************ C:\Rspec Test>jruby -S rake spec --trace (in C:/Rspec Test) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment db pool warmup starting...................... Mon Sep 12 18:05:23 +0530 2011 warmed up...........===========================================.............. db pool warmup done........................... Mon Sep 12 18:05:23 +0530 2011 ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:load (first_time) ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge RspecTest already exists ** Execute db:test:load ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load rake aborted! ActiveRecord::ActiveRecordError: ERROR: cannot drop table channels because other objects depend on it Detail: constraint messages_channel_id_fk on table messages depends on table c hannels constraint invitation_workflow_mapping_invitor on table invitation_workflows dep ends on table channels constraint invitation_workflow_mapping_invited_whom_id on table invitation_workf lows depends on table channels constraint invitation_workflow_mapping_invited_for_channel_id on table invitatio n_workflows depends on table channels Hint: Use DROP ... CASCADE to drop the dependent objects too.: DROP TABLE "cha nnels" C:/Rspec Test/vendor/rails/activerecord/lib/active_record/ connection_adapters/ab stract_adapter.rb:219:in `log' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7- java/lib/a ctive_record/connection_adapters/jdbc_adapter.rb:582:in `execute' C:/Rspec Test/vendor/rails/activerecord/lib/active_record/ connection_adapters/ab stract/schema_statements.rb:187:in `drop_table' C:/Rspec Test/vendor/rails/activerecord/lib/active_record/ connection_adapters/ab stract/schema_statements.rb:107:in `create_table' C:/Rspec Test/vendor/rails/activerecord/lib/active_record/migration.rb: 352:in `m ethod_missing' C:/Rspec Test/vendor/rails/activerecord/lib/active_record/migration.rb: 328:in `s ay_with_time' c:/jruby-1.5.0/lib/ruby/1.8/benchmark.rb:293:in `measure' C:/Rspec Test/vendor/rails/activerecord/lib/active_record/migration.rb: 328:in `s ay_with_time' C:/Rspec Test/vendor/rails/activerecord/lib/active_record/migration.rb: 348:in `m ethod_missing' C:/Rspec Test/db/schema.rb:139 C:/Rspec Test/vendor/rails/activerecord/lib/active_record/schema.rb: 43:in `insta nce_eval' C:/Rspec Test/vendor/rails/activerecord/lib/active_record/schema.rb: 43:in `defin e' C:/Rspec Test/db/schema.rb:12 C:/Rspec Test/db/schema.rb:269:in `load' C:/Rspec Test/vendor/rails/railties/lib/tasks/databases.rake:269 c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with _call_chain' c:/jruby-1.5.0/lib/ruby/1.8/monitor.rb:191:in `mon_synchronize' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with _call_chain' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' C:/Rspec Test/vendor/rails/railties/lib/tasks/databases.rake:317 c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with _call_chain' c:/jruby-1.5.0/lib/ruby/1.8/monitor.rb:191:in `mon_synchronize' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with _call_chain' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' C:/Rspec Test/vendor/rails/railties/lib/tasks/databases.rake:391 c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with _call_chain' c:/jruby-1.5.0/lib/ruby/1.8/monitor.rb:191:in `mon_synchronize' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with _call_chain' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prer equisites' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prer equisites' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with _call_chain' c:/jruby-1.5.0/lib/ruby/1.8/monitor.rb:191:in `mon_synchronize' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with _call_chain' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_tas k' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_e xception_handling' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_e xception_handling' c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:19:in `load' c:/jruby-1.5.0/bin/rake:19 ************************************************************************************************************************ What does the error indicate,I tried commenting all lines having drop_database statement in them. Another thing is that the database already has tables and by using the tutorial I have just added another table for the bank-account. Kindly let me know what exactly needs to be done in this case Thanks & Regards Chandrika From lists at ruby-forum.com Mon Sep 12 19:51:32 2011 From: lists at ruby-forum.com (wolf volpi) Date: Tue, 13 Sep 2011 01:51:32 +0200 Subject: [rspec-users] generate user-readable tests from Rspec tests? In-Reply-To: References: <7a19a93e4713c6abd0cd235bbede07f4@ruby-forum.com> Message-ID: <09747fb866b0058e730e2f5d58556f71@ruby-forum.com> Sorry my question was not clear. Sidu Ponnappa wrote in post #1021398: > You can write your own Formatter[1] if the existing ones don't work for > you. > [1] http://cheat.errtheblog.com/s/rspec/ I am mostly testing Java web applications (I do not know Rails). Will Formatter[1] work without Rails? > The default RSpec document format is already available[2] - just pass > `--format doc` as a param when running the specs. > [2] https://github.com/jeffkreeftmeijer/fuubar I watched the video and it looks like it just outputs test results. The output should be a test-narrative similar to: Given some context When some event occurs Then I expect some outcome. Then the end users will review the test-narrative before we start development. Is there a tool that can generate a test-narrative from Rspec tests or Watir tests? Thanks Sidu. -- Posted via http://www.ruby-forum.com/. From patrick at collinatorstudios.com Mon Sep 12 21:34:06 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 12 Sep 2011 18:34:06 -0700 (PDT) Subject: [rspec-users] how can I get rspec to generate files with rails g model ...? Message-ID: I just added RSpec 2 to a project that has been using test::unit, and I was wondering how to get RSpec to automatically build test files for my models? when I do rails g rspec:model foo, I just get see CREATE spec/models/foo_spec.rb (no other files) if I do rails g model foo, I see "invoke test unit", and a test/unit/foo_test.rb gets created.. .. Is there something I need to do to get rspec invoked? Thanks. Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Tue Sep 13 02:06:48 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Sep 2011 08:06:48 +0200 Subject: [rspec-users] how can I get rspec to generate files with rails g model ...? In-Reply-To: References: Message-ID: On Sep 13, 2011, at 3:34 AM, Patrick J. Collins wrote: > I just added RSpec 2 to a project that has been using test::unit, and I was > wondering how to get RSpec to automatically build test files for my models? > > when I do rails g rspec:model foo, I just get see CREATE > spec/models/foo_spec.rb (no other files) > > if I do rails g model foo, I see "invoke test unit", and a > test/unit/foo_test.rb gets created.. > > .. Is there something I need to do to get rspec invoked? See the Configure section on https://www.relishapp.com/rspec/rspec-rails. Cheers, David From dchelimsky at gmail.com Tue Sep 13 02:14:03 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Sep 2011 08:14:03 +0200 Subject: [rspec-users] generate user-readable tests from Rspec tests? In-Reply-To: <09747fb866b0058e730e2f5d58556f71@ruby-forum.com> References: <7a19a93e4713c6abd0cd235bbede07f4@ruby-forum.com> <09747fb866b0058e730e2f5d58556f71@ruby-forum.com> Message-ID: On Sep 13, 2011, at 1:51 AM, wolf volpi wrote: > Sorry my question was not clear. > > Sidu Ponnappa wrote in post #1021398: >> You can write your own Formatter[1] if the existing ones don't work for >> you. >> [1] http://cheat.errtheblog.com/s/rspec/ > I am mostly testing Java web applications (I do not know Rails). Will > Formatter[1] work without Rails? > >> The default RSpec document format is already available[2] - just pass >> `--format doc` as a param when running the specs. >> [2] https://github.com/jeffkreeftmeijer/fuubar > I watched the video and it looks like it just outputs test results. The > output should be a test-narrative similar to: > Given some context > When some event occurs > Then I expect some outcome. > Then the end users will review the test-narrative before we start > development. Is there a tool that can generate a test-narrative from > Rspec tests or Watir tests? See https://www.relishapp.com/rspec/rspec-core/docs/command-line/format-option. Also, you can get a good start by typing `rspec help`. HTH, David From dchelimsky at gmail.com Tue Sep 13 02:32:19 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Sep 2011 08:32:19 +0200 Subject: [rspec-users] Rspec error while running jruby -S rake spec In-Reply-To: <538e9228-5231-4904-bf80-378fc52f3332@i14g2000prd.googlegroups.com> References: <538e9228-5231-4904-bf80-378fc52f3332@i14g2000prd.googlegroups.com> Message-ID: <0D185D85-209C-4FE9-A0AC-A26E12B14576@gmail.com> On Sep 12, 2011, at 2:44 PM, Chandu80 wrote: > Hello All, > > I followed steps to install Rspec as in the link pasted below. > > http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-factory-girl/ > > I have jRuby on Rails installed on my machine.Hence all commands need > to be run with jruby -S extension. > However when I run the jruby -S rake spec command,I get the following > error as shown below. > > ************************************************************************************************************************ > C:\Rspec Test>jruby -S rake spec --trace > (in C:/Rspec Test) > ** Invoke spec (first_time) > ** Invoke db:test:prepare (first_time) > ** Invoke db:abort_if_pending_migrations (first_time) > ** Invoke environment (first_time) > ** Execute environment > db pool warmup starting...................... Mon Sep 12 18:05:23 > +0530 2011 > > warmed > up...........===========================================.............. > > db pool warmup done........................... Mon Sep 12 18:05:23 > +0530 2011 > > ** Execute db:abort_if_pending_migrations > ** Execute db:test:prepare > ** Invoke db:test:load (first_time) > ** Invoke db:test:purge (first_time) > ** Invoke environment > ** Execute db:test:purge > RspecTest already exists > ** Execute db:test:load > ** Invoke db:schema:load (first_time) > ** Invoke environment > ** Execute db:schema:load When you run a spec suite, RSpec delegates to Rails to do the same work it does before and after a test suite. One task it runs is db:schema:load, which is defined in Rails. It asks the configured database for a list of tables and then tries to drop and recreate them. This ensures that any data from a previous run is removed, and the schema for the test db matches that of the development db. > rake aborted! > ActiveRecord::ActiveRecordError: ERROR: cannot drop table channels > because other > objects depend on it > Detail: constraint messages_channel_id_fk on table messages depends > on table c > hannels > constraint invitation_workflow_mapping_invitor on table > invitation_workflows dep > ends on table channels > constraint invitation_workflow_mapping_invited_whom_id on table > invitation_workf > lows depends on table channels > constraint invitation_workflow_mapping_invited_for_channel_id on table > invitatio > n_workflows depends on table channels > Hint: Use DROP ... CASCADE to drop the dependent objects too.: DROP > TABLE "cha > nnels" > What does the error indicate,I tried commenting all lines having > drop_database statement in them. > Another thing is that the database already has tables and by using the > tutorial I have just added another table for the bank-account. > Kindly let me know what exactly needs to be done in this case The message tells you the underlying problem: there are database constraints that are not allowing the tables to be deleted in the order in which the rake task is trying to delete them. For whatever reason, the active record adapter you are using is not invoking a cascading delete. What adapter are you using? What database? Also, what other db-related gems do you have in the app? Just type `jruby -S bundle show`. From lists at ruby-forum.com Tue Sep 13 06:03:39 2011 From: lists at ruby-forum.com (wolf volpi) Date: Tue, 13 Sep 2011 12:03:39 +0200 Subject: [rspec-users] generate user-readable tests from Rspec tests? In-Reply-To: <7a19a93e4713c6abd0cd235bbede07f4@ruby-forum.com> References: <7a19a93e4713c6abd0cd235bbede07f4@ruby-forum.com> Message-ID: <01d29ff6987ea647027fa33c646d76b8@ruby-forum.com> Now I understand better. Goggling "rspec formatter" shows that there are formatters for progress, documentation, and html. This will make more sense after I learn Rspec. Thank you David and Sidu. -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Tue Sep 13 06:56:21 2011 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 13 Sep 2011 11:56:21 +0100 Subject: [rspec-users] Assertions for asynchronous behaviour Message-ID: Hi all, In GOOS[1] they use an assertion called assertEventually which samples the system for a success state until a certain timeout has elapsed. This allows you to synchronise the tests with asynchronous code. Do we have an equivalent of that in the Ruby / RSpec world already? I know capybara has wait_until { } but that's fairly rudimentary - the failure message isn't very helpful. Is there anything else already out there? [1] http://www.growing-object-oriented-software.com/ cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Tue Sep 13 10:38:15 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 13 Sep 2011 10:38:15 -0400 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: References: Message-ID: On Tue, Sep 13, 2011 at 6:56 AM, Matt Wynne wrote: > Hi all, > > In GOOS[1] they use an assertion called assertEventually which samples the > system for a success state until a certain timeout has elapsed. This allows > you to synchronise the tests with asynchronous code. > > Do we have an equivalent of that in the Ruby / RSpec world already? I know > capybara has wait_until { } but that's fairly rudimentary - the failure > message isn't very helpful. Is there anything else already out there? > > [1] http://www.growing-object-oriented-software.com/ > > cheers, > Matt > > -- > Freelance programmer & coach > Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak > Helles?y) > Founder, http://relishapp.com > +44(0)7974430184 | http://twitter.com/mattwynne > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > the_object.should eventually_call(:foo).within(2).seconds Sounds like Matt is going to make us this matcher! :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From alex at stinky.com Tue Sep 13 12:41:54 2011 From: alex at stinky.com (Alex Chaffee) Date: Tue, 13 Sep 2011 09:41:54 -0700 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: References: Message-ID: Sure. "wait_for" is a method Brian Takita and I originally wrote for use in Selenium tests, then IIRC it made it into the Selenium gem and now lots of libraries use it (or their own version -- I make no patent claim on polling :-)). The wait_for I remember allowed you to customize the failure message. Let me go see if it's on GitHub or anything... Ah, here's one: https://github.com/pivotal/selenium/blob/master/lib/selenium/wait_for.rb (Maybe I should put it in Wrong.) - A On Tue, Sep 13, 2011 at 3:56 AM, Matt Wynne wrote: > Hi all, > In GOOS[1] they use an assertion called assertEventually which samples the > system for a success state until a certain timeout has elapsed. This allows > you to synchronise the tests with asynchronous code. > Do we have an equivalent of that in the Ruby / RSpec world already? I know > capybara has wait_until { } but that's fairly rudimentary - the failure > message isn't very helpful. Is there anything else already out there? > [1]?http://www.growing-object-oriented-software.com/ > cheers, > Matt > -- > Freelance programmer &?coach > Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak > Helles?y) > Founder,?http://relishapp.com > +44(0)7974430184 | http://twitter.com/mattwynne > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Alex Chaffee - alex at stinky.com http://alexch.github.com http://twitter.com/alexch From ckponnappa at gmail.com Tue Sep 13 13:06:39 2011 From: ckponnappa at gmail.com (Sidu Ponnappa) Date: Tue, 13 Sep 2011 22:36:39 +0530 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: References: Message-ID: > the_object.should eventually_call(:foo).within(2).seconds TDDing multithreaded apps. Good times. Best, Sidu. http://blog.sidu.in On 13 September 2011 20:08, Justin Ko wrote: > > > On Tue, Sep 13, 2011 at 6:56 AM, Matt Wynne wrote: >> >> Hi all, >> In GOOS[1] they use an assertion called assertEventually which samples the >> system for a success state until a certain timeout has elapsed. This allows >> you to synchronise the tests with asynchronous code. >> Do we have an equivalent of that in the Ruby / RSpec world already? I know >> capybara has wait_until { } but that's fairly rudimentary - the failure >> message isn't very helpful. Is there anything else already out there? >> [1]?http://www.growing-object-oriented-software.com/ >> cheers, >> Matt >> -- >> Freelance programmer &?coach >> Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak >> Helles?y) >> Founder,?http://relishapp.com >> +44(0)7974430184 | http://twitter.com/mattwynne >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > the_object.should eventually_call(:foo).within(2).seconds > Sounds like Matt is going to make us this matcher! :) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mikerin.slava at gmail.com Tue Sep 13 20:53:39 2011 From: mikerin.slava at gmail.com (slavix) Date: Tue, 13 Sep 2011 17:53:39 -0700 (PDT) Subject: [rspec-users] rspec and should have_many through Message-ID: <078e2b3d-e9ee-4fbd-9aeb-274e6871e977@n39g2000prl.googlegroups.com> Hi, Anyone can help me with rspec shoulda validations please. I can't get the syntax right for these validations. Please correct me it { should have_one :tradable, :through => :trade_order} it { should belong_to :source, :polymorphic => true } it { should have_many :transfers, :as => :source } this is for Rspec 2, rails 3.1, gem "rspec-rails" gem "remarkable_activerecord", "~> 4.0.0.alpha4" gem 'rspec-rails-ext' gem 'rspec-rails-matchers' gem "shoulda-matchers" From jko170 at gmail.com Tue Sep 13 21:41:15 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 13 Sep 2011 21:41:15 -0400 Subject: [rspec-users] rspec and should have_many through In-Reply-To: <078e2b3d-e9ee-4fbd-9aeb-274e6871e977@n39g2000prl.googlegroups.com> References: <078e2b3d-e9ee-4fbd-9aeb-274e6871e977@n39g2000prl.googlegroups.com> Message-ID: On Tue, Sep 13, 2011 at 8:53 PM, slavix wrote: > Hi, > Anyone can help me with rspec shoulda validations please. > I can't get the syntax right for these validations. Please correct me > > it { should have_one :tradable, :through => :trade_order} > it { should belong_to :source, :polymorphic => true } > it { should have_many :transfers, :as => :source } > > this is for Rspec 2, rails 3.1, > > gem "rspec-rails" > gem "remarkable_activerecord", "~> 4.0.0.alpha4" > gem 'rspec-rails-ext' > gem 'rspec-rails-matchers' > gem "shoulda-matchers" > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I believe remarkable_activerecord and shoulda-matchers have conflicting API's? Also, looks like you need to use methods, rather than symbols as arguments: it { should have_one(:tradable).through(:trade_order) } -------------- next part -------------- An HTML attachment was scrubbed... URL: From rob at stardotstar.com Wed Sep 14 06:51:24 2011 From: rob at stardotstar.com (Rob Aldred) Date: Wed, 14 Sep 2011 11:51:24 +0100 Subject: [rspec-users] Mocking expectations on I/O operations Message-ID: I'm speccing a small lib which manipulates image files using mini_magick. The lib creates various temporary files during the process, the lib then cleans up the temporary files at the end. I'm trying to mock expectations that the calls are made to File#delete Eg... File.should_receive(:delete).once.with("#{generator.tmp_path}-full\.png") File.should_receive(:delete).once.with("#{generator.tmp_path}-screen\.png") File.should_receive(:delete).once.with("#{generator.tmp_path}-shadow\.png") The method in the lib that does this is: Class IconGenerator ... private def cleanup # remove temporary files created during # image manipulation ['-full','_screen','_shadow','_back_shadow'].each do |f| File.delete "#{tmp_path}#{f}.png" if File.exists? "#{tmp_path}#{f}.png" end end ... end The expectations work fine, however, I also have an after block which also calls File.delete to clean up the final version of the manipulated test image after(:each) do # cleanup manipulated image File.delete out_dir.join('MenuIcon.png') if File.exists? out_dir.join('MenuIcon.png') end The File.delete call in the after block fails because its calling the mocked version of File.delete This results in the following error: Failure/Error: File.delete out_dir.join('MenuIcon.png') if File.exists? out_dir.join('MenuIcon.png') NoMethodError: undefined method `=~' for # My next step was to stub the write method for every instance of MiniMagick::Image However I will then no longer be able to test the cleanup because the delete method will never be called if the files don't exist. I'm pretty sure I'm going about this the wrong way and making it difficult for myself here. Appreciate any help & feedback Thanks -- Rob From jko170 at gmail.com Wed Sep 14 20:52:37 2011 From: jko170 at gmail.com (Justin Ko) Date: Wed, 14 Sep 2011 20:52:37 -0400 Subject: [rspec-users] Mocking expectations on I/O operations In-Reply-To: References: Message-ID: On Wed, Sep 14, 2011 at 6:51 AM, Rob Aldred wrote: > I'm speccing a small lib which manipulates image files using mini_magick. > The lib creates various temporary files during the process, the lib then > cleans up the temporary files at the end. > > I'm trying to mock expectations that the calls are made to File#delete > > Eg... > File.should_receive(:delete).once.with("#{generator.tmp_path}-full\.png") > File.should_receive(:delete).once.with("#{generator.tmp_path}-screen\.png") > File.should_receive(:delete).once.with("#{generator.tmp_path}-shadow\.png") > > The method in the lib that does this is: > > Class IconGenerator > ... > > private > > def cleanup > # remove temporary files created during > # image manipulation > ['-full','_screen','_shadow','_back_shadow'].each do |f| > File.delete "#{tmp_path}#{f}.png" if File.exists? "#{tmp_path}#{f}.png" > end > end > ... > end > > The expectations work fine, however, I also have an after block which also > calls File.delete to clean up the final version of the manipulated test > image > > after(:each) do > # cleanup manipulated image > File.delete out_dir.join('MenuIcon.png') if File.exists? > out_dir.join('MenuIcon.png') > end > > The File.delete call in the after block fails because its calling the > mocked version of File.delete > This results in the following error: > > Failure/Error: File.delete out_dir.join('MenuIcon.png') if File.exists? > out_dir.join('MenuIcon.png') > NoMethodError: > undefined method `=~' for > # > > > My next step was to stub the write method for every instance of > MiniMagick::Image > However I will then no longer be able to test the cleanup because the > delete method will never be called if the files don't exist. > > I'm pretty sure I'm going about this the wrong way and making it difficult > for myself here. > Appreciate any help & feedback > > Thanks > -- > Rob > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Give `File.unstub(:delete)` in your `after` block. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chandu.shenoy at gmail.com Thu Sep 15 03:54:51 2011 From: chandu.shenoy at gmail.com (Chandu80) Date: Thu, 15 Sep 2011 00:54:51 -0700 (PDT) Subject: [rspec-users] Rspec error while running jruby -S rake spec In-Reply-To: <0D185D85-209C-4FE9-A0AC-A26E12B14576@gmail.com> References: <538e9228-5231-4904-bf80-378fc52f3332@i14g2000prd.googlegroups.com> <0D185D85-209C-4FE9-A0AC-A26E12B14576@gmail.com> Message-ID: <3da004b3-e741-4e4c-a832-db25c8639aef@k29g2000yqf.googlegroups.com> Hi David, So does that mean that I need to manually delete all other tables for the rake command to run successfully? Regards Chandrika On Sep 13, 11:32?am, David Chelimsky wrote: > On Sep 12, 2011, at 2:44 PM, Chandu80 wrote: > > > > > Hello All, > > > I followed steps to install Rspec as in the link pasted below. > > >http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-fac... > > > I have jRuby on Rails installed on my machine.Hence all commands need > > to be run with jruby -S extension. > > However when I run the jruby -S rake spec command,I get the following > > error as shown below. > > > ************************************************************************************************************************ > > C:\Rspec Test>jruby -S rake spec --trace > > (in C:/Rspec Test) > > ** Invoke spec (first_time) > > ** Invoke db:test:prepare (first_time) > > ** Invoke db:abort_if_pending_migrations (first_time) > > ** Invoke environment (first_time) > > ** Execute environment > > db pool warmup starting...................... Mon Sep 12 18:05:23 > > +0530 2011 > > > warmed > > up...........===========================================.............. > > > db pool warmup done........................... Mon Sep 12 18:05:23 > > +0530 2011 > > > ** Execute db:abort_if_pending_migrations > > ** Execute db:test:prepare > > ** Invoke db:test:load (first_time) > > ** Invoke db:test:purge (first_time) > > ** Invoke environment > > ** Execute db:test:purge > > RspecTest already exists > > ** Execute db:test:load > > ** Invoke db:schema:load (first_time) > > ** Invoke environment > > ** Execute db:schema:load > > When you run a spec suite, RSpec delegates to Rails to do the same work it does before and after a test suite. One task it runs is db:schema:load, which is defined in Rails. It asks the configured database for a list of tables and then tries to drop and recreate them. This ensures that any data from a previous run is removed, and the schema for the test db matches that of the development db. > > > > > rake aborted! > > ActiveRecord::ActiveRecordError: ERROR: cannot drop table channels > > because other > > objects depend on it > > ?Detail: constraint messages_channel_id_fk on table messages depends > > on table c > > hannels > > constraint invitation_workflow_mapping_invitor on table > > invitation_workflows dep > > ends on table channels > > constraint invitation_workflow_mapping_invited_whom_id on table > > invitation_workf > > lows depends on table channels > > constraint invitation_workflow_mapping_invited_for_channel_id on table > > invitatio > > n_workflows depends on table channels > > ?Hint: Use DROP ... CASCADE to drop the dependent objects too.: DROP > > TABLE "cha > > nnels" > > > > > What does the error indicate,I tried commenting all lines having > > drop_database statement in them. > > Another thing is that the database already has tables and by using the > > tutorial I have just added another table for the bank-account. > > Kindly let me know what exactly needs to be done in this case > > The message tells you the underlying problem: there are database constraints that are not allowing the tables to be deleted in the order in which the rake task is trying to delete them. For whatever reason, the active record adapter you are using is not invoking a cascading delete. What adapter are you using? What database? Also, what other db-related gems do you have in the app? Just type `jruby -S bundle show`. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Sep 15 05:01:02 2011 From: lists at ruby-forum.com (Aashish Kiran) Date: Thu, 15 Sep 2011 11:01:02 +0200 Subject: [rspec-users] rspec not recognised Message-ID: Hi, I am using Rails 3 and rspec-rails gem. When try to run rspec spec\models\profile.rb I get result as follows: 'rspec' is not recognized as an internal or external command, Can you help? Thanks, Aashish -- Posted via http://www.ruby-forum.com/. From rob at stardotstar.com Thu Sep 15 05:05:59 2011 From: rob at stardotstar.com (Rob Aldred) Date: Thu, 15 Sep 2011 10:05:59 +0100 Subject: [rspec-users] Mocking expectations on I/O operations In-Reply-To: References: Message-ID: <61A553E4678643AD8E8815DDE8DA01F0@stardotstar.com> Thanks Justin, That isnt working... its erroring with: The method `delete` was not stubbed or was already unstubbed -- Rob Aldred Software Developer rob at stardotstar.com twitter: stardotstar 47 Newton Street, Manchester, M1 1FT T: +44 (0) 161 236 9740 ___________________________________________________ This email and any files or ideas transmitted within it are sent in confidence and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager at info at stardotstar.com On Thursday, 15 September 2011 at 01:52, Justin Ko wrote: > > > On Wed, Sep 14, 2011 at 6:51 AM, Rob Aldred wrote: > > I'm speccing a small lib which manipulates image files using mini_magick. > > The lib creates various temporary files during the process, the lib then cleans up the temporary files at the end. > > > > I'm trying to mock expectations that the calls are made to File#delete > > > > Eg... > > File.should_receive(:delete).once.with("#{generator.tmp_path}-full\.png") > > File.should_receive(:delete).once.with("#{generator.tmp_path}-screen\.png") > > File.should_receive(:delete).once.with("#{generator.tmp_path}-shadow\.png") > > > > The method in the lib that does this is: > > > > Class IconGenerator > > ... > > > > private > > > > def cleanup > > # remove temporary files created during > > # image manipulation > > ['-full','_screen','_shadow','_back_shadow'].each do |f| > > File.delete "#{tmp_path}#{f}.png" if File.exists? "#{tmp_path}#{f}.png" > > end > > end > > ... > > end > > > > The expectations work fine, however, I also have an after block which also calls File.delete to clean up the final version of the manipulated test image > > > > after(:each) do > > # cleanup manipulated image > > File.delete out_dir.join('MenuIcon.png') if File.exists? out_dir.join('MenuIcon.png') > > end > > > > The File.delete call in the after block fails because its calling the mocked version of File.delete > > This results in the following error: > > > > Failure/Error: File.delete out_dir.join('MenuIcon.png') if File.exists? out_dir.join('MenuIcon.png') > > NoMethodError: > > undefined method `=~' for # > > > > > > My next step was to stub the write method for every instance of MiniMagick::Image > > However I will then no longer be able to test the cleanup because the delete method will never be called if the files don't exist. > > > > I'm pretty sure I'm going about this the wrong way and making it difficult for myself here. > > Appreciate any help & feedback > > > > Thanks > > -- > > Rob > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > > http://rubyforge.org/mailman/listinfo/rspec-users > > Give `File.unstub(:delete)` in your `after` block. > > Attachments: > - ATT00001..txt > From dchelimsky at gmail.com Thu Sep 15 05:31:04 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Sep 2011 11:31:04 +0200 Subject: [rspec-users] Rspec error while running jruby -S rake spec In-Reply-To: <3da004b3-e741-4e4c-a832-db25c8639aef@k29g2000yqf.googlegroups.com> References: <538e9228-5231-4904-bf80-378fc52f3332@i14g2000prd.googlegroups.com> <0D185D85-209C-4FE9-A0AC-A26E12B14576@gmail.com> <3da004b3-e741-4e4c-a832-db25c8639aef@k29g2000yqf.googlegroups.com> Message-ID: On Sep 15, 2011, at 9:54 AM, Chandu80 wrote: > On Sep 13, 11:32 am, David Chelimsky wrote: >> On Sep 12, 2011, at 2:44 PM, Chandu80 wrote: >> >> >> >>> Hello All, >> >>> I followed steps to install Rspec as in the link pasted below. >> >>> http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-fac... >> >>> I have jRuby on Rails installed on my machine.Hence all commands need >>> to be run with jruby -S extension. >>> However when I run the jruby -S rake spec command,I get the following >>> error as shown below. >> >>> ************************************************************************************************************************ >>> C:\Rspec Test>jruby -S rake spec --trace >>> (in C:/Rspec Test) >>> ** Invoke spec (first_time) >>> ** Invoke db:test:prepare (first_time) >>> ** Invoke db:abort_if_pending_migrations (first_time) >>> ** Invoke environment (first_time) >>> ** Execute environment >>> db pool warmup starting...................... Mon Sep 12 18:05:23 >>> +0530 2011 >> >>> warmed >>> up...........===========================================.............. >> >>> db pool warmup done........................... Mon Sep 12 18:05:23 >>> +0530 2011 >> >>> ** Execute db:abort_if_pending_migrations >>> ** Execute db:test:prepare >>> ** Invoke db:test:load (first_time) >>> ** Invoke db:test:purge (first_time) >>> ** Invoke environment >>> ** Execute db:test:purge >>> RspecTest already exists >>> ** Execute db:test:load >>> ** Invoke db:schema:load (first_time) >>> ** Invoke environment >>> ** Execute db:schema:load >> >> When you run a spec suite, RSpec delegates to Rails to do the same work it does before and after a test suite. One task it runs is db:schema:load, which is defined in Rails. It asks the configured database for a list of tables and then tries to drop and recreate them. This ensures that any data from a previous run is removed, and the schema for the test db matches that of the development db. >> >> >> >>> rake aborted! >>> ActiveRecord::ActiveRecordError: ERROR: cannot drop table channels >>> because other >>> objects depend on it >>> Detail: constraint messages_channel_id_fk on table messages depends >>> on table c >>> hannels >>> constraint invitation_workflow_mapping_invitor on table >>> invitation_workflows dep >>> ends on table channels >>> constraint invitation_workflow_mapping_invited_whom_id on table >>> invitation_workf >>> lows depends on table channels >>> constraint invitation_workflow_mapping_invited_for_channel_id on table >>> invitatio >>> n_workflows depends on table channels >>> Hint: Use DROP ... CASCADE to drop the dependent objects too.: DROP >>> TABLE "cha >>> nnels" >> >> >> >>> What does the error indicate,I tried commenting all lines having >>> drop_database statement in them. >>> Another thing is that the database already has tables and by using the >>> tutorial I have just added another table for the bank-account. >>> Kindly let me know what exactly needs to be done in this case >> >> The message tells you the underlying problem: there are database constraints that are not allowing the tables to be deleted in the order in which the rake task is trying to delete them. For whatever reason, the active record adapter you are using is not invoking a cascading delete. What adapter are you using? What database? Also, what other db-related gems do you have in the app? Just type `jruby -S bundle show`. > So does that mean that I need to manually delete all other tables for > the rake command to run successfully? That needs to happen but the activerecord adapter you are using should handle it implicitly for you. Which one are you using? From ash.moran at patchspace.co.uk Thu Sep 15 06:08:35 2011 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Thu, 15 Sep 2011 11:08:35 +0100 Subject: [rspec-users] Mocking expectations on I/O operations In-Reply-To: <61A553E4678643AD8E8815DDE8DA01F0@stardotstar.com> References: <61A553E4678643AD8E8815DDE8DA01F0@stardotstar.com> Message-ID: <4BED7FFB-0B01-4CEC-A94F-12D83101F937@patchspace.co.uk> On 15 Sep 2011, at 10:05, Rob Aldred wrote: > Thanks Justin, > That isnt working... its erroring with: > > The method `delete` was not stubbed or was already unstubbed Hi Rob For reasons I could go into, when I'm coding myself I don't usually stub out file system access or other third party systems. Rather, I write an adapter that behaves in the way I expect and test it using the real file system, then test the rest of the system against a mock. That avoids this category of problem. What you're doing here appears to be mixing both real (from mini_magick) and stubbed (your own library's) calls to filesystem code, and I think it's the asymmetry that's biting you. I could explain the above in more detail*, but in lieu of that, here's another angle: can you run the code in a subdirectory per image and nuke that after? That way you only have one point to hit for the cleanup. HTH Ash * As a quick example, you might have a TempFileCleaner object in place of IconGenerator#cleanup, seeded with all the potential temp filenames, or some algorithm to figure them out -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From ckponnappa at gmail.com Thu Sep 15 06:20:21 2011 From: ckponnappa at gmail.com (Sidu Ponnappa) Date: Thu, 15 Sep 2011 15:50:21 +0530 Subject: [rspec-users] rspec not recognised In-Reply-To: References: Message-ID: If you've installed the gem via bundler, you'll need to either do 'bundle exec rspec' or run the build via rake (do `rake -T | grep spec` to list all the spec related tasks). You should also take a look at http://blog.davidchelimsky.net/2011/07/18/stop-typing-bundle-exec/ In any event, most editors and IDEs allow you to run your test(s) inline using a shortcut, so you may want to explore that option as it's far more convenient/productive than switching to a shell. Best, Sidu. http://c42.in http://blog.sidu.in On 15 September 2011 14:31, Aashish Kiran wrote: > Hi, > I am using Rails 3 and rspec-rails gem. > When try to run rspec spec\models\profile.rb > I get result as follows: > 'rspec' is not recognized as an internal or external command, > Can you help? > > Thanks, > Aashish > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rob at stardotstar.com Thu Sep 15 06:53:01 2011 From: rob at stardotstar.com (Rob Aldred) Date: Thu, 15 Sep 2011 11:53:01 +0100 Subject: [rspec-users] Mocking expectations on I/O operations In-Reply-To: <4BED7FFB-0B01-4CEC-A94F-12D83101F937@patchspace.co.uk> References: <61A553E4678643AD8E8815DDE8DA01F0@stardotstar.com> <4BED7FFB-0B01-4CEC-A94F-12D83101F937@patchspace.co.uk> Message-ID: <715C556ECDDD48B1A05B77B4DC1FF407@stardotstar.com> Hey Ash, I like the idea of a wrapper. In fact I use this method for methods that need to shell out Maybe your right, the subdirectory would probably a better safer way of organising the temporary files. I'll have a re-think. Thanks for the info. Rob -- On Thursday, 15 September 2011 at 11:08, Ash Moran wrote: > > On 15 Sep 2011, at 10:05, Rob Aldred wrote: > > > Thanks Justin, > > That isnt working... its erroring with: > > > > The method `delete` was not stubbed or was already unstubbed > > Hi Rob > > For reasons I could go into, when I'm coding myself I don't usually stub out file system access or other third party systems. Rather, I write an adapter that behaves in the way I expect and test it using the real file system, then test the rest of the system against a mock. That avoids this category of problem. > > What you're doing here appears to be mixing both real (from mini_magick) and stubbed (your own library's) calls to filesystem code, and I think it's the asymmetry that's biting you. > > I could explain the above in more detail*, but in lieu of that, here's another angle: can you run the code in a subdirectory per image and nuke that after? That way you only have one point to hit for the cleanup. > > HTH > > Ash > > * As a quick example, you might have a TempFileCleaner object in place of IconGenerator#cleanup, seeded with all the potential temp filenames, or some algorithm to figure them out > > -- > http://www.patchspace.co.uk/ > http://www.linkedin.com/in/ashmoran > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > http://rubyforge.org/mailman/listinfo/rspec-users From jko170 at gmail.com Thu Sep 15 07:35:16 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 15 Sep 2011 07:35:16 -0400 Subject: [rspec-users] Mocking expectations on I/O operations In-Reply-To: <61A553E4678643AD8E8815DDE8DA01F0@stardotstar.com> References: <61A553E4678643AD8E8815DDE8DA01F0@stardotstar.com> Message-ID: On Thu, Sep 15, 2011 at 5:05 AM, Rob Aldred wrote: > Thanks Justin, > That isnt working... its erroring with: > > The method `delete` was not stubbed or was already unstubbed > Woops, you're using expectations, not stubs. Try `File.rspec_reset` > > -- > Rob Aldred > > Software Developer > rob at stardotstar.com > twitter: stardotstar > > 47 Newton Street, Manchester, M1 1FT > T: +44 (0) 161 236 9740 > ___________________________________________________ > > This email and any files or ideas transmitted within it are sent in > confidence and are intended solely for the use of the individual or > entity to whom they are addressed. If you have received this email > in error please notify the system manager at info at stardotstar.com > > On Thursday, 15 September 2011 at 01:52, Justin Ko wrote: > > > > > > > On Wed, Sep 14, 2011 at 6:51 AM, Rob Aldred rob at stardotstar.com)> wrote: > > > I'm speccing a small lib which manipulates image files using > mini_magick. > > > The lib creates various temporary files during the process, the lib > then cleans up the temporary files at the end. > > > > > > I'm trying to mock expectations that the calls are made to File#delete > > > > > > Eg... > > > > File.should_receive(:delete).once.with("#{generator.tmp_path}-full\.png") > > > > File.should_receive(:delete).once.with("#{generator.tmp_path}-screen\.png") > > > > File.should_receive(:delete).once.with("#{generator.tmp_path}-shadow\.png") > > > > > > The method in the lib that does this is: > > > > > > Class IconGenerator > > > ... > > > > > > private > > > > > > def cleanup > > > # remove temporary files created during > > > # image manipulation > > > ['-full','_screen','_shadow','_back_shadow'].each do |f| > > > File.delete "#{tmp_path}#{f}.png" if File.exists? "#{tmp_path}#{f}.png" > > > end > > > end > > > ... > > > end > > > > > > The expectations work fine, however, I also have an after block which > also calls File.delete to clean up the final version of the manipulated test > image > > > > > > after(:each) do > > > # cleanup manipulated image > > > File.delete out_dir.join('MenuIcon.png') if File.exists? > out_dir.join('MenuIcon.png') > > > end > > > > > > The File.delete call in the after block fails because its calling the > mocked version of File.delete > > > This results in the following error: > > > > > > Failure/Error: File.delete out_dir.join('MenuIcon.png') if > File.exists? out_dir.join('MenuIcon.png') > > > NoMethodError: > > > undefined method `=~' for > # > > > > > > > > > My next step was to stub the write method for every instance of > MiniMagick::Image > > > However I will then no longer be able to test the cleanup because the > delete method will never be called if the files don't exist. > > > > > > I'm pretty sure I'm going about this the wrong way and making it > difficult for myself here. > > > Appreciate any help & feedback > > > > > > Thanks > > > -- > > > Rob > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > Give `File.unstub(:delete)` in your `after` block. > > > > Attachments: > > - ATT00001..txt > > > > > > _______________________________________________ > 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 apremdas at gmail.com Thu Sep 15 17:47:39 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Thu, 15 Sep 2011 22:47:39 +0100 Subject: [rspec-users] Mocking expectations on I/O operations In-Reply-To: References: Message-ID: On 14 September 2011 11:51, Rob Aldred wrote: > I'm speccing a small lib which manipulates image files using mini_magick. > The lib creates various temporary files during the process, the lib then cleans up the temporary files at the end. > > I'm trying to mock expectations that the calls are made to File#delete > > Eg... > File.should_receive(:delete).once.with("#{generator.tmp_path}-full\.png") > File.should_receive(:delete).once.with("#{generator.tmp_path}-screen\.png") > File.should_receive(:delete).once.with("#{generator.tmp_path}-shadow\.png") > > The method in the lib that does this is: > > Class IconGenerator > ... > > ?private > > ?def cleanup > ?# remove temporary files created during > ?# image manipulation > ?['-full','_screen','_shadow','_back_shadow'].each do |f| > ?File.delete "#{tmp_path}#{f}.png" if File.exists? "#{tmp_path}#{f}.png" > ?end > ?end > ... > end > > The expectations work fine, however, I also have an after block which also calls File.delete to clean up the final version of the manipulated test image > > after(:each) do > ?# cleanup manipulated image > ?File.delete out_dir.join('MenuIcon.png') if File.exists? out_dir.join('MenuIcon.png') > ?end > > The File.delete call in the after block fails because its calling the mocked version of File.delete > This results in the following error: > > Failure/Error: File.delete out_dir.join('MenuIcon.png') if File.exists? out_dir.join('MenuIcon.png') > NoMethodError: > undefined method `=~' for # > > > My next step was to stub the write method for every instance of MiniMagick::Image > However I will then no longer be able to test the cleanup because the delete method will never be called if the files don't exist. > > I'm pretty sure I'm going about this the wrong way and making it difficult for myself here. > Appreciate any help & feedback > > Thanks > -- > Rob > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hi Rob, First of all perhaps you are testing the wrong thing in the wrong place. As cleanup is a private method, why are you specifying (in this spec how it works). As far as IconGenerator is concerned currently all you care about is that it calls cleanup. You're not interested in how that cleanup is implemented. If you want to specify how the cleanup works then make cleanup public - either in this class, or perhaps better yet in another class. e.g. describe "Cleanup.clean" it "should delete files" end ... end describe IconGenerator ... it should cleanup Cleanup.should_receive(:clean) ... end Once you separate the cleanup spec from the IconGenerator spec then the clash should disappear! You'll never have to mock File.delete HTH Andrew ------------------------ Andrew Premdas blog.andrew.premdas.org From alex at stinky.com Thu Sep 15 20:17:43 2011 From: alex at stinky.com (Alex Chaffee) Date: Thu, 15 Sep 2011 17:17:43 -0700 Subject: [rspec-users] Mocking expectations on I/O operations In-Reply-To: References: Message-ID: https://github.com/defunkt/fakefs might help too -- Alex Chaffee - alex at stinky.com http://alexch.github.com http://twitter.com/alexch From ash.moran at patchspace.co.uk Fri Sep 16 08:23:02 2011 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Fri, 16 Sep 2011 13:23:02 +0100 Subject: [rspec-users] Mocking expectations on I/O operations In-Reply-To: References: Message-ID: <9D1AC909-93AB-40F5-8636-12BF7C1402E6@patchspace.co.uk> On 16 Sep 2011, at 01:17, Alex Chaffee wrote: > https://github.com/defunkt/fakefs might help too I thought that too, but then it occurred to me there's a chance mini_magick isn't using Ruby's filesystem code (it might be writing to the FileSystem with native code for example), so I didn't put this in to confuse the situation. But yes, if it could be done, FakeFS might work well here. -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From chandu.shenoy at gmail.com Mon Sep 19 07:38:28 2011 From: chandu.shenoy at gmail.com (Chandu80) Date: Mon, 19 Sep 2011 04:38:28 -0700 (PDT) Subject: [rspec-users] Rspec error while running jruby -S rake spec In-Reply-To: References: <538e9228-5231-4904-bf80-378fc52f3332@i14g2000prd.googlegroups.com> <0D185D85-209C-4FE9-A0AC-A26E12B14576@gmail.com> <3da004b3-e741-4e4c-a832-db25c8639aef@k29g2000yqf.googlegroups.com> Message-ID: <3209ee16-dd50-4ed1-8dc0-a7f926a48d58@b28g2000yqa.googlegroups.com> Hi, I am using the jdbc adapter because the application I am using is being developed on Jruby on Rails. Regards Chandrika On Sep 15, 2:31?pm, David Chelimsky wrote: > On Sep 15, 2011, at 9:54 AM, Chandu80 wrote: > > > > > > > > > > > On Sep 13, 11:32 am, David Chelimsky wrote: > >> On Sep 12, 2011, at 2:44 PM, Chandu80 wrote: > > >>> Hello All, > > >>> I followed steps to install Rspec as in the link pasted below. > > >>>http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-fac... > > >>> I have jRuby on Rails installed on my machine.Hence all commands need > >>> to be run with jruby -S extension. > >>> However when I run the jruby -S rake spec command,I get the following > >>> error as shown below. > > >>> ************************************************************************************************************************ > >>> C:\Rspec Test>jruby -S rake spec --trace > >>> (in C:/Rspec Test) > >>> ** Invoke spec (first_time) > >>> ** Invoke db:test:prepare (first_time) > >>> ** Invoke db:abort_if_pending_migrations (first_time) > >>> ** Invoke environment (first_time) > >>> ** Execute environment > >>> db pool warmup starting...................... Mon Sep 12 18:05:23 > >>> +0530 2011 > > >>> warmed > >>> up...........===========================================.............. > > >>> db pool warmup done........................... Mon Sep 12 18:05:23 > >>> +0530 2011 > > >>> ** Execute db:abort_if_pending_migrations > >>> ** Execute db:test:prepare > >>> ** Invoke db:test:load (first_time) > >>> ** Invoke db:test:purge (first_time) > >>> ** Invoke environment > >>> ** Execute db:test:purge > >>> RspecTest already exists > >>> ** Execute db:test:load > >>> ** Invoke db:schema:load (first_time) > >>> ** Invoke environment > >>> ** Execute db:schema:load > > >> When you run a spec suite, RSpec delegates to Rails to do the same work it does before and after a test suite. One task it runs is db:schema:load, which is defined in Rails. It asks the configured database for a list of tables and then tries to drop and recreate them. This ensures that any data from a previous run is removed, and the schema for the test db matches that of the development db. > > >>> rake aborted! > >>> ActiveRecord::ActiveRecordError: ERROR: cannot drop table channels > >>> because other > >>> objects depend on it > >>> ?Detail: constraint messages_channel_id_fk on table messages depends > >>> on table c > >>> hannels > >>> constraint invitation_workflow_mapping_invitor on table > >>> invitation_workflows dep > >>> ends on table channels > >>> constraint invitation_workflow_mapping_invited_whom_id on table > >>> invitation_workf > >>> lows depends on table channels > >>> constraint invitation_workflow_mapping_invited_for_channel_id on table > >>> invitatio > >>> n_workflows depends on table channels > >>> ?Hint: Use DROP ... CASCADE to drop the dependent objects too.: DROP > >>> TABLE "cha > >>> nnels" > > >> > > >>> What does the error indicate,I tried commenting all lines having > >>> drop_database statement in them. > >>> Another thing is that the database already has tables and by using the > >>> tutorial I have just added another table for the bank-account. > >>> Kindly let me know what exactly needs to be done in this case > > >> The message tells you the underlying problem: there are database constraints that are not allowing the tables to be deleted in the order in which the rake task is trying to delete them. For whatever reason, the active record adapter you are using is not invoking a cascading delete. What adapter are you using? What database? Also, what other db-related gems do you have in the app? Just type `jruby -S bundle show`. > > So does that mean that I need to manually delete all other tables for > > the rake command to run successfully? > > That needs to happen but the activerecord adapter you are using should handle it implicitly for you. Which one are you using? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jperkins at me.com Mon Sep 19 18:50:24 2011 From: jperkins at me.com (Jason Perkins) Date: Mon, 19 Sep 2011 18:50:24 -0400 Subject: [rspec-users] running rspec alongside test::unit? Message-ID: <1DDC94D7-9464-4A7E-A84F-9243E8FED645@me.com> Earlier documentation indicated that it was possible to run RSpec alongside existing test::unit tests. Is this still possible? -- Jason Perkins From matt at mattwynne.net Tue Sep 20 07:55:13 2011 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 20 Sep 2011 12:55:13 +0100 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: References: Message-ID: <0A421E76-01E3-4831-9DD5-090AF1E285D0@mattwynne.net> Thanks for all the ideas. I just rolled my own which expects a block with an assertion in it: https://gist.github.com/1228927 Could we put this into RSpec somewhere? I'd rather not dump the source into The Cucumber Book - it's too low level. I could put it into it's own little gem but that seems like creating clutter in the gemsphere. WDYT? On 13 Sep 2011, at 17:41, Alex Chaffee wrote: > Sure. "wait_for" is a method Brian Takita and I originally wrote for > use in Selenium tests, then IIRC it made it into the Selenium gem and > now lots of libraries use it (or their own version -- I make no patent > claim on polling :-)). The wait_for I remember allowed you to > customize the failure message. Let me go see if it's on GitHub or > anything... > > Ah, here's one: > https://github.com/pivotal/selenium/blob/master/lib/selenium/wait_for.rb > > (Maybe I should put it in Wrong.) > > - A > > On Tue, Sep 13, 2011 at 3:56 AM, Matt Wynne wrote: >> Hi all, >> In GOOS[1] they use an assertion called assertEventually which samples the >> system for a success state until a certain timeout has elapsed. This allows >> you to synchronise the tests with asynchronous code. >> Do we have an equivalent of that in the Ruby / RSpec world already? I know >> capybara has wait_until { } but that's fairly rudimentary - the failure >> message isn't very helpful. Is there anything else already out there? >> [1] http://www.growing-object-oriented-software.com/ >> cheers, >> Matt >> -- >> Freelance programmer & coach >> Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak >> Helles?y) >> Founder, http://relishapp.com >> +44(0)7974430184 | http://twitter.com/mattwynne >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Alex Chaffee - alex at stinky.com > http://alexch.github.com > http://twitter.com/alexch > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Tue Sep 20 17:45:17 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 20 Sep 2011 14:45:17 -0700 (PDT) Subject: [rspec-users] using rspec to verify an xpath (via capybara/cucumber) Message-ID: I am doing: page.should have_xpath("//img[contains(@class, 'foobar')]", :count => 0) but cucumber tells me: expected xpath "//img[contains(@class, 'foobar')]" to return something (RSpec::Expectations::ExpectationNotMetError) ... Shouldn't this be returning true/false ? Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Tue Sep 20 17:57:24 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Sep 2011 23:57:24 +0200 Subject: [rspec-users] using rspec to verify an xpath (via capybara/cucumber) In-Reply-To: References: Message-ID: <6569BF37-7067-4A17-BB80-BE67DCB9218E@gmail.com> On Sep 20, 2011, at 11:45 PM, Patrick J. Collins wrote: > I am doing: > > page.should have_xpath("//img[contains(@class, 'foobar')]", :count => 0) > > but cucumber tells me: > > expected xpath "//img[contains(@class, 'foobar')]" to return something > (RSpec::Expectations::ExpectationNotMetError) > > > ... Shouldn't this be returning true/false ? have_xpath is a Capybara matcher that defines its own failure message: https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec/matchers.rb#L112-114 HTH, David From jko170 at gmail.com Tue Sep 20 18:01:34 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 20 Sep 2011 16:01:34 -0600 Subject: [rspec-users] using rspec to verify an xpath (via capybara/cucumber) In-Reply-To: References: Message-ID: <27CE0A1D-91CF-4AA1-AF5B-120309171F94@gmail.com> "have_[xpath]" is a custom matcher in Capybara. So, the answer would be no. https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec/matchers.rb On Sep 20, 2011, at 3:45 PM, Patrick J. Collins wrote: > I am doing: > > page.should have_xpath("//img[contains(@class, 'foobar')]", :count => 0) > > but cucumber tells me: > > expected xpath "//img[contains(@class, 'foobar')]" to return something > (RSpec::Expectations::ExpectationNotMetError) > > > ... Shouldn't this be returning true/false ? > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From alex at stinky.com Tue Sep 20 18:38:48 2011 From: alex at stinky.com (Alex Chaffee) Date: Tue, 20 Sep 2011 15:38:48 -0700 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: <0A421E76-01E3-4831-9DD5-090AF1E285D0@mattwynne.net> References: <0A421E76-01E3-4831-9DD5-090AF1E285D0@mattwynne.net> Message-ID: On Tue, Sep 20, 2011 at 4:55 AM, Matt Wynne wrote: > Thanks for all the ideas. I just rolled my own which expects a block with an > assertion in it: I love the language! eventually { white.should be_black } > Could we put this into RSpec somewhere? It's not actually RSpec-specific. I'll put it (or probably a hybrid between your new code and my old code) into Wrong and you can use it via the wrong rspec adapter. def two rand(3) end require "rspec" require "wrong/adapters/rspec" describe "two" do it "should eventually be half of four" do eventually { (two + two).should == 4 } end end should work soonish... -- Alex Chaffee - alex at stinky.com http://alexchaffee.com http://twitter.com/alexch From matt at mattwynne.net Wed Sep 21 06:42:49 2011 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 21 Sep 2011 11:42:49 +0100 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: References: <0A421E76-01E3-4831-9DD5-090AF1E285D0@mattwynne.net> Message-ID: On 20 Sep 2011, at 23:38, Alex Chaffee wrote: > On Tue, Sep 20, 2011 at 4:55 AM, Matt Wynne wrote: >> Thanks for all the ideas. I just rolled my own which expects a block with an >> assertion in it: > > I love the language! > > eventually { white.should be_black } > >> Could we put this into RSpec somewhere? > > It's not actually RSpec-specific. I'll put it (or probably a hybrid > between your new code and my old code) into Wrong and you can use it > via the wrong rspec adapter. Thanks! I know it's not RSpec specific. I suppose my motivation is I want to keep the number of tools / gems we have to mention in the book to a minimum. Since we're already using RSpec in the book already it made sense to me if it became part of the RSpec assertion toolkit. I'd have thought it would be useful to other RSpec users too. I've never used Wrong, only read about it--and I like the idea very much, I must say. Is there any danger of adverse effects (other than an extra line the Gemfile) if we have to use the Wrong RSpec adapter in the book alongside the existing vanilla RSpec assertions? > > def two > rand(3) > end > > require "rspec" > require "wrong/adapters/rspec" > describe "two" do > it "should eventually be half of four" do > eventually { (two + two).should == 4 } > end > end > > should work soonish... > > -- > Alex Chaffee - alex at stinky.com > http://alexchaffee.com > http://twitter.com/alexch cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne From alex at stinky.com Wed Sep 21 12:46:36 2011 From: alex at stinky.com (Alex Chaffee) Date: Wed, 21 Sep 2011 09:46:36 -0700 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: References: <0A421E76-01E3-4831-9DD5-090AF1E285D0@mattwynne.net> Message-ID: On Wed, Sep 21, 2011 at 3:42 AM, Matt Wynne wrote: > I've never used Wrong, only read about it--and I like the idea very much, I must say. Is there any danger of adverse effects (other than an extra line the Gemfile) if we have to use the Wrong RSpec adapter in the book alongside the existing vanilla RSpec assertions? > There shouldn't be, but I'd love for more people to verify that. The adapter source is at https://github.com/sconover/wrong/blob/master/lib/wrong/adapters/rspec.rb (It doesn't actually do much, just includes Wrong inside RSpec's ExampleGroup. The bulk of that code is in case anyone uses the Wrong feature "alias_assert" which allows users to define their own DSLy name for assert. I like "expect" but RSpec already has its own "expect"; David kindly provided a way to cleanly remove RSpec's "expect" before defining my own, but I couldn't quite get it to work so I'm still using the brute force way which just chops it out using Ruby's "Module#remove_method" method. In any case, none of that is relevant unless users go out of their way and call "Wrong.config.alias_assert :expect, :override=>true" which most won't do.) There's a semantic issue in your eventually method that I'd like to discuss. My wait_for[1] and friends take a *predicate* (in the form of a block) and wait for it to return true(ish). Your eventually[2] ignores the return condition, and merely waits for it to not raise an error. I think using a predicate is more useful, and strictly no less powerful since the waiter code will *also* wait for it to not raise an error, so you could do *either* this eventually { rand(10) == 0 } or this eventually { rand(10).should == 0 } and if, after 2 sec or whatever, it keeps either being false or raising an ExpectationNotMetError, then the waiter will itself raise an ExpectationNotMetError. IOW, should the following pass or should it fail? eventually { false == true } - A P.S. (Lurkers please feel free to chime in too. :-) [1] https://github.com/pivotal/selenium/blob/master/lib/selenium/wait_for.rb [2] https://gist.github.com/1228927 -- Alex Chaffee - alex at stinky.com http://alexchaffee.com http://twitter.com/alexch From matt at mattwynne.net Wed Sep 21 16:01:23 2011 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 21 Sep 2011 21:01:23 +0100 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: References: <0A421E76-01E3-4831-9DD5-090AF1E285D0@mattwynne.net> Message-ID: <7F7DF0A0-FF61-4CCB-B17B-70BF095CC7B2@mattwynne.net> On 21 Sep 2011, at 17:46, Alex Chaffee wrote: > There's a semantic issue in your eventually method that I'd like to > discuss. My wait_for[1] and friends take a *predicate* (in the form of > a block) and wait for it to return true(ish). Your eventually[2] > ignores the return condition, and merely waits for it to not raise an > error. I think using a predicate is more useful, and strictly no less > powerful since the waiter code will *also* wait for it to not raise an > error, so you could do *either* this > > eventually { rand(10) == 0 } > > or this > > eventually { rand(10).should == 0 } > > and if, after 2 sec or whatever, it keeps either being false or > raising an ExpectationNotMetError, then the waiter will itself raise > an ExpectationNotMetError. > > IOW, should the following pass or should it fail? > > eventually { false == true } To be honest, I just ignored the true / false version in my implementation because I want a helpful error message when the test fails, rather than a crude TimeoutError or whatever. I'm ambivalent about this: I would worry that allowing falsiness to cause an assertion to be raised is not idiomatic RSpec, but perhaps it is idiomatic Wrong, since you can do all that magic to infer an error message anyway, right? I think as long as I can use my own assertions too I don't have any objections to it doing both. > P.S. (Lurkers please feel free to chime in too. :-) > > [1] https://github.com/pivotal/selenium/blob/master/lib/selenium/wait_for.rb > [2] https://gist.github.com/1228927 cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne From alex at stinky.com Wed Sep 21 20:51:42 2011 From: alex at stinky.com (Alex Chaffee) Date: Wed, 21 Sep 2011 17:51:42 -0700 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: <7F7DF0A0-FF61-4CCB-B17B-70BF095CC7B2@mattwynne.net> References: <0A421E76-01E3-4831-9DD5-090AF1E285D0@mattwynne.net> <7F7DF0A0-FF61-4CCB-B17B-70BF095CC7B2@mattwynne.net> Message-ID: On Wed, Sep 21, 2011 at 1:01 PM, Matt Wynne wrote: > I want a helpful error message when the test fails, rather than a crude TimeoutError or whatever. I hear you. > I'm ambivalent about this: I would worry that allowing falsiness to cause an assertion to be raised is not idiomatic RSpec, but perhaps it is idiomatic Wrong, since you can do all that magic to infer an error message anyway, right? I hope so... I mean, uh, yes! Definitely! :-) -- Alex Chaffee - alex at stinky.com http://alexchaffee.com http://twitter.com/alexch From patrick at collinatorstudios.com Wed Sep 21 22:35:06 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 21 Sep 2011 19:35:06 -0700 (PDT) Subject: [rspec-users] preferred place for methods used by both rspec and cucumber? Message-ID: Hi, I have some helper methods such as: def mock_omniauth OmniAuth.config.test_mode = true OmniAuth.config.mock_auth[:facebook] = facebook_user end def facebook_user @facebook_user ||= HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/test/fixtures/fb_user.yml"))) end that I want to use in both cucumber step definitions and rspec. Is there a preferred place to store this code, or is it standard practice to just define them in a module in config/inititalizers and include that in both cucumber's env.rb and rspec's spec_helper.rb? Thanks. Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Thu Sep 22 01:29:41 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 22 Sep 2011 07:29:41 +0200 Subject: [rspec-users] preferred place for methods used by both rspec and cucumber? In-Reply-To: References: Message-ID: On Sep 22, 2011, at 4:35 AM, Patrick J. Collins wrote: > Hi, > > I have some helper methods such as: > > def mock_omniauth > OmniAuth.config.test_mode = true > OmniAuth.config.mock_auth[:facebook] = facebook_user > end > > def facebook_user > @facebook_user ||= HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/test/fixtures/fb_user.yml"))) > end > > that I want to use in both cucumber step definitions and rspec. Is there a > preferred place to store this code, This doesn't come up that often so there is no established convention. I've put such code in files in spec/support and included it from the features directory before. I'm sure the other way round would work just fine. > or is it standard practice to just define > them in a module in config/inititalizers and include that in both cucumber's > env.rb and rspec's spec_helper.rb? config/initializers is about application initialization IMO, so I wouldn't put this material there. Anybody else? David From chandu.shenoy at gmail.com Thu Sep 22 08:35:34 2011 From: chandu.shenoy at gmail.com (Chandu80) Date: Thu, 22 Sep 2011 05:35:34 -0700 (PDT) Subject: [rspec-users] uninitialized constant Spec::Rails (NameError) when running spec command Message-ID: <321df365-37ef-46b4-8960-de996e27f93e@a7g2000yqb.googlegroups.com> I get the following error when trying to run a spec command on a model test. The command is :- C:\Rspec Test\spec\models>spec bank_account_spec.rb The error is :- c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/rails/ matchers/ ar_be_valid.rb:2: uninitialized constant Spec::Rails (NameError) from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec- rails-1.3.0/lib/spec/ra ils/matchers/ar_be_valid.rb:31:in require' from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31 :inrequire' from C:/Rspec Test/vendor/rails/activesupport/lib/ active_support/depende ncies.rb:158:in require' from c:/jruby-1.5.0/ lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra ils/matchers.rb:2 from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ ra ils/matchers.rb:31:inrequire' from c:/jruby-1.5.0/lib/ruby/ site_ruby/1.8/rubygems/custom_require.rb:31 :in require' from C:/Rspec Test/vendor/rails/activesupport/lib/active_support/depende ncies.rb: 158:inrequire' from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec- rails-1.3.0/lib/spec/ra ils.rb:15 ... 13 levels... from C:/jruby-1.5.0/ lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:5 from C:/jruby-1.5.0/lib/ ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:22:in `l oad' from c:/ jruby-1.5.0/bin/spec:22 I actually tried changing version to 1.3.0 in the C:\jruby-1.5.0\bin \spec file but it results in the same error. Please advice. Regards Chandrika From phillipkoebbe at gmail.com Thu Sep 22 09:30:06 2011 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 22 Sep 2011 08:30:06 -0500 Subject: [rspec-users] preferred place for methods used by both rspec and cucumber? In-Reply-To: References: Message-ID: <4E7B385E.7090603@gmail.com> On 2011-09-21 9:35 PM, Patrick J. Collins wrote: > Hi, > > I have some helper methods such as: > > def mock_omniauth > OmniAuth.config.test_mode = true > OmniAuth.config.mock_auth[:facebook] = facebook_user > end > > def facebook_user > @facebook_user ||= HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/test/fixtures/fb_user.yml"))) > end > > that I want to use in both cucumber step definitions and rspec. Is there a > preferred place to store this code, or is it standard practice to just define > them in a module in config/inititalizers and include that in both cucumber's > env.rb and rspec's spec_helper.rb? > > Thanks. > > Patrick J. Collins > http://collinatorstudios.com I agree with David that config/initializers isn't the right place as that would load test-related code into your application in production. I create a folder in Rails.root for shared code and then require it as necessary in RSpec and Cucumber. My current directory name is test_support, which I'm not terribly fond of, but doesn't really matter so I haven't wasted the brain energy to rename it. The benefit of keeping shared code in a folder external to both tools is I can totally remove one tool without the other breaking. If you keep the shared code inside one or the other, you have to be careful about changing whichever one hosts the shared code. Peace. From dchelimsky at gmail.com Thu Sep 22 18:32:29 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 23 Sep 2011 00:32:29 +0200 Subject: [rspec-users] uninitialized constant Spec::Rails (NameError) when running spec command In-Reply-To: <321df365-37ef-46b4-8960-de996e27f93e@a7g2000yqb.googlegroups.com> References: <321df365-37ef-46b4-8960-de996e27f93e@a7g2000yqb.googlegroups.com> Message-ID: <2CA95345-304F-4D1D-BE5E-BBE6A2CAF713@gmail.com> On Sep 22, 2011, at 2:35 PM, Chandu80 wrote: > I get the following error when trying to run a spec command on a model > test. > > The command is :- C:\Rspec Test\spec\models>spec bank_account_spec.rb The rspec command is designed to be run from the project root. Try: C:\Rspec Test>spec spec\models\spec bank_account_spec.rb From chandu.shenoy at gmail.com Fri Sep 23 01:41:23 2011 From: chandu.shenoy at gmail.com (Chandu80) Date: Thu, 22 Sep 2011 22:41:23 -0700 (PDT) Subject: [rspec-users] uninitialized constant Spec::Rails (NameError) when running spec command In-Reply-To: <2CA95345-304F-4D1D-BE5E-BBE6A2CAF713@gmail.com> References: <321df365-37ef-46b4-8960-de996e27f93e@a7g2000yqb.googlegroups.com> <2CA95345-304F-4D1D-BE5E-BBE6A2CAF713@gmail.com> Message-ID: Hi David, Tried from the root directory,gives the same error. C:/Rspec Test 1/rspec_demo/vendor/rails/activesupport/lib/ active_support/depende ncies.rb:443:in `load_missing_constant': uninitialized constant Spec::Rails (Nam eError) from C:/Rspec Test 1/rspec_demo/vendor/rails/activesupport/lib/ active_su pport/dependencies.rb:80:in `const_missing_with_dependencies' from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/ lib/spec/ra ils/matchers/ar_be_valid.rb:2 from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/ lib/spec/ra ils/matchers/ar_be_valid.rb:31:in `require' from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:31 :in `require' from C:/Rspec Test 1/rspec_demo/vendor/rails/activesupport/lib/ active_su pport/dependencies.rb:158:in `require' from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/ lib/spec/ra ils/matchers.rb:2 from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/ lib/spec/ra ils/matchers.rb:31:in `require' from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:31 :in `require' ... 15 levels... from C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/ spec:5 from C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/ spec:21:in `l oad' from c:/jruby-1.5.0/bin/spec:21 Regards Chandrika On Sep 23, 3:32?am, David Chelimsky wrote: > On Sep 22, 2011, at 2:35 PM, Chandu80 wrote: > > > I get the following error when trying to run a spec command on a model > > test. > > > The command is :- C:\Rspec Test\spec\models>spec bank_account_spec.rb > > The rspec command is designed to be run from the project root. Try: > > C:\Rspec Test>spec spec\models\spec bank_account_spec.rb > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From patmaddox at me.com Fri Sep 23 12:42:59 2011 From: patmaddox at me.com (Pat Maddox) Date: Fri, 23 Sep 2011 09:42:59 -0700 Subject: [rspec-users] preferred place for methods used by both rspec and cucumber? In-Reply-To: References: Message-ID: <242FB2C0-97B2-4C8D-B35B-0DB3DA787FB9@me.com> I use spec/support or Rails.root/bdd_support not a big deal really. just pick a place and require em On Sep 21, 2011, at 7:35 PM, Patrick J. Collins wrote: > Hi, > > I have some helper methods such as: > > def mock_omniauth > OmniAuth.config.test_mode = true > OmniAuth.config.mock_auth[:facebook] = facebook_user > end > > def facebook_user > @facebook_user ||= HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/test/fixtures/fb_user.yml"))) > end > > that I want to use in both cucumber step definitions and rspec. Is there a > preferred place to store this code, or is it standard practice to just define > them in a module in config/inititalizers and include that in both cucumber's > env.rb and rspec's spec_helper.rb? > > Thanks. > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From silumesii at pencilcasestudios.com Thu Sep 15 05:08:10 2011 From: silumesii at pencilcasestudios.com (Silumesii Maboshe) Date: Thu, 15 Sep 2011 02:08:10 -0700 (PDT) Subject: [rspec-users] Access to asset_path helper in a Rails 3.1 application request spec Message-ID: <9933335.535.1316077690559.JavaMail.geo-discussion-forums@yqnh42> Hello! I am learning to use RSpec for testing Rails 3.1 applications - really enjoying using it so far. In testing for the presence of assets (e.g rails.png), I've been using: get "/assets/rails.png" response.status.should be(200) After some reading about the Rails 3.1 asset pipeline I discovered the "asset_path" helper. Is it possible to access this helper in a request spec? I have not had any success so far: get asset_path, "rails.png" response.status.should be(200) Gives: undefined local variable or method 'asset_path'. Any help with this would be appreciated. Best, Silumesii -------------- next part -------------- An HTML attachment was scrubbed... URL: From joahking at gmail.com Fri Sep 16 06:40:28 2011 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Fri, 16 Sep 2011 12:40:28 +0200 Subject: [rspec-users] shared examples in test unit? Message-ID: hi, at work we use TestUnit, and I miss there a lot the shared_examples from RSpec, do you know if is there something alike for TestUnit? I know this might be a bit OT but I thought you probably might know :-) tia, joaquin -- para.pent.es vamos a volar, let's go flying least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mafordha at gmail.com Fri Sep 16 14:33:18 2011 From: mafordha at gmail.com (mattf) Date: Fri, 16 Sep 2011 11:33:18 -0700 (PDT) Subject: [rspec-users] How to stub ApplicationController method in request spec Message-ID: <901ee258-2989-467e-b941-05b1b5b5a9d8@i2g2000yqm.googlegroups.com> Hey there, I am needing to stub a 'current_user' method in an Rspec/capybara request spec. The method is defined in ApplicationController and is using helper_method. The method should simply return a user id. Alternatively, I could fix my problem by setting 'session[:user_id]' in the spec (which is what 'current_user' returns)... but that doesn't seem to work either. Are either of these possible? Thanks!!! From jack at healthtalker.com Fri Sep 23 09:09:12 2011 From: jack at healthtalker.com (Jack Desert) Date: Fri, 23 Sep 2011 13:09:12 +0000 Subject: [rspec-users] Redirecting from rspec.info to relishapp.com/rspec Message-ID: <3D2486FB-7340-40C9-9C67-C2D84F10300A@healthtalker.com> I'm interested in writing a redirect app from rspec.info (rspec 1.0) to relishapp.com/rspec (rspec 2). Can someone tell me who I would contact to get the information I need (what old links need to redirect to where, etc?) -Jack Rails/PHP Developer Healthtalker.com From dchelimsky at gmail.com Sun Sep 25 02:59:03 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 25 Sep 2011 08:59:03 +0200 Subject: [rspec-users] Redirecting from rspec.info to relishapp.com/rspec In-Reply-To: <3D2486FB-7340-40C9-9C67-C2D84F10300A@healthtalker.com> References: <3D2486FB-7340-40C9-9C67-C2D84F10300A@healthtalker.com> Message-ID: <2188D830-DF05-4C6A-AC2B-C7F5F2EC6235@gmail.com> On Sep 23, 2011, at 3:09 PM, Jack Desert wrote: > I'm interested in writing a redirect app from rspec.info (rspec 1.0) to relishapp.com/rspec (rspec 2). Can someone tell me who I would contact to get the information I need (what old links need to redirect to where, etc?) Thanks Jack. A couple of others have offered to do the same and I'll be coordinating the effort shortly. Just returning from a couple of weeks vacation, so lots of catching up to do. I'll be in touch within the next week. Cheers, David > -Jack > Rails/PHP Developer > Healthtalker.com From jko170 at gmail.com Sun Sep 25 03:02:01 2011 From: jko170 at gmail.com (Justin Ko) Date: Sun, 25 Sep 2011 01:02:01 -0600 Subject: [rspec-users] How to stub ApplicationController method in request spec In-Reply-To: <901ee258-2989-467e-b941-05b1b5b5a9d8@i2g2000yqm.googlegroups.com> References: <901ee258-2989-467e-b941-05b1b5b5a9d8@i2g2000yqm.googlegroups.com> Message-ID: <00BA3E49-200B-4148-9B12-E12ED8723D24@gmail.com> On Sep 16, 2011, at 12:33 PM, mattf wrote: > Hey there, > > I am needing to stub a 'current_user' method in an Rspec/capybara > request spec. The method is defined in ApplicationController and is > using helper_method. The method should simply return a user id. > > Alternatively, I could fix my problem by setting 'session[:user_id]' > in the spec (which is what 'current_user' returns)... but that doesn't > seem to work either. > > Are either of these possible? Thanks!!! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Capybara was designed to force the dev to build true request specs. Meaning, you cannot tamper with cookies, request headers, etc. directly. You have to go through the app - clicking links, visiting paths, etc. So, you're going to have to go to the authentication page and login before hitting the pages you actually want to test. From jko170 at gmail.com Sun Sep 25 02:54:09 2011 From: jko170 at gmail.com (Justin Ko) Date: Sun, 25 Sep 2011 00:54:09 -0600 Subject: [rspec-users] shared examples in test unit? In-Reply-To: References: Message-ID: On Sep 16, 2011, at 4:40 AM, Joaquin Rivera Padron wrote: > hi, > at work we use TestUnit, and I miss there a lot the shared_examples from RSpec, do you know if is there something alike for TestUnit? > > I know this might be a bit OT but I thought you probably might know :-) > > tia, > joaquin > > -- > para.pent.es vamos a volar, let's go flying > least-significant-bit.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users T/U tests are just Ruby classes, so you can do things like "include UserAssertions". -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Sun Sep 25 03:35:10 2011 From: jko170 at gmail.com (Justin Ko) Date: Sun, 25 Sep 2011 01:35:10 -0600 Subject: [rspec-users] Access to asset_path helper in a Rails 3.1 application request spec In-Reply-To: <9933335.535.1316077690559.JavaMail.geo-discussion-forums@yqnh42> References: <9933335.535.1316077690559.JavaMail.geo-discussion-forums@yqnh42> Message-ID: On Sep 15, 2011, at 3:08 AM, Silumesii Maboshe wrote: > Hello! > > I am learning to use RSpec for testing Rails 3.1 applications - really enjoying using it so far. > In testing for the presence of assets (e.g rails.png), I've been using: > > get "/assets/rails.png" > response.status.should be(200) > > After some reading about the Rails 3.1 asset pipeline I discovered the "asset_path" helper. Is it possible to access this helper in a request spec? I have not had any success so far: > > get asset_path, "rails.png" > response.status.should be(200) > > Gives: > > undefined local variable or method 'asset_path'. > > Any help with this would be appreciated. > > Best, > > Silumesii > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users "asset_path" isn't a routing URL helper, it's a Sprocket helper. Try this: # in spec_helper.rb config.include Sprockets::Helpers::RailsHelper, :type => :request From patrick at collinatorstudios.com Mon Sep 26 17:11:28 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 26 Sep 2011 14:11:28 -0700 (PDT) Subject: [rspec-users] how to test identical behavior without being redundant? Message-ID: I've got many models that have this declared: has_many :notifications, :as => :notifiable, :dependent => :destroy ... And so I have many model specs such as: describe Reply do it "should eliminate any associated notification records when destroyed" do reply = create_reply reply.notifications.should_not be_blank reply.destroy reply.notifications.reload.should be_blank end end describe Post do it "should eliminate any associated notification records when destroyed" do post = create_post post.notifications.should_not be_blank post.destroy post.notifications.reload.should be_blank end end etc... Is there an ideal way to dynamically generate this for any models that respond to notificaions so that I don't have redundant noisy tests? Thanks. Patrick J. Collins http://collinatorstudios.com From patmaddox at me.com Mon Sep 26 17:39:03 2011 From: patmaddox at me.com (Pat Maddox) Date: Mon, 26 Sep 2011 14:39:03 -0700 Subject: [rspec-users] how to test identical behavior without being redundant? In-Reply-To: References: Message-ID: <3804FA3F-EE2E-4BF6-A19B-11E441E673E5@me.com> https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples On Sep 26, 2011, at 2:11 PM, Patrick J. Collins wrote: > I've got many models that have this declared: > has_many :notifications, :as => :notifiable, :dependent => :destroy > > > ... And so I have many model specs such as: > > describe Reply do > > it "should eliminate any associated notification records when destroyed" do > reply = create_reply > reply.notifications.should_not be_blank > > reply.destroy > reply.notifications.reload.should be_blank > end > > end > > describe Post do > > it "should eliminate any associated notification records when destroyed" do > post = create_post > post.notifications.should_not be_blank > > post.destroy > post.notifications.reload.should be_blank > end > > end > > etc... > > Is there an ideal way to dynamically generate this for any models that respond > to notificaions so that I don't have redundant noisy tests? > > > Thanks. > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From marko at renderedtext.com Tue Sep 27 04:51:00 2011 From: marko at renderedtext.com (Marko Anastasov) Date: Tue, 27 Sep 2011 10:51:00 +0200 Subject: [rspec-users] running rspec alongside test::unit? In-Reply-To: <1DDC94D7-9464-4A7E-A84F-9243E8FED645@me.com> References: <1DDC94D7-9464-4A7E-A84F-9243E8FED645@me.com> Message-ID: On Tue, Sep 20, 2011 at 00:50, Jason Perkins wrote: > Earlier documentation indicated that it was possible to run RSpec alongside existing test::unit tests. Is this still possible? > It's possible, I'm involved in one project that has been using test::unit in the past and has still not completely transitioned to RSpec (but RSpec is the default for new code). Basically you just run "rake test" then "rake spec". From chandu.shenoy at gmail.com Tue Sep 27 07:04:04 2011 From: chandu.shenoy at gmail.com (Chandu80) Date: Tue, 27 Sep 2011 04:04:04 -0700 (PDT) Subject: [rspec-users] uninitialized constant Spec::Rails (NameError) when running spec command In-Reply-To: References: <321df365-37ef-46b4-8960-de996e27f93e@a7g2000yqb.googlegroups.com> <2CA95345-304F-4D1D-BE5E-BBE6A2CAF713@gmail.com> Message-ID: Hello All, Is there any way to fix the error? Regards Chandrika On Sep 23, 10:41?am, Chandu80 wrote: > Hi David, > Tried from the root directory,gives the same error. > > C:/Rspec Test 1/rspec_demo/vendor/rails/activesupport/lib/ > active_support/depende > ncies.rb:443:in `load_missing_constant': uninitialized constant > Spec::Rails (Nam > eError) > ? ? ? ? from C:/Rspec Test 1/rspec_demo/vendor/rails/activesupport/lib/ > active_su > pport/dependencies.rb:80:in `const_missing_with_dependencies' > ? ? ? ? from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/ > lib/spec/ra > ils/matchers/ar_be_valid.rb:2 > ? ? ? ? from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/ > lib/spec/ra > ils/matchers/ar_be_valid.rb:31:in `require' > ? ? ? ? from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/ > custom_require.rb:31 > :in `require' > ? ? ? ? from C:/Rspec Test 1/rspec_demo/vendor/rails/activesupport/lib/ > active_su > pport/dependencies.rb:158:in `require' > ? ? ? ? from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/ > lib/spec/ra > ils/matchers.rb:2 > ? ? ? ? from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/ > lib/spec/ra > ils/matchers.rb:31:in `require' > ? ? ? ? from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/ > custom_require.rb:31 > :in `require' > ? ? ? ? ?... 15 levels... > ? ? ? ? from C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/ > spec:5 > ? ? ? ? from C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/ > spec:21:in `l > oad' > ? ? ? ? from c:/jruby-1.5.0/bin/spec:21 > > Regards > Chandrika > > On Sep 23, 3:32?am, David Chelimsky wrote:> On Sep 22, 2011, at 2:35 PM, Chandu80 wrote: > > > > I get the following error when trying to run a spec command on a model > > > test. > > > > The command is :- C:\Rspec Test\spec\models>spec bank_account_spec.rb > > > The rspec command is designed to be run from the project root. Try: > > > C:\Rspec Test>spec spec\models\spec bank_account_spec.rb > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From alex at stinky.com Tue Sep 27 20:09:42 2011 From: alex at stinky.com (Alex Chaffee) Date: Tue, 27 Sep 2011 17:09:42 -0700 Subject: [rspec-users] Assertions for asynchronous behaviour In-Reply-To: References: <0A421E76-01E3-4831-9DD5-090AF1E285D0@mattwynne.net> <7F7DF0A0-FF61-4CCB-B17B-70BF095CC7B2@mattwynne.net> Message-ID: After a week of stealing minutes, I eventually wrote eventually! Please check this out and give me feedback. I can ship it in a new Wrong gem as soon as you all tell me it's ready. docs: https://github.com/alexch/wrong/commit/cae852f09a3d4dcb3f014b486a10d5eb7a10e7f5 test (spec): https://github.com/alexch/wrong/blob/master/test/eventually_test.rb code: https://github.com/alexch/wrong/blob/master/lib/wrong/eventually.rb The only major feature I haven't done is editing the error message from inside the block, since Wrong seems to do a good job of this on its own. If the block contains a "should" or a Wrong "assert" then it ends up looking like it just got called and failed the final time. It'd be nice if I could sneak into an exception and append "(after 5 sec)" to e.message but I don't know if I want to go there... -- Alex Chaffee - alex at stinky.com http://alexchaffee.com http://twitter.com/alexch From jeffnyman at gmail.com Wed Sep 28 08:30:26 2011 From: jeffnyman at gmail.com (Jeff Nyman) Date: Wed, 28 Sep 2011 05:30:26 -0700 (PDT) Subject: [rspec-users] Custom Formatter: Getting Text from It Method Message-ID: <6ba93974-a471-476f-8943-ad7849b219fe@db5g2000vbb.googlegroups.com> Hey all. I've been playing around with RSpec custom formatters to see how much flexibility there is. One thing I've been trying to see is if I can print the contents of a variable that's in an example (it) method. So, for example, here's what I have in my specification: it "should display results range" do search_for("star wars") @browser.text.should match(/Showing .* of .* Results/) intent = "Text 'Showing .* of .* Results' shows after 'Star Wars' search" end Notice the line with intent there? I realize this is not what most people would do with RSpec. The reason I'm doing this is because I'd like viewers of the test results to see the exact condition that was tested for in the should if they want to -- without having to read the code. Again, I'm just experimenting. What I'm trying to do is figure out how I could use a custom formatter to print out that intent text. I know that the example_passed method in the formatters contains elements like example.description that prints out the text of the it method. But trying @output.puts example.intent does not seem to work. Is there a better way to do what I'm trying to do here? Again, I realize that most people are happy with the describe and it text being printed out. But sometimes people -- like my business users -- want to check the actual condition that was checked for, without having to read Ruby code. Any pointers or tips would be greatly appreciated. - Jeff From patrick at collinatorstudios.com Fri Sep 30 15:48:23 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 30 Sep 2011 12:48:23 -0700 (PDT) Subject: [rspec-users] let vs ivar w/ before block Message-ID: Am I correct in understanding that the point of using let is that it can minimize database calls due to memoization? describe "#something" do let(:something) = Something.groovy_scope it "does x" do something.first.x.should have_coolness end it "does y" do something.first.y.should_not have_coolness end end vs. describe "#something" do before :each do @something = Something.groovy_scope end it "does x" do @something.first.x.should_not have_coolness end it "does y" do @something.first.y.should_not have_coolness end end ... Is that the proper usage? Patrick J. Collins http://collinatorstudios.com From patrick at collinatorstudios.com Fri Sep 30 15:49:35 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 30 Sep 2011 12:49:35 -0700 (PDT) Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: References: Message-ID: > Am I correct in understanding that the point of using let is that it can > minimize database calls due to memoization? > > describe "#something" do > > let(:something) = Something.groovy_scope and obviously I meant let(:something) { ... }, not = (oops)... Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Fri Sep 30 16:05:37 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 30 Sep 2011 15:05:37 -0500 Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: References: Message-ID: On Sep 30, 2011, at 2:48 PM, Patrick J. Collins wrote: > Am I correct in understanding that the point of using let is that it can > minimize database calls due to memoization? > > describe "#something" do > > let(:something) = Something.groovy_scope > > it "does x" do > something.first.x.should have_coolness > end > > it "does y" do > something.first.y.should_not have_coolness > end > > end > > vs. > > describe "#something" do > > before :each do > @something = Something.groovy_scope > end > > it "does x" do > @something.first.x.should_not have_coolness > end > > it "does y" do > @something.first.y.should_not have_coolness > end > > end > > ... > > Is that the proper usage? Proper usage, sure, but the memoization is only within each example - not across examples. That way you can do this: let(:thing) { Thing.new } it "does something" do thing.blah thing.whatever thing.yet_again end In that case each reference to thing returns the same object. Make sense? From patrick at collinatorstudios.com Fri Sep 30 16:31:40 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 30 Sep 2011 13:31:40 -0700 (PDT) Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: References: Message-ID: > Proper usage, sure, but the memoization is only within each example - not across examples. That way you can do this: > > let(:thing) { Thing.new } > > it "does something" do > thing.blah > thing.whatever > thing.yet_again > end > > In that case each reference to thing returns the same object. > > Make sense? Hmm.. now I am confused... What is the difference between: describe "Foo" do let(:foo) { Foo.new } it "is tubular" do foo.bar foo.baz end it "is gnarly" do foo.gnarl foo.wurd_up end end vs. describe "Foo" do before :each do @foo = Foo.new end it "seems just as tubular as the foo w/ let" do @foo.bar @foo.baz end it "seems just as gnarly as the foo w/ let" do foo.gnarl foo.wurd_up end end I am not seeing any difference...? Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Fri Sep 30 16:35:17 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 30 Sep 2011 15:35:17 -0500 Subject: [rspec-users] Custom Formatter: Getting Text from It Method In-Reply-To: <6ba93974-a471-476f-8943-ad7849b219fe@db5g2000vbb.googlegroups.com> References: <6ba93974-a471-476f-8943-ad7849b219fe@db5g2000vbb.googlegroups.com> Message-ID: <54697668-6839-46D1-BA22-A47D98DAB79E@gmail.com> On Sep 28, 2011, at 7:30 AM, Jeff Nyman wrote: > Hey all. > > I've been playing around with RSpec custom formatters to see how much > flexibility there is. One thing I've been trying to see is if I can > print the contents of a variable that's in an example (it) method. So, > for example, here's what I have in my specification: > > it "should display results range" do > search_for("star wars") > @browser.text.should match(/Showing .* of .* Results/) > intent = "Text 'Showing .* of .* Results' shows after 'Star Wars' > search" > end > > Notice the line with intent there? I realize this is not what most > people would do with RSpec. The reason I'm doing this is because I'd > like viewers of the test results to see the exact condition that was > tested for in the should if they want to -- without having to read the > code. Again, I'm just experimenting. > > What I'm trying to do is figure out how I could use a custom formatter > to print out that intent text. I know that the example_passed method > in the formatters contains elements like example.description that > prints out the text of the it method. But trying @output.puts > example.intent does not seem to work. > > Is there a better way to do what I'm trying to do here? Again, I > realize that most people are happy with the describe and it text being > printed out. But sometimes people -- like my business users -- want to > check the actual condition that was checked for, without having to > read Ruby code. > > Any pointers or tips would be greatly appreciated. > > - Jeff The variables defined inside the example are out of scope in the formatter. You can do something like this: ================== require 'rspec/core/formatters/base_text_formatter' module ExtraDoc def example_passed(example) example.description << ": #{example.metadata[:extra_doc]}" end end RSpec::Core::Formatters::BaseTextFormatter.send(:include, ExtraDoc) describe "something" do it "does something", :extra_doc => "with extra sauce" do end end ================== Output from `rspec --format documentation` is: ================== something does something: with extra sauce ================== That said, I'd focus on naming the examples better so they serve the needs of all readers. HTH, David From dchelimsky at gmail.com Fri Sep 30 16:58:57 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 30 Sep 2011 15:58:57 -0500 Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: References: Message-ID: On Sep 30, 2011, at 3:31 PM, Patrick J. Collins wrote: >> Proper usage, sure, but the memoization is only within each example - not across examples. That way you can do this: >> >> let(:thing) { Thing.new } >> >> it "does something" do >> thing.blah >> thing.whatever >> thing.yet_again >> end >> >> In that case each reference to thing returns the same object. >> >> Make sense? > > Hmm.. now I am confused... > > What is the difference between: > > describe "Foo" do > > let(:foo) { Foo.new } > > it "is tubular" do > foo.bar > foo.baz > end > > it "is gnarly" do > foo.gnarl > foo.wurd_up > end > > end > > vs. > > describe "Foo" do > > before :each do > @foo = Foo.new > end > > it "seems just as tubular as the foo w/ let" do > @foo.bar > @foo.baz > end > > it "seems just as gnarly as the foo w/ let" do > @foo.gnarl > @foo.wurd_up > end > > end > > I am not seeing any difference...? There is not, really, other than how the declaration of foo is expressed and referenced. This evolved out of a common pattern in TDD: 1: describe "something" do it "does something" do thing = Thing.new thing.do_something.should have_some_outcome end end 2: describe "something" do it "does something" do thing = Thing.new thing.do_something.should have_some_outcome end it "does something else" do thing = Thing.new thing.do_something_else.should have_some_other_outcome end end Now there is duplication so we can refactor out the declaration of thing. It takes less work and is less error prone to change it to a let declaration than to change the references to thing to an instance variable declared in a before hook. Cheers, David From srushti at ambekallu.com Fri Sep 30 17:32:25 2011 From: srushti at ambekallu.com (Srushti Ambekallu) Date: Fri, 30 Sep 2011 16:32:25 -0500 Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: References: Message-ID: <4E863569.2080508@gmail.com> On 30/09/11 3:58 PM, David Chelimsky wrote: > On Sep 30, 2011, at 3:31 PM, Patrick J. Collins wrote: > >>> Proper usage, sure, but the memoization is only within each example - not across examples. That way you can do this: >>> >>> let(:thing) { Thing.new } >>> >>> it "does something" do >>> thing.blah >>> thing.whatever >>> thing.yet_again >>> end >>> >>> In that case each reference to thing returns the same object. >>> >>> Make sense? >> Hmm.. now I am confused... >> >> What is the difference between: >> >> describe "Foo" do >> >> let(:foo) { Foo.new } >> >> it "is tubular" do >> foo.bar >> foo.baz >> end >> >> it "is gnarly" do >> foo.gnarl >> foo.wurd_up >> end >> >> end >> >> vs. >> >> describe "Foo" do >> >> before :each do >> @foo = Foo.new >> end >> >> it "seems just as tubular as the foo w/ let" do >> @foo.bar >> @foo.baz >> end >> >> it "seems just as gnarly as the foo w/ let" do >> @foo.gnarl >> @foo.wurd_up >> end >> >> end >> >> I am not seeing any difference...? > There is not, really, other than how the declaration of foo is expressed and referenced. This evolved out of a common pattern in TDD: > > 1: > > describe "something" do > it "does something" do > thing = Thing.new > thing.do_something.should have_some_outcome > end > end > > 2: > > describe "something" do > it "does something" do > thing = Thing.new > thing.do_something.should have_some_outcome > end > > it "does something else" do > thing = Thing.new > thing.do_something_else.should have_some_other_outcome > end > end > > Now there is duplication so we can refactor out the declaration of thing. It takes less work and is less error prone to change it to a let declaration than to change the references to thing to an instance variable declared in a before hook. > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > One thing I noticed, and something that always catches me out is the fact that the 'let'ted object doesn't get instantiated until it gets referenced. Therefore, describe "all" do let(:foo) { Foo.create! } it "returns the created object" do Foo.all.should include(foo) end end ... fails, since at the time of calling :all, the 'foo' object hasn't been referred yet, and hence the block hasn't executed. "Foo.all" in the case above returns an empty array, which wouldn't have been the case with an instance object created in "before(:each)". Srushti http://c42.in From dchelimsky at gmail.com Fri Sep 30 17:42:31 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 30 Sep 2011 16:42:31 -0500 Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: <4E863569.2080508@gmail.com> References: <4E863569.2080508@gmail.com> Message-ID: <41135802-A201-4C1D-9EF6-34EAEA4A00A9@gmail.com> On Sep 30, 2011, at 4:32 PM, Srushti Ambekallu wrote: > On 30/09/11 3:58 PM, David Chelimsky wrote: >> On Sep 30, 2011, at 3:31 PM, Patrick J. Collins wrote: >> >>>> Proper usage, sure, but the memoization is only within each example - not across examples. That way you can do this: >>>> >>>> let(:thing) { Thing.new } >>>> >>>> it "does something" do >>>> thing.blah >>>> thing.whatever >>>> thing.yet_again >>>> end >>>> >>>> In that case each reference to thing returns the same object. >>>> >>>> Make sense? >>> Hmm.. now I am confused... >>> >>> What is the difference between: >>> >>> describe "Foo" do >>> >>> let(:foo) { Foo.new } >>> >>> it "is tubular" do >>> foo.bar >>> foo.baz >>> end >>> >>> it "is gnarly" do >>> foo.gnarl >>> foo.wurd_up >>> end >>> >>> end >>> >>> vs. >>> >>> describe "Foo" do >>> >>> before :each do >>> @foo = Foo.new >>> end >>> >>> it "seems just as tubular as the foo w/ let" do >>> @foo.bar >>> @foo.baz >>> end >>> >>> it "seems just as gnarly as the foo w/ let" do >>> @foo.gnarl >>> @foo.wurd_up >>> end >>> >>> end >>> >>> I am not seeing any difference...? >> There is not, really, other than how the declaration of foo is expressed and referenced. This evolved out of a common pattern in TDD: >> >> 1: >> >> describe "something" do >> it "does something" do >> thing = Thing.new >> thing.do_something.should have_some_outcome >> end >> end >> >> 2: >> >> describe "something" do >> it "does something" do >> thing = Thing.new >> thing.do_something.should have_some_outcome >> end >> >> it "does something else" do >> thing = Thing.new >> thing.do_something_else.should have_some_other_outcome >> end >> end >> >> Now there is duplication so we can refactor out the declaration of thing. It takes less work and is less error prone to change it to a let declaration than to change the references to thing to an instance variable declared in a before hook. >> >> Cheers, >> David >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > One thing I noticed, and something that always catches me out is the fact that the 'let'ted object doesn't get instantiated until it gets referenced. Therefore, > > describe "all" do > let(:foo) { Foo.create! } > > it "returns the created object" do > Foo.all.should include(foo) > end > end > > ... fails, since at the time of calling :all, the 'foo' object hasn't been referred yet, and hence the block hasn't executed. "Foo.all" in the case above returns an empty array, which wouldn't have been the case with an instance object created in "before(:each)". > > Srushti > http://c42.in That's one of the benefits of let :) You can use it to declare objects but they only get instantiated when you reference them. See https://www.relishapp.com/rspec/rspec-core/docs/helper-methods/let-and-let From patrick at collinatorstudios.com Fri Sep 30 19:24:58 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 30 Sep 2011 16:24:58 -0700 (PDT) Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: <41135802-A201-4C1D-9EF6-34EAEA4A00A9@gmail.com> References: <4E863569.2080508@gmail.com> <41135802-A201-4C1D-9EF6-34EAEA4A00A9@gmail.com> Message-ID: > Proper usage, sure, but the memoization is only within each example - not > across examples. That way you can do this: So regarding objects persisting over multiple examples-- I was told repeatedly by experienced RSpec peeps to not use before(:all)... But in a case like: before(:each) do @user = create_user create_user_item(:user => @user) end it "has an item" do @user.user_item.should_not be_nil end it "rocks the house" do @user.user_item.should respond_to(:rocks_the_house) end ..etc... It seems like this is an instance where before :all, really would shine because it would not require records to be repeatedly created... Do you guys feel like before(:all) is just bad because of the possibility of a method call in one example changing the state and therefore breaking future examples and not having it be clear as to why.. ? Patrick J. Collins http://collinatorstudios.com From srushti at ambekallu.com Fri Sep 30 19:36:44 2011 From: srushti at ambekallu.com (Srushti Ambekallu) Date: Fri, 30 Sep 2011 18:36:44 -0500 Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: References: <4E863569.2080508@gmail.com> <41135802-A201-4C1D-9EF6-34EAEA4A00A9@gmail.com> Message-ID: <4E86528C.20700@gmail.com> On 30/09/11 6:24 PM, Patrick J. Collins wrote: >> Proper usage, sure, but the memoization is only within each example - not >> across examples. That way you can do this: > So regarding objects persisting over multiple examples-- I was told repeatedly > by experienced RSpec peeps to not use before(:all)... > > But in a case like: > > before(:each) do > @user = create_user > create_user_item(:user => @user) > end > > it "has an item" do > @user.user_item.should_not be_nil > end > > it "rocks the house" do > @user.user_item.should respond_to(:rocks_the_house) > end > > ..etc... > > It seems like this is an instance where before :all, really would shine because > it would not require records to be repeatedly created... > > Do you guys feel like before(:all) is just bad because of the possibility of a > method call in one example changing the state and therefore breaking future > examples and not having it be clear as to why.. ? > > > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I don't know if object creation (including the corresponding database calls) are really expensive enough that I would worry about optimising that (unless you're getting it anyway, without losing anything in the process, like with 'let'). Occasionally, for some reason I'll end up using a 'before(:all)' for one isolated scenario, but inevitably a few months down the line, I'll end up wasting a couple of hours on a weird failing test, until I look closely enough to notice the ":all". So, unless I'm doing something that's prohibitively expensive (I haven't found anything that would qualify in any of my projects) I'm not likely to create anything in a 'before(:all)'. Srushti http://c42.in From alexch at gmail.com Fri Sep 30 22:17:44 2011 From: alexch at gmail.com (Alex Chaffee) Date: Fri, 30 Sep 2011 19:17:44 -0700 Subject: [rspec-users] Custom Formatter: Getting Text from It Method In-Reply-To: <6ba93974-a471-476f-8943-ad7849b219fe@db5g2000vbb.googlegroups.com> References: <6ba93974-a471-476f-8943-ad7849b219fe@db5g2000vbb.googlegroups.com> Message-ID: <3BA13A5B-69E7-4C8F-8C99-D33031DC9A15@gmail.com> > The reason I'm doing this is because I'd like viewers of the test results to see the exact condition that was tested for in the should if they want to -- without having to read the code. Have you seen Wrong? You just described its intent :-) http://github.com/sconover/wrong If you get a source code block you can use the Chunk class in Wrong to parse it and pull out useful snippets. But you probably won't have access to the binding and its values at that point. hth - A On Sep 28, 2011, at 5:30 AM, Jeff Nyman wrote: > Hey all. > > I've been playing around with RSpec custom formatters to see how much > flexibility there is. One thing I've been trying to see is if I can > print the contents of a variable that's in an example (it) method. So, > for example, here's what I have in my specification: > > it "should display results range" do > search_for("star wars") > @browser.text.should match(/Showing .* of .* Results/) > intent = "Text 'Showing .* of .* Results' shows after 'Star Wars' > search" > end > > Notice the line with intent there? I realize this is not what most > people would do with RSpec. The reason I'm doing this is because I'd > like viewers of the test results to see the exact condition that was > tested for in the should if they want to -- without having to read the > code. Again, I'm just experimenting. > > What I'm trying to do is figure out how I could use a custom formatter > to print out that intent text. I know that the example_passed method > in the formatters contains elements like example.description that > prints out the text of the it method. But trying @output.puts > example.intent does not seem to work. > > Is there a better way to do what I'm trying to do here? Again, I > realize that most people are happy with the describe and it text being > printed out. But sometimes people -- like my business users -- want to > check the actual condition that was checked for, without having to > read Ruby code. > > Any pointers or tips would be greatly appreciated. > > - Jeff > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: