From ash.moran at patchspace.co.uk Sat Oct 1 06:30:40 2011 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Sat, 1 Oct 2011 11:30:40 +0100 Subject: [rspec-users] let vs ivar w/ before block In-Reply-To: <4E86528C.20700@gmail.com> References: <4E863569.2080508@gmail.com> <41135802-A201-4C1D-9EF6-34EAEA4A00A9@gmail.com> <4E86528C.20700@gmail.com> Message-ID: On 1 Oct 2011, at 00:36, Srushti Ambekallu wrote: > On 30/09/11 6:24 PM, Patrick J. Collins wrote: >> So regarding objects persisting over multiple examples-- I was told repeatedly >> by experienced RSpec peeps to not use before(:all)? > > 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)'. I'll second that. It's better to feel the pain of the multiple database hits and refactor it out in the code (can you separate more of the logic and persistence?), than try to optimise the test run by introducing shared state. In the long run, the former will give you many faster test runs through better design, where as the latter will give you a few faster tests now at the risk of - as Srushti points out - stepping on a landmine later. HTH Ash -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From f.schaefer at finn.de Sat Oct 1 09:03:12 2011 From: f.schaefer at finn.de (=?iso-8859-1?Q?Felix_Sch=E4fer?=) Date: Sat, 1 Oct 2011 15:03:12 +0200 Subject: [rspec-users] Override tests (of a core rails app from a plugin) Message-ID: <3F850FC4-2A0C-4E60-A2BB-505EF435277C@finn.de> Hello, Is there some way to override a spec and more specifically parts of spec, ideally down to a specific example? I've been looking and googling for something like this, but I haven't found a good strategy for it. The use-case is for a rails app that supports plugins, and those plugins may also tweak the behavior of core objects. For example (and it is a simplistic and bad example, but bear with me): Suppose a User object that has a boolean attribute show_mail_address that controls if the mail address of the user can be shown publicly, and that this defaults to true in the core app, but a security-savvy user of the software doesn't want that and creates a plugin to change the default to false. Running the core tests with the plugin will fail because the default won't be the one the tests expect. Is there any way to selectively override examples/tests/groups and/or extend tests (in the case the plugin adds functionality to the core object)? Thanks, Felix From jko170 at gmail.com Sat Oct 1 16:17:16 2011 From: jko170 at gmail.com (Justin Ko) Date: Sat, 1 Oct 2011 14:17:16 -0600 Subject: [rspec-users] Override tests (of a core rails app from a plugin) In-Reply-To: <3F850FC4-2A0C-4E60-A2BB-505EF435277C@finn.de> References: <3F850FC4-2A0C-4E60-A2BB-505EF435277C@finn.de> Message-ID: <7A97505B-825F-4833-8B61-AF614A91993D@gmail.com> On Oct 1, 2011, at 7:03 AM, Felix Sch?fer wrote: > Hello, > > Is there some way to override a spec and more specifically parts of spec, ideally down to a specific example? I've been looking and googling for something like this, but I haven't found a good strategy for it. > > The use-case is for a rails app that supports plugins, and those plugins may also tweak the behavior of core objects. For example (and it is a simplistic and bad example, but bear with me): Suppose a User object that has a boolean attribute show_mail_address that controls if the mail address of the user can be shown publicly, and that this defaults to true in the core app, but a security-savvy user of the software doesn't want that and creates a plugin to change the default to false. Running the core tests with the plugin will fail because the default won't be the one the tests expect. Is there any way to selectively override examples/tests/groups and/or extend tests (in the case the plugin adds functionality to the core object)? > > Thanks, > > Felix > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Specs do not over-ride each other, so I can't think of an easy to do what you're trying to do. With that said, I have never come across a situation like this because usually the app has one or the other. Shouldn't the user delete their own code that your plugin accomplishes after they install it? Or, maybe your plugin overrides their core functionality, but doesn't provide tests - in which case it's up to the user to adjust their tests to your plugin. From f.schaefer at finn.de Sun Oct 2 14:57:19 2011 From: f.schaefer at finn.de (=?iso-8859-1?Q?Felix_Sch=E4fer?=) Date: Sun, 2 Oct 2011 20:57:19 +0200 Subject: [rspec-users] Override tests (of a core rails app from a plugin) In-Reply-To: <7A97505B-825F-4833-8B61-AF614A91993D@gmail.com> References: <3F850FC4-2A0C-4E60-A2BB-505EF435277C@finn.de> <7A97505B-825F-4833-8B61-AF614A91993D@gmail.com> Message-ID: <21C9A936-51BD-4770-B299-64DC233C277F@finn.de> Am 01.10.2011 um 22:17 schrieb Justin Ko: > Specs do not over-ride each other That's what I was able to gather so far, unfortunately. > , so I can't think of an easy to do what you're trying to do. With that said, I have never come across a situation like this because usually the app has one or the other. Shouldn't the user delete their own code that your plugin accomplishes after they install it? Or, maybe your plugin overrides their core functionality, but doesn't provide tests - in which case it's up to the user to adjust their tests to your plugin. The point is that a plugin can change core code but not core tests, making the core tests virtually useless. I'm aware that the preferred solution would probably be to test the core app and the plugins independently, or at least that the plugins only test what they change so that you could say "if the core tests without the plugin and the plugin tests with the plugin work, everything is fine", it doesn't work that well though. Changes introduced by plugins might slightly change other behaviors and have unintended (and thus not tested by the plugin's tests) side-effects which the core tests might catch, if those are known to break because of intentional changes to the core by the plugin, they're of no use. Felix From alex at stinky.com Sun Oct 2 15:41:33 2011 From: alex at stinky.com (Alex Chaffee) Date: Sun, 2 Oct 2011 12:41:33 -0700 Subject: [rspec-users] Override tests (of a core rails app from a plugin) In-Reply-To: <21C9A936-51BD-4770-B299-64DC233C277F@finn.de> References: <3F850FC4-2A0C-4E60-A2BB-505EF435277C@finn.de> <7A97505B-825F-4833-8B61-AF614A91993D@gmail.com> <21C9A936-51BD-4770-B299-64DC233C277F@finn.de> Message-ID: I'm not sure what you mean by "core code" and "the user" here. Are you writing an app, or a library, or a plugin? If you're writing an app, you should test the app's behavior, which includes all the plugins and however you configured them; if you're writing a library you should have scenarios that test the various configuration options and basic functionality. If you're writing a Rails plugin, you should test how that plugin works inside apps. One way to do this is to generate some toy rails apps, stick them deep inside your "spec" directory somewhere, have them include your plugin and configure it in various ways, then test that the toy apps perform as expected. (Technically those would be integration tests, not unit tests, and you don't want to write too many of them if you can test the bulk of your code through unit tests.) you could say "if the core tests without the plugin and the plugin tests > with the plugin work, everything is fine", it doesn't work that well though. If your app is using a plugin, then why (and how) would you ever test your app without the plugin? -- Alex Chaffee - alex at stinky.com http://alexchaffee.com http://twitter.com/alexch -------------- next part -------------- An HTML attachment was scrubbed... URL: From adam.sroka at gmail.com Sun Oct 2 16:28:46 2011 From: adam.sroka at gmail.com (Adam Sroka) Date: Sun, 2 Oct 2011 13:28:46 -0700 Subject: [rspec-users] Override tests (of a core rails app from a plugin) In-Reply-To: <21C9A936-51BD-4770-B299-64DC233C277F@finn.de> References: <3F850FC4-2A0C-4E60-A2BB-505EF435277C@finn.de> <7A97505B-825F-4833-8B61-AF614A91993D@gmail.com> <21C9A936-51BD-4770-B299-64DC233C277F@finn.de> Message-ID: On Sun, Oct 2, 2011 at 11:57 AM, Felix Sch?fer wrote: > > Am 01.10.2011 um 22:17 schrieb Justin Ko: > >> Specs do not over-ride each other > > That's what I was able to gather so far, unfortunately. > >> , so I can't think of an easy to do what you're trying to do. With that said, I have never come across a situation like this because usually the app has one or the other. Shouldn't the user delete their own code that your plugin accomplishes after they install it? Or, maybe your plugin overrides their core functionality, but doesn't provide tests - in which case it's up to the user to adjust their tests to your plugin. > > The point is that a plugin can change core code but not core tests, making the core tests virtually useless. I'm aware that the preferred solution would probably be to test the core app and the plugins independently, or at least that the plugins only test what they change so that you could say "if the core tests without the plugin and the plugin tests with the plugin work, everything is fine", it doesn't work that well though. Changes introduced by plugins might slightly change other behaviors and have unintended (and thus not tested by the plugin's tests) side-effects which the core tests might catch, if those are known to break because of intentional changes to the core by the plugin, they're of no use. > So, what you are saying is that you don't know how the core is supposed to work after the user modifies it. So, you can't test that. But, you need the core tests to prove that it works after they modify it (Although, you don't know how it will work then.) :-( What you want seems like a logical impossibility to me. From matt at mattwynne.net Sun Oct 2 17:02:58 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 2 Oct 2011 22:02:58 +0100 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: On 28 Sep 2011, at 01:09, Alex Chaffee wrote: > 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... I haven't used it, but this looks good to me. > > -- > Alex Chaffee - alex at stinky.com > http://alexchaffee.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 From byofuel at gmail.com Sun Oct 2 03:57:26 2011 From: byofuel at gmail.com (Byo Fuel) Date: Sun, 2 Oct 2011 00:57:26 -0700 (PDT) Subject: [rspec-users] Why does rake spec attempt to drop development db? Message-ID: <22207111.19.1317542246513.JavaMail.geo-discussion-forums@prfp13> I have a new Rails 3.1 app on Ruby 1.9.2 with Postgres. My specs pass if run separately, but when I rake spec it fails because it can't purge the development database. in task 'rake:test:purge' . I confirmed my database.yml is pointing to the correct db: development: &postgres_defaults adapter: postgresql encoding: unicode database: via_development pool: 5 username: devuser password: xxx # host: /var/run/postgresql # or: 127.0.0.1 host: 127.0.0.1 test: <<: *postgres_defaults database: via_test Here's the stack dump (I get the same results with RAILS_ENV=test rake spec --tracce) kurtmacb:via kurtsnyder$ rake spec --trace ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment ** 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 rake aborted! PGError: ERROR: database "via_development" is being accessed by other users DETAIL: There are 2 other session(s) using the database. : DROP DATABASE IF EXISTS "via_development" /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:541:in `async_exec' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:541:in `block in execute' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:540:in `execute' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `drop_database' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:546:in `drop_database' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:454:in `block (3 levels) in ' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:205:in `call' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:200:in `each' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' /Users/kurtsnyder/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:174:in `each' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain' /Users/kurtsnyder/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:481:in `block (3 levels) in ' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:205:in `call' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:200:in `each' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' /Users/kurtsnyder/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:174:in `each' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain' /Users/kurtsnyder/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:90:in `each' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:59:in `run' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/bin/rake:32:in `' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `load' /Users/kurtsnyder/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `
' Tasks: TOP => db:test:load => db:test:purge Thanks for looking! -------------- next part -------------- An HTML attachment was scrubbed... URL: From pieter at noort.be Tue Oct 4 03:26:59 2011 From: pieter at noort.be (Pieter Michels) Date: Tue, 4 Oct 2011 00:26:59 -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> <8869616.1039.1315181173326.JavaMail.geo-discussion-forums@yqja21> Message-ID: <79684b2d-d7fe-4f12-9b49-bf97014be02d@i14g2000yqg.googlegroups.com> I seem to have the same problem. DId you guys find out what the problem was? Thanks On Sep 5, 3:11?am, Chris Habgood wrote: > 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-us... 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 > * > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From patrik.sundberg at gmail.com Wed Oct 5 04:46:44 2011 From: patrik.sundberg at gmail.com (sundbp) Date: Wed, 5 Oct 2011 01:46:44 -0700 (PDT) Subject: [rspec-users] Could this pull request pls be considered? Message-ID: <13268331.2008.1317804405000.JavaMail.geo-discussion-forums@yqjw35> https://github.com/rspec/rspec-core/pull/421 If you look at rcov's code it's clear it always use ":", not PATH_SEPARATOR. On windows where PATH_SEPARATOR=; rspec therefore breaks when using rcov (and having more than 1 directory given to the -I flag). Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Oct 5 07:51:14 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Oct 2011 06:51:14 -0500 Subject: [rspec-users] Could this pull request pls be considered? In-Reply-To: <13268331.2008.1317804405000.JavaMail.geo-discussion-forums@yqjw35> References: <13268331.2008.1317804405000.JavaMail.geo-discussion-forums@yqjw35> Message-ID: <907CEF61-66BE-49BD-9955-1A7E9ACEE09F@gmail.com> On Oct 5, 2011, at 3:46 AM, sundbp wrote: > https://github.com/rspec/rspec-core/pull/421 > > If you look at rcov's code it's clear it always use ":", not PATH_SEPARATOR. On windows where PATH_SEPARATOR=; rspec therefore breaks when using rcov (and having more than 1 directory given to the -I flag). > > Thanks! I had already made that fix before the pull request came in. It'll be part of the 2.7 release (in the next few weeks). Cheers, David From hi at nicolassanguinetti.info Wed Oct 5 08:08:10 2011 From: hi at nicolassanguinetti.info (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Wed, 5 Oct 2011 10:08:10 -0200 Subject: [rspec-users] Could this pull request pls be considered? In-Reply-To: <13268331.2008.1317804405000.JavaMail.geo-discussion-forums@yqjw35> References: <13268331.2008.1317804405000.JavaMail.geo-discussion-forums@yqjw35> Message-ID: Why this instead of changing rcov to use PATH_SEPARATOR instead? On Wed, Oct 5, 2011 at 6:46 AM, sundbp wrote: > https://github.com/rspec/rspec-core/pull/421 > > If you look at rcov's code it's clear it always use ":", not PATH_SEPARATOR. > On windows where PATH_SEPARATOR=; rspec therefore breaks when using rcov > (and having more than 1 directory given to the -I flag). > > Thanks! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Oct 5 08:45:17 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Oct 2011 07:45:17 -0500 Subject: [rspec-users] Could this pull request pls be considered? In-Reply-To: References: <13268331.2008.1317804405000.JavaMail.geo-discussion-forums@yqjw35> Message-ID: <596ACD42-75D2-4923-9979-EDBFC8C5F559@gmail.com> On Oct 5, 2011, at 7:08 AM, Nicol?s Sanguinetti wrote: > On Wed, Oct 5, 2011 at 6:46 AM, sundbp wrote: >> https://github.com/rspec/rspec-core/pull/421 >> >> If you look at rcov's code it's clear it always use ":", not PATH_SEPARATOR. >> On windows where PATH_SEPARATOR=; rspec therefore breaks when using rcov >> (and having more than 1 directory given to the -I flag). >> >> Thanks! > Why this instead of changing rcov to use PATH_SEPARATOR instead? Excellent point! I've submitted https://github.com/relevance/rcov/issues/83. Please feel free to comment on it. Cheers, David From dchelimsky at gmail.com Wed Oct 5 09:15:09 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Oct 2011 08:15:09 -0500 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: <3E052B7E-2E66-4117-8FF5-197E52D86F98@gmail.com> On Sep 3, 2011, at 4:17 PM, Chris Habgood wrote: > 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 Try Factory.build instead of Factory (which is an alias for Factory.create): user = Factory.build(:user, :email => '', :password => '') user.should_not be_valid # this triggers the validation user.should have(1).error_on(:email) user.should have(1).error_on(: password) HTH, David > #user.should have(2).errors #_on(:name) > end From nathanvda at gmail.com Wed Oct 5 15:28:57 2011 From: nathanvda at gmail.com (nathanvda) Date: Wed, 5 Oct 2011 12:28:57 -0700 (PDT) Subject: [rspec-users] testing a render of a partial in a helper Message-ID: <2b77c3f1-bd5c-487d-8bf1-7d991bc5d278@t16g2000yqm.googlegroups.com> I am trying to spec my helpers, and I find a few of my helpers actually render a partial. My code: module PageHelper def settings_menu render :partial => '_shared/settings_menu' end def banner_for(model) banner_message = ... some message ... render :partial => 'shared/banner', :locals => { :message => banner_message } end end I want to be able to either capture the result of the render, or just express the expectation that the `render` is called. For now neither work. My test now looks as follows: require 'spec_helper' describe PageHelper do context "settings_menu" do it "render the correct partial" do helper.should_receive(:render).with({:partial => 'shared/ settings_menu'}) helper.settings_menu end it "generates the correct result" do @result = helper.settings_menu @result.should be == "something" end end end Both of these tests fail. The expectation is never met, and `@result` is always `nil`. From pieter at noort.be Wed Oct 5 16:02:54 2011 From: pieter at noort.be (Pieter Michels) Date: Wed, 5 Oct 2011 13:02:54 -0700 (PDT) Subject: [rspec-users] mongo_mapper validations, rpsec In-Reply-To: <3E052B7E-2E66-4117-8FF5-197E52D86F98@gmail.com> References: <12366665.943.1315084644109.JavaMail.geo-discussion-forums@yqav15> <3E052B7E-2E66-4117-8FF5-197E52D86F98@gmail.com> Message-ID: <358d2baa-f873-40b9-9efa-d41f6ade5597@fx14g2000vbb.googlegroups.com> Hi I sort of fixed the issue. Let me first describe it some more. My tests kept generating the following failed test: 1) Portfolio require a valid e-mail address Failure/Error: port = Factory :portfolio, :email => email MongoMapper::DocumentNotValid: Validation failed: Email is invalid # ./spec/models/portfolio_spec.rb:44:in `block (3 levels) in ' # ./spec/models/portfolio_spec.rb:43:in `each' # ./spec/models/portfolio_spec.rb:43:in `block (2 levels) in ' This tells me my validation is working as it should be. But although the code in production reacts normally on 'update_attributes' or 'save' by returning a 'false', in my test the MongoMapper::DocumentNotValid: is raised. I fixed it by using the following test code: lambda { port = Factory :portfolio, :email => '' }.should raise_error(MongoMapper::DocumentNotValid) This way I test for a working validation. I believe I have some setting that is causing this behaviour. I also tested it out in Rails console where it works as expected: port = Portfolio.find_by_name('test') port.name = 'new_name' port.save => false port.update_attributes(:name => 'new_name') => false Any ideas? regards On Oct 5, 3:15?pm, David Chelimsky wrote: > On Sep 3, 2011, at 4:17 PM, Chris Habgood wrote: > > > > 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 > > Try Factory.build instead of Factory (which is an alias for Factory.create): > > ? user = Factory.build(:user, :email => '', :password => '') > ? user.should_not be_valid # this triggers the validation > ? user.should have(1).error_on(:email) > ? user.should have(1).error_on(: password) > > HTH, > David > > > ? ? ? #user.should have(2).errors #_on(:name) > > ? end > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From byofuel at gmail.com Thu Oct 6 12:22:59 2011 From: byofuel at gmail.com (Byo Fuel) Date: Thu, 6 Oct 2011 09:22:59 -0700 (PDT) Subject: [rspec-users] Why does rake spec attempt to drop development db? In-Reply-To: <22207111.19.1317542246513.JavaMail.geo-discussion-forums@prfp13> References: <22207111.19.1317542246513.JavaMail.geo-discussion-forums@prfp13> Message-ID: <22805630.621.1317918180073.JavaMail.geo-discussion-forums@prho12> Figured it out -- sort of. For some reason, the database.yml was not being parsed properly to pick up the values for the development environment but override the database name for test. This block: test: <<: *postgres_defaults database: via_test was not successfully switching the database name declared in the development block, even though it follows the syntax I've used in other projects. This project is Ruby 1.9.2p180, Rails 3.1. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Oct 9 16:23:59 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 9 Oct 2011 15:23:59 -0500 Subject: [rspec-users] rspec 2.7.0.rc1 is released! Message-ID: <5FF64527-657A-4F67-86A8-ECD9DC47AD60@gmail.com> rspec 2.7.0.rc1 is released! This includes the following (see the changelog for each lib below): rspec-2.7.0.rc1 rspec-core-2.7.0.rc1 rspec-expectations-2.7.0.rc1 rspec-mocks-2.7.0.rc1 rspec-rails-2.7.0.rc1 Please direct any questions or issues to the github issues tracker for each repository or http://rubyforge.org/mailman/listinfo/rspec-users. Enjoy! David ### rspec-core-2.7.0.rc1 full changelog: http://github.com/rspec/rspec-core/compare/v2.6.4...v2.7.0.rc1 NOTE: RSpec's release policy dictates that there should not be any backward incompatible changes in minor releases, but we're making an exception to release a change to how RSpec interacts with other command line tools. As of 2.7.0, you must explicity `require "rspec/autorun"` unless you use the `rspec` command (which already does this for you). * Enhancements * Add example.exception (David Chelimsky) * --default_path command line option (Justin Ko) * support multiple --line_number options (David J. Hamilton) * also supports path/to/file.rb:5:9 (runs examples on lines 5 and 9) * Allow classes/modules to be used as shared example group identifiers (Arthur Gunn) * Friendly error message when shared context cannot be found (S?awosz S?awi?ski) * Clear formatters when resetting config (John Bintz) * Add xspecify and xexample as temp-pending methods (David Chelimsky) * Add --no-drb option (Iain Hecker) * Provide more accurate run time by registering start time before code is loaded (David Chelimsky) * Rake task default pattern finds specs in symlinked dirs (Kelly Felkins) * Rake task decides whether to use bundler or not based on presence of BUNDLE_GEMFILE (David Chelimsky) * Bug fixes * Include Rake::DSL to remove deprecation warnings in Rake > 0.8.7 (Pivotal Casebook) * Only eval `let` block once even if it returns `nil` (Adam Meehan) * Fix --pattern option (wasn't being recognized) (David Chelimsky) * Only implicitly require "rspec/autorun" with the `rspec` command (David Chelimsky) * Ensure that rspec's at_exit defines the exit code (Daniel Doubrovkine) * Show the correct snippet in the HTML and TextMate formatters (Brian Faherty) ### rspec-expectations-2.7.0.rc1 full changelog: http://github.com/rspec/rspec-expectations/compare/v2.6.0...v2.7.0.rc1 * Enhancements * HaveMatcher converts argument using #to_i (Alex Bepple & Pat Maddox) * Improved failure message for the have_xxx matcher (Myron Marston) * HaveMatcher supports #count (Matthew Bellantoni) * Change matcher dups Enumerable before the action, supporting custom Enumerable types like CollectionProxy in Rails (David Chelimsky) * Bug fixes * Fix typo in have(n).xyz documentation (Jean Boussier) * fix safe_sort for ruby 1.9.2 (Kernel now defines <=> for Object) (Peter van Hardenberg) ### rspec-mocks-2.7.0.rc1 full changelog: http://github.com/rspec/rspec-mocks/compare/v2.6.0...v2.7.0.rc1 * Enhancements * Use `__send__` rather than `send` (alextk) * Add support for any_instance.stub_chain (Sidu Ponnappa) * Add support for any_instance argument matching based on `with` (Sidu Ponnappa and Andy Lindeman) * Changes * Check for #failure_message_for_should or #failure_message instead of #description to detect a matcher (Tibor Claassen) * Bug fixes * pass a hash to `any_instance.stub`. (Justin Ko) * allow :to_ary to be called without raising NoMethodError (Mikhail Dieterle) ### rspec-rails-2.7.0.rc1 full changelog: http://github.com/rspec/rspec-rails/compare/v2.6.1...v2.7.0.rc1 * Enhancments * ActiveRecord::Relation can use the "=~" matcher (Andy Lindeman) * Make generated controller spec more consistent with regard to ids (Brent J. Nordquist) * Less restrictive autotest mapping between spec and implementation files (Jos? Valim) * require 'rspec/autorun' from generated spec_helper.rb (David Chelimsky) * bypass_rescue (Lenny Marks) * route_to accepts query string (Marc Weil) * Internal * Added specs for generators using ammeter (Alex Rothenberg) * Bug fixes * Fix configuration/integration bug with rails 3.0 (fixed in 3.1) in which fixure_file_upload reads from ActiveSupport::TestCase.fixture_path and misses RSpec's configuration (David Chelimsky) * Support nested resource in view spec generator (David Chelimsky) * Define `primary_key` on class generated by mock_model("WithAString") (David Chelimsky) From ash.moran at patchspace.co.uk Mon Oct 10 05:16:18 2011 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Mon, 10 Oct 2011 10:16:18 +0100 Subject: [rspec-users] rspec 2.7.0.rc1 is released! In-Reply-To: <5FF64527-657A-4F67-86A8-ECD9DC47AD60@gmail.com> References: <5FF64527-657A-4F67-86A8-ECD9DC47AD60@gmail.com> Message-ID: <61683929-2C97-48A6-8756-49540E83BC1B@patchspace.co.uk> On 9 Oct 2011, at 21:23, David Chelimsky wrote: > * Allow classes/modules to be used as shared example group identifiers > (Arthur Gunn) This sounds awesome. Are there any full examples? I could only see unit tests in the code. Ash -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From dchelimsky at gmail.com Mon Oct 10 10:22:20 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 10 Oct 2011 09:22:20 -0500 Subject: [rspec-users] rspec 2.7.0.rc1 is released! In-Reply-To: <61683929-2C97-48A6-8756-49540E83BC1B@patchspace.co.uk> References: <5FF64527-657A-4F67-86A8-ECD9DC47AD60@gmail.com> <61683929-2C97-48A6-8756-49540E83BC1B@patchspace.co.uk> Message-ID: <5B592195-0844-48D8-AD6F-7045F2ABA58B@gmail.com> On Oct 10, 2011, at 4:16 AM, Ash Moran wrote: > > On 9 Oct 2011, at 21:23, David Chelimsky wrote: > >> * Allow classes/modules to be used as shared example group identifiers >> (Arthur Gunn) > > This sounds awesome. Are there any full examples? I could only see unit tests in the code. Nope. Wanna add one? The basic idea is: shared_examples Enumerable do describe "#count" do it "returns 0 by default" do subject.count.should eq(0) end end end describe SpecialCollection do it_behaves_like Enumerable end Cheers, David From patrick at collinatorstudios.com Mon Oct 10 21:17:38 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 10 Oct 2011 18:17:38 -0700 (PDT) Subject: [rspec-users] understanding rspec predicates Message-ID: I know I can do: blah.should be_empty or blah.should have_key(:to_my_house) ... But, is there a way to do: str = "lmaonade omg rotfcopter!" str.should start_with("lmao") Or is it just best to do: str.starts_with?("lmao").should be_true ? Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Mon Oct 10 22:05:02 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 10 Oct 2011 21:05:02 -0500 Subject: [rspec-users] understanding rspec predicates In-Reply-To: References: Message-ID: <142999E7-A325-4601-8D22-23CEB0184354@gmail.com> On Oct 10, 2011, at 8:17 PM, Patrick J. Collins wrote: > I know I can do: > > blah.should be_empty > > or > > blah.should have_key(:to_my_house) > > ... > > But, is there a way to do: > > str = "lmaonade omg rotfcopter!" > > str.should start_with("lmao") > > Or is it just best to do: > > str.starts_with?("lmao").should be_true See https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/be-matchers and https://www.relishapp.com/rspec/rspec-expectations/docs/custom-matchers/define-matcher From nathanvda at gmail.com Tue Oct 11 07:04:28 2011 From: nathanvda at gmail.com (nathanvda) Date: Tue, 11 Oct 2011 04:04:28 -0700 (PDT) Subject: [rspec-users] testing a render of a partial in a helper In-Reply-To: <2b77c3f1-bd5c-487d-8bf1-7d991bc5d278@t16g2000yqm.googlegroups.com> References: <2b77c3f1-bd5c-487d-8bf1-7d991bc5d278@t16g2000yqm.googlegroups.com> Message-ID: Ignore this, I had a different problem in my code causing this. On Oct 5, 9:28?pm, nathanvda wrote: > I am trying to spec my helpers, and I find a few of my helpers > actually render a partial. > > My code: > > ? ? module PageHelper > ? ? ? def settings_menu > ? ? ? ? render :partial => '_shared/settings_menu' > ? ? ? end > > ? ? ? def banner_for(model) > ? ? ? ? banner_message = ... some message ... > ? ? ? ? render :partial => 'shared/banner', :locals => { :message => > banner_message } > ? ? ? end > ? ? end > > I want to be able to either capture the result of the render, or just > express the expectation that the `render` is called. For now neither > work. My test now looks as follows: > > ? ? require 'spec_helper' > > ? ? describe PageHelper do > > ? ? ? context "settings_menu" do > ? ? ? ? it "render the correct partial" do > ? ? ? ? ? helper.should_receive(:render).with({:partial => 'shared/ > settings_menu'}) > ? ? ? ? ? helper.settings_menu > ? ? ? ? end > ? ? ? ? it "generates the correct result" do > ? ? ? ? ? @result = helper.settings_menu > ? ? ? ? ? @result.should be == "something" > ? ? ? ? end > ? ? ? end > ? ? end > > Both of these tests fail. The expectation is never met, and `@result` > is always `nil`. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From nathanvda at gmail.com Tue Oct 11 07:05:38 2011 From: nathanvda at gmail.com (nathanvda) Date: Tue, 11 Oct 2011 04:05:38 -0700 (PDT) Subject: [rspec-users] Attempting to speed up my controller specs: using before all fails? Message-ID: I have a simple controller test, containing a.o. the following code: context "POST :create" do before (:each) do post :create, :user_id => @user.id, :account => { .. some data ... } end it { response.status.should == 201 } it { response.location.should be_present } end Now I thought of a very simple way to speed up this test, and to use a `before(:all)` instead of a `before(:each)`. In that case the POST would only be done once. So i wrote: context "POST :create" do before (:all) do post :create, :user_id => @user.id, :account => { .. some data ... } end it { response.status.should == 201 } it { response.location.should be_present } end But then I get the following errors: RuntimeError: @routes is nil: make sure you set it in your test's setup method. Is this by design? Is there a way to circumvent it? From xugrace at hotmail.com Fri Oct 7 14:04:36 2011 From: xugrace at hotmail.com (grace xu) Date: Fri, 7 Oct 2011 11:04:36 -0700 Subject: [rspec-users] rspec dry run Message-ID: We count how many examples before start executing example, we used to use --dry--run option to achieve this. Now dry run is removed in Rspec 2, do you have a way that we can count examples without executing examples? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjbottaro at gmail.com Sat Oct 8 14:30:25 2011 From: cjbottaro at gmail.com (Christopher J. Bottaro) Date: Sat, 8 Oct 2011 11:30:25 -0700 (PDT) Subject: [rspec-users] Rails view spec expectations/matchers Message-ID: <1079823.1315.1318098625176.JavaMail.geo-discussion-forums@yqjh13> >From looking at the RSpec Rails documentation (https://www.relishapp.com/rspec/rspec-rails/docs/view-specs/view-spec) it seems like rendered is just a string and you can't really do any assert_select type stuff out of the box. After Googling around, it seems that the RSpec authors decided that if you want that functionality, you should just use Capybara or some such... is that correct? If that is the case, can you please look at how I'm writing my view specs and let me know if there is a better/cleaner way? Here goes... *spec/spec_helper.rb* RSpec.configure do |config| config.include RSpec::ViewHelper, :type => :view end *spec/support/view_helper.rb* module RSpec::ViewHelper def page @page ||= Capybara::Node::Simple.new(rendered) end end *spec/views/comments/index.html.haml_spec.rb* require "spec_helper" describe "comments/index.html.haml" do it "should show a proper breadcrumb" do # Assign instance vars # Mock helper methods render page.should have_selector("div.breadcrumb") page.find("div.breadcrumb").tap do |node| node.find_link("Home").should be node.find_link("Blah1").should be node.find_link("Blah1").should be node.find_link("Comments").should be end end end Is there a better way? Including Capybara just for the finders/matchers seems kinda heavy. Also it would be nice if I could write stuff like node.should have_link("Home"), to be more consistent with RSpec matchers (though I guess I could write custom matchers to wrap all the Capybara stuff... has anyone already done this?). Thanks for the help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Mon Oct 10 13:02:19 2011 From: nick at deadorange.com (Nick) Date: Mon, 10 Oct 2011 10:02:19 -0700 (PDT) Subject: [rspec-users] URL helpers in model specs Message-ID: <3200209.3663.1318266139917.JavaMail.geo-discussion-forums@yqcs10> Hey guys. One of my models uses a Rails URL helper. In IRB, the method works. However, when I run the specs for the method, the URL helper doesn't exist. The only solution I've found is to include Rails.application.routes.url_helpers in both the model and the example group. Obviously, that's not ideal, because it's only necessary for the specs to work. Is there any other solution? https://gist.github.com/1275799 Thanks, Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Oct 11 09:21:13 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Oct 2011 08:21:13 -0500 Subject: [rspec-users] Rails view spec expectations/matchers In-Reply-To: <1079823.1315.1318098625176.JavaMail.geo-discussion-forums@yqjh13> References: <1079823.1315.1318098625176.JavaMail.geo-discussion-forums@yqjh13> Message-ID: <11AF84AF-A053-444B-ABE8-179AC4DE7340@gmail.com> On Oct 8, 2011, at 1:30 PM, Christopher J. Bottaro wrote: > >From looking at the RSpec Rails documentation (https://www.relishapp.com/rspec/rspec-rails/docs/view-specs/view-spec) it seems like rendered is just a string and you can't really do any assert_select type stuff out of the box. > > After Googling around, it seems that the RSpec authors decided that if you want that functionality, you should just use Capybara or some such... is that correct? The `rendered` method is a wrapper around the `@rendered` instance variable, which is provided by Rails: https://github.com/rails/rails/blob/master/actionpack/lib/action_view/test_case.rb#L113 The fact that assert_select doesn't work on a string is an issue you can (and probably should) report to the rails project. > If that is the case, can you please look at how I'm writing my view specs and let me know if there is a better/cleaner way? > > Here goes... > > spec/spec_helper.rb > RSpec.configure do |config| > config.include RSpec::ViewHelper, :type => :view > end > > spec/support/view_helper.rb > module RSpec::ViewHelper > def page > @page ||= Capybara::Node::Simple.new(rendered) > end > end ViewHelper sounds like something to help your views, not your view specs. I'd name this something like RSpec::CapybaraExtensions. I'd also avoid the name "page", which carries different implications in controller and request specs. Suggestions below ... > spec/views/comments/index.html.haml_spec.rb > require "spec_helper" > > describe "comments/index.html.haml" do > > it "should show a proper breadcrumb" do > # Assign instance vars > # Mock helper methods > > render > > page.should have_selector("div.breadcrumb") > page.find("div.breadcrumb").tap do |node| > node.find_link("Home").should be > node.find_link("Blah1").should be > node.find_link("Blah1").should be > node.find_link("Comments").should be > end > end > > end > > Is there a better way? Several! Here's one: def rendered Capybara.string(@rendered) end it "displays a proper breadcrumb" do render rendered.find("div.breadcrumb a", :text => "Home") rendered.find("div.breadcrumb a", :text => "Comments") end it "displays a proper breadcrumb" do render rendered.find("div.breadcrumb").tap do |form| form.find("a", :text => "Home") form.find("a", :text => "Comments") end end `find` doesn't look like an expectation, but if the elements aren't there you get OK feedback: Capybara::ElementNotFound: Unable to find css "div.breadcrumb" You could also make this more expressive like this: def rendered Capybara.string(@rendered) end def within(selector) yield rendered.find(selector) end it "displays a proper breadcrumb" do render within "div.breadcrumb" do |breadcrumb| breadcrumb.should have_selector("a", :text => "Home") breadcrumb.should have_selector("a", :text => "Comments") end end Now you'd get the feedback above if there were no "div.breadcrumb", but you'd get Capy's matcher feedback if there were no matching anchor tags within "div.breadcrumb", which is not very good right now: expected css "a" with text "Home" to return something There is a github issue to address this, but it's no small matter to get right (which is why it's still open): https://github.com/jnicklas/capybara/issues/331 > Including Capybara just for the finders/matchers seems kinda heavy. Why? Just load up the parts you want. > Also it would be nice if I could write stuff like node.should have_link("Home"), to be more consistent with RSpec matchers (though I guess I could write custom matchers to wrap all the Capybara stuff... has anyone already done this?). I'd prefer to stick to `have_selector("a", :text => "Home")`. That way it's the same API for every tag. But that's me. If you prefer have_link, have_text_field, etc, etc, then you should write them, and maybe even publish them in a gem. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Tue Oct 11 16:03:40 2011 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 11 Oct 2011 21:03:40 +0100 Subject: [rspec-users] URL helpers in model specs In-Reply-To: <3200209.3663.1318266139917.JavaMail.geo-discussion-forums@yqcs10> References: <3200209.3663.1318266139917.JavaMail.geo-discussion-forums@yqcs10> Message-ID: On 10 Oct 2011, at 18:02, Nick wrote: > Hey guys. One of my models uses a Rails URL helper. In IRB, the method works. However, when I run the specs for the method, the URL helper doesn't exist. > > The only solution I've found is to include Rails.application.routes.url_helpers in both the model and the example group. Obviously, that's not ideal, because it's only necessary for the specs to work. Is there any other solution? > > https://gist.github.com/1275799 I don't know about anyone else, but I can't see that gist. 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 patrick at collinatorstudios.com Tue Oct 11 20:22:55 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 11 Oct 2011 17:22:55 -0700 (PDT) Subject: [rspec-users] understanding rspec predicates In-Reply-To: <142999E7-A325-4601-8D22-23CEB0184354@gmail.com> References: <142999E7-A325-4601-8D22-23CEB0184354@gmail.com> Message-ID: > On Oct 10, 2011, at 8:17 PM, Patrick J. Collins wrote: > > > I know I can do: > > > > blah.should be_empty > > > > or > > > > blah.should have_key(:to_my_house) > > > > ... > > > > But, is there a way to do: > > > > str = "lmaonade omg rotfcopter!" > > > > str.should start_with("lmao") > > > > Or is it just best to do: > > > > str.starts_with?("lmao").should be_true > > See > > https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/be-matchers > > and > > https://www.relishapp.com/rspec/rspec-expectations/docs/custom-matchers/define-matcher > I see... So, the question I have now is, would some argue that defining custom matchers is not the best thing to do because it results in obfuscated test behavior which could result in false positives / funky breakage where one might not think to look? For example, one of my models has a method: def alert_flag? flag == FLAG_VALUES[:alert] end ... Having a spec that does: @my_model.alert_flag?.should be_true Seemed a little goofy to me... So I did: RSpec::Matchers.define :have_alert_flag do match do |actual| actual.alert_flag? end end So that I can do: @my_model.should have_alert_flag ... But then I got a little worried about the fact that this creates more magic in my test, makes things less clear for other developers who might not know what custom matchers are, etc.. Are these valid concerns? Or should I just keep making custom machers like this? As always, thanks for the guidance! Patrick J. Collins http://collinatorstudios.com From patmaddox at me.com Tue Oct 11 20:38:09 2011 From: patmaddox at me.com (Pat Maddox) Date: Tue, 11 Oct 2011 17:38:09 -0700 Subject: [rspec-users] understanding rspec predicates In-Reply-To: References: <142999E7-A325-4601-8D22-23CEB0184354@gmail.com> Message-ID: <2C415B3A-E07C-46B3-BFC4-91DC3C276FF0@me.com> On Oct 11, 2011, at 5:22 PM, Patrick J. Collins wrote: > Having a spec that does: > > @my_model.alert_flag?.should be_true > > Seemed a little goofy to me... So I did: You can do @my_model.should be_alert_flag A custom matcher isn't worth it in this case, in my opinion. Pat From dchelimsky at gmail.com Tue Oct 11 21:19:28 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Oct 2011 20:19:28 -0500 Subject: [rspec-users] understanding rspec predicates In-Reply-To: <2C415B3A-E07C-46B3-BFC4-91DC3C276FF0@me.com> References: <142999E7-A325-4601-8D22-23CEB0184354@gmail.com> <2C415B3A-E07C-46B3-BFC4-91DC3C276FF0@me.com> Message-ID: <39350D57-00AC-4978-9A5C-2680DBF4329C@gmail.com> On Oct 11, 2011, at 7:38 PM, Pat Maddox wrote: > On Oct 11, 2011, at 5:22 PM, Patrick J. Collins wrote: >> Having a spec that does: >> >> @my_model.alert_flag?.should be_true >> >> Seemed a little goofy to me... So I did: > > You can do > > @my_model.should be_alert_flag That name feels odd to me. The model is not an alert flag, it has one. This is actually a good thing! One point of be_xxx is to make you ask if "xxx?" is a good predicate name. If you wouldn't say "should be xxx" then you shouldnt be asking "xxx?". I'd rename it to something like "has_alert_flag?" or "flagged_for_alert?" so I could say "model.should have_alert_flag" or "model.should be_flagged_for_alert". > A custom matcher isn't worth it in this case, in my opinion. Agreed, as long as the name changes :) > Pat From patmaddox at me.com Tue Oct 11 22:09:47 2011 From: patmaddox at me.com (Pat Maddox) Date: Tue, 11 Oct 2011 19:09:47 -0700 Subject: [rspec-users] understanding rspec predicates In-Reply-To: <39350D57-00AC-4978-9A5C-2680DBF4329C@gmail.com> References: <142999E7-A325-4601-8D22-23CEB0184354@gmail.com> <2C415B3A-E07C-46B3-BFC4-91DC3C276FF0@me.com> <39350D57-00AC-4978-9A5C-2680DBF4329C@gmail.com> Message-ID: <23A3BBAD-3CDC-43B6-8BD4-F1D8FFFDC317@me.com> On Oct 11, 2011, at 6:19 PM, David Chelimsky wrote: > On Oct 11, 2011, at 7:38 PM, Pat Maddox wrote: > >> On Oct 11, 2011, at 5:22 PM, Patrick J. Collins wrote: >>> Having a spec that does: >>> >>> @my_model.alert_flag?.should be_true >>> >>> Seemed a little goofy to me... So I did: >> >> You can do >> >> @my_model.should be_alert_flag > > That name feels odd to me. The model is not an alert flag, it has one. This is actually a good thing! One point of be_xxx is to make you ask if "xxx?" is a good predicate name. If you wouldn't say "should be xxx" then you shouldnt be asking "xxx?". > > I'd rename it to something like "has_alert_flag?" or "flagged_for_alert?" so I could say "model.should have_alert_flag" or "model.should be_flagged_for_alert". Totally agree. I was going to let him come to that conclusion on his own ;) Pat From nick at deadorange.com Tue Oct 11 23:27:00 2011 From: nick at deadorange.com (Nick) Date: Tue, 11 Oct 2011 20:27:00 -0700 (PDT) Subject: [rspec-users] URL helpers in model specs In-Reply-To: References: <3200209.3663.1318266139917.JavaMail.geo-discussion-forums@yqcs10> Message-ID: <14051417.492.1318390020655.JavaMail.geo-discussion-forums@vbkd1> Hey Matt. Thanks for replying. I deleted that gist by accident earlier today. Despite that, the problem's solved by including Rails.application.routes.url_helpers in my model. My Rails console sessions include Rails.application.routes.url_helpers automatically, which is why it worked in IRB but not when run with RSpec. -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Wed Oct 12 01:56:24 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 11 Oct 2011 22:56:24 -0700 (PDT) Subject: [rspec-users] understanding rspec predicates In-Reply-To: <23A3BBAD-3CDC-43B6-8BD4-F1D8FFFDC317@me.com> References: <142999E7-A325-4601-8D22-23CEB0184354@gmail.com> <2C415B3A-E07C-46B3-BFC4-91DC3C276FF0@me.com> <39350D57-00AC-4978-9A5C-2680DBF4329C@gmail.com> <23A3BBAD-3CDC-43B6-8BD4-F1D8FFFDC317@me.com> Message-ID: > > I'd rename it to something like "has_alert_flag?" or "flagged_for_alert?" > > so I could say "model.should have_alert_flag" or "model.should > > be_flagged_for_alert". Ok, for whatever reason I wasn't 100% clear on this.. So the rule is, any predicate method that starts with "has_" can be replaced with "have_", and all others would begin with "be_". Got it.... Thanks! Patrick J. Collins http://collinatorstudios.com From anexiole at gmail.com Wed Oct 12 01:58:48 2011 From: anexiole at gmail.com (Gordon) Date: Tue, 11 Oct 2011 22:58:48 -0700 (PDT) Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) Message-ID: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> Hi all, I am trying to figure out how to use assert_select properly. When I created a new resource in rails 3 called Brands, the view specs for brands had a test which read: # Run the generator again with the --webrat flag if you want to use webrat matchers assert_select "form", :action => brands_path, :method => "post" do assert_select "input#brand_name", :name => "brand[name]" assert_select "input#brand_description", :name => "brand[description]" assert_select "input#brand_created_by", :name => "brand[created_by]" end With my project, I do not want the "created by" attribute to be set from the new.html.erb entry form. I read http://content.labnotes.org/assert_select/assert_select.html and figured I need to use the 'false' equality operator. It also says the following: ---------- extract starts -------------- assert_select(selector, *values, equality?, message?) { |elems| ... } assert_select(element, selector, *values, equality?, message?) { | elems| ... } ---------- extract ends -------------- Alas, my attempts at using it failed. For a spec/statement such as 'assert_select input#brand_created_by", :name => "brand[created_by]', I would think that input#brand_created_by would be the 'element' and the 'selector' combined. Since I need to use the 'false' equality operator, 1) how do i give null to *values? I have tried the following to no success and kept getting syntax errors: a) assert_select "input#brand_created_by", :name => "brand[created_by]", '', false --> spec/views/brands/ new.html.erb_spec.rb:53: syntax error, unexpected ',', expecting tASSOC (SyntaxError) ?me => "brand[created_by]", '', false b) assert_select "input#brand_created_by", :name => "brand[created_by]", nil, false --> spec/views/brands/new.html.erb_spec.rb:53: syntax error, unexpected ',', expecting tASSOC (SyntaxError) ...me => "brand[created_by]", nil, false c) assert_select "input#brand_created_by", :name => "brand[created_by]", , false --> spec/views/brands/ new.html.erb_spec.rb:53: syntax error, unexpected ',', expecting keyword_end (SyntaxError) ...:name => "brand[created_by]", , false It looks as if any attempts I make to denote that I have no 'values' to give to it is not working. Can someone please tell me what the right syntax is for saying, "i expect not to see the brand[created_by]" input attribute at all in the rendered form for adding new entries? Thank you :) Gordon From dchelimsky at gmail.com Wed Oct 12 07:20:44 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Oct 2011 06:20:44 -0500 Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) In-Reply-To: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> References: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> Message-ID: <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> On Oct 12, 2011, at 12:58 AM, Gordon wrote: > Hi all, > > I am trying to figure out how to use assert_select properly. > > When I created a new resource in rails 3 called Brands, the view specs for brands had a test which read: > > # Run the generator again with the --webrat flag if you want to > use webrat matchers > assert_select "form", :action => brands_path, :method => "post" do > assert_select "input#brand_name", :name => "brand[name]" > assert_select "input#brand_description", :name => > "brand[description]" > assert_select "input#brand_created_by", :name => > "brand[created_by]" > end > > > With my project, I do not want the "created by" attribute to be set from the new.html.erb entry form. > > I read http://content.labnotes.org/assert_select/assert_select.html and figured I need to use the 'false' equality operator. That's old. Check out http://api.rubyonrails.org/classes/ActionDispatch/Assertions/SelectorAssertions.html#method-i-assert_select for the latest. > Alas, my attempts at using it failed. > > For a spec/statement such as 'assert_select > input#brand_created_by", :name => "brand[created_by]', > I would think that input#brand_created_by would be the 'element' and > the 'selector' combined. Correct. > a) assert_select "input#brand_created_by", :name => > "brand[created_by]", '', false --> spec/views/brands/ > new.html.erb_spec.rb:53: syntax error, unexpected ',', expecting > tASSOC (SyntaxError) ?me => "brand[created_by]", '', false This is a problem with Ruby argument ordering working against the expressiveness you're looking for. Keyword arguments have to come last. So you can say: do_something 1, 2, :a, thing, :b => 3 but you can't say do_something 1, :a, thing, :b => 3, 2 What _will_ work is this: assert_select "input#brand_created_by", false This leaves out the :name argument, but you don't need it IMO. If you really want it, you'd have to do this: assert_select "input#brand_created_by", false, :name => "brand[created_by]" But that feels really awkward to me, since the negative assertion is expressed in the middle of the argument list > Can someone please tell me what the right syntax is for saying, "i > expect not to see the brand[created_by]" input attribute at all in the > rendered form for adding new entries? rendered.should_not have_selector("input#brand_created_by") # ;) You need Capybara for that, of course, but I think it's easier to grok than: assert_select "input#brand_created_by", false HTH, David From anexiole at gmail.com Wed Oct 12 07:53:51 2011 From: anexiole at gmail.com (Gordon Yeong) Date: Wed, 12 Oct 2011 22:53:51 +1100 Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) In-Reply-To: <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> References: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> Message-ID: > > What _will_ work is this: > > assert_select "input#brand_created_by", false > > Hmmm. Sadly it does not work :( See below: ---------------- extract start ------------------------- Failure/Error: assert_select "input#brand_created_by", false, :name => "brand[created_by]" ArgumentError: assertion message must be String or Proc, but Hash was given. # (eval):2:in `assert' # ./spec/views/brands/new.html.erb_spec.rb:37:in `block (3 levels) in ' # ./spec/views/brands/new.html.erb_spec.rb:34:in `block (2 levels) in From dchelimsky at gmail.com Wed Oct 12 10:34:20 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Oct 2011 09:34:20 -0500 Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) In-Reply-To: References: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> Message-ID: <72998C63-A7AF-4A7D-8CDB-47E1710E08B4@gmail.com> On Oct 12, 2011, at 6:53 AM, Gordon Yeong wrote: > What _will_ work is this: > > assert_select "input#brand_created_by", false This ^^ does not include :name => "..." > > > Hmmm. Sadly it does not work :( See below: > > ---------------- extract start ------------------------- > > Failure/Error: assert_select "input#brand_created_by", false, :name => "brand[created_by]" This ^^ does include :name => "....". What happens when you just run assert_select "input#brand_created_by", false -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathanvda at gmail.com Wed Oct 12 15:09:41 2011 From: nathanvda at gmail.com (nathanvda) Date: Wed, 12 Oct 2011 12:09:41 -0700 (PDT) Subject: [rspec-users] Attempting to speed up my controller specs: using before all fails? In-Reply-To: References: Message-ID: <3ac2b076-c923-44a5-8b83-8a020e84f501@b6g2000vbz.googlegroups.com> Nobody? On Oct 11, 1:05?pm, nathanvda wrote: > I have a simple controller test, containing a.o. the following code: > > ? ? context "POST :create" do > ? ? ? before (:each) do > ? ? ? ? post :create, :user_id => @user.id, > ? ? ? ? ? ? ?:account => { .. some data ... } > ? ? ? end > ? ? ? it { response.status.should == 201 } > ? ? ? it { response.location.should be_present } > ? ? end > > Now I thought of a very simple way to speed up this test, and to use a > `before(:all)` instead of a `before(:each)`. In that case the POST > would only be done once. > > So i wrote: > > ? ? context "POST :create" do > ? ? ? before (:all) do > ? ? ? ? post :create, :user_id => @user.id, > ? ? ? ? ? ? ?:account => { .. some data ... } > ? ? ? end > ? ? ? it { response.status.should == 201 } > ? ? ? it { response.location.should be_present } > ? ? end > > But then I get the following errors: > > ? ? ?RuntimeError: > ? ? ? ?@routes is nil: make sure you set it in your test's setup > method. > > Is this by design? Is there a way to circumvent it? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Oct 12 17:14:32 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Oct 2011 16:14:32 -0500 Subject: [rspec-users] Attempting to speed up my controller specs: using before all fails? In-Reply-To: <3ac2b076-c923-44a5-8b83-8a020e84f501@b6g2000vbz.googlegroups.com> References: <3ac2b076-c923-44a5-8b83-8a020e84f501@b6g2000vbz.googlegroups.com> Message-ID: <68F56DB7-490A-491D-8237-92459A2D3A9A@gmail.com> On Oct 12, 2011, at 2:09 PM, nathanvda wrote: > Nobody? > > On Oct 11, 1:05 pm, nathanvda wrote: >> I have a simple controller test, containing a.o. the following code: >> >> context "POST :create" do >> before (:each) do >> post :create, :user_id => @user.id, >> :account => { .. some data ... } >> end >> it { response.status.should == 201 } >> it { response.location.should be_present } >> end >> >> Now I thought of a very simple way to speed up this test, and to use a >> `before(:all)` instead of a `before(:each)`. In that case the POST >> would only be done once. >> >> So i wrote: >> >> context "POST :create" do >> before (:all) do >> post :create, :user_id => @user.id, >> :account => { .. some data ... } >> end >> it { response.status.should == 201 } >> it { response.location.should be_present } >> end >> >> But then I get the following errors: >> >> RuntimeError: >> @routes is nil: make sure you set it in your test's setup >> method. >> >> Is this by design? Yes. rspec-rails wraps the rails' testing framework which doesn't have a before(:all) concept in it, so all the data is reset before each example. Even if we wanted to support this in rspec-rails (which I don't) it would require changes to rails first. >> Is there a way to circumvent it? Not really. I'd just stick them in a single example: describe "POST create" do it "responds with a 201 and a location" do post :create, :user_id => @user.id, :account => { .. some data ... } response.status.should eq(201) response.location.should be_present end end This violates the "one expectation per example" guideline, but a) that's just a guideline, and b) the real benefit of following the guideline is that it tends to limit you to one event per example (which is a GOOD thing). If that event has multiple outcomes to check, however, I see little benefit in this guideline. HTH, David From srshti at gmail.com Wed Oct 12 17:16:31 2011 From: srshti at gmail.com (Srushti) Date: Wed, 12 Oct 2011 14:16:31 -0700 Subject: [rspec-users] Attempting to speed up my controller specs: using before all fails? In-Reply-To: <3ac2b076-c923-44a5-8b83-8a020e84f501@b6g2000vbz.googlegroups.com> References: <3ac2b076-c923-44a5-8b83-8a020e84f501@b6g2000vbz.googlegroups.com> Message-ID: On 12 October 2011 12:09, nathanvda wrote: > Nobody? > > On Oct 11, 1:05 pm, nathanvda wrote: > > I have a simple controller test, containing a.o. the following code: > > > > context "POST :create" do > > before (:each) do > > post :create, :user_id => @user.id, > > :account => { .. some data ... } > > end > > it { response.status.should == 201 } > > it { response.location.should be_present } > > end > > > > Now I thought of a very simple way to speed up this test, and to use a > > `before(:all)` instead of a `before(:each)`. In that case the POST > > would only be done once. > > > > So i wrote: > > > > context "POST :create" do > > before (:all) do > > post :create, :user_id => @user.id, > > :account => { .. some data ... } > > end > > it { response.status.should == 201 } > > it { response.location.should be_present } > > end > > > > But then I get the following errors: > > > > RuntimeError: > > @routes is nil: make sure you set it in your test's setup > > method. > > > > Is this by design? Is there a way to circumvent it? > > _______________________________________________ > > 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 > I'm afraid I can't help with your specific situation, except to say I've faced weird issues like this with "before(:all)" in the past, and have generally tried to stay away from it these days. Also, the largest amount of time is generally involved in actually loading up rails itself. Can you confirm that there's a significant amount of time taken to execute your controller action? Srushti http://c42.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From patmaddox at me.com Wed Oct 12 17:38:27 2011 From: patmaddox at me.com (Pat Maddox) Date: Wed, 12 Oct 2011 14:38:27 -0700 Subject: [rspec-users] Attempting to speed up my controller specs: using before all fails? In-Reply-To: <3ac2b076-c923-44a5-8b83-8a020e84f501@b6g2000vbz.googlegroups.com> References: <3ac2b076-c923-44a5-8b83-8a020e84f501@b6g2000vbz.googlegroups.com> Message-ID: <41E9CA3A-EF0D-4C15-B2F7-B4B8C08DC1CF@me.com> Yes it's by design, no you cannot circumvent it. What you can do is use mocks to avoid expensive DB hits, or have multiple expectations in a single example. Pat p.s. This is Ruby, so you absolutely *can* circumvent it. How to do that and whether it's worth the trouble is up to you to figure out. On Oct 12, 2011, at 12:09 PM, nathanvda wrote: > Nobody? > > On Oct 11, 1:05 pm, nathanvda wrote: >> I have a simple controller test, containing a.o. the following code: >> >> context "POST :create" do >> before (:each) do >> post :create, :user_id => @user.id, >> :account => { .. some data ... } >> end >> it { response.status.should == 201 } >> it { response.location.should be_present } >> end >> >> Now I thought of a very simple way to speed up this test, and to use a >> `before(:all)` instead of a `before(:each)`. In that case the POST >> would only be done once. >> >> So i wrote: >> >> context "POST :create" do >> before (:all) do >> post :create, :user_id => @user.id, >> :account => { .. some data ... } >> end >> it { response.status.should == 201 } >> it { response.location.should be_present } >> end >> >> But then I get the following errors: >> >> RuntimeError: >> @routes is nil: make sure you set it in your test's setup >> method. >> >> Is this by design? Is there a way to circumvent it? >> _______________________________________________ >> 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 patrick at collinatorstudios.com Wed Oct 12 19:59:44 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 12 Oct 2011 16:59:44 -0700 (PDT) Subject: [rspec-users] instance variables from outer before blocks don't persist? Message-ID: Hmmm.. I am used to doing this with Test::Unit & Shoulda.. setup do @foo = Bar.new end context "something" setup do @foo.blah = 123 end should "make me say lol" do # ...etc end end ... But I just tried doing this in RSpec with before :each, and it seems that my @foo ivar is non existant inside the inner context...... Is this the way it's supposed to be? Patrick J. Collins http://collinatorstudios.com From patmaddox at me.com Wed Oct 12 21:50:08 2011 From: patmaddox at me.com (Pat Maddox) Date: Wed, 12 Oct 2011 18:50:08 -0700 Subject: [rspec-users] instance variables from outer before blocks don't persist? In-Reply-To: References: Message-ID: <11A8BD8B-C7F1-4952-9615-301E3F7E328B@me.com> On Oct 12, 2011, at 4:59 PM, Patrick J. Collins wrote: > ... But I just tried doing this in RSpec with before :each, and it seems that > my @foo ivar is non existant inside the inner context...... Is this the way > it's supposed to be? post the whole example From anexiole at gmail.com Thu Oct 13 05:40:22 2011 From: anexiole at gmail.com (Gordon Yeong) Date: Thu, 13 Oct 2011 20:40:22 +1100 Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) In-Reply-To: <72998C63-A7AF-4A7D-8CDB-47E1710E08B4@gmail.com> References: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> <72998C63-A7AF-4A7D-8CDB-47E1710E08B4@gmail.com> Message-ID: > > > This ^^ does include :name => "....". > > What happens when you just run > > assert_select "input#brand_created_by", false > > this runs successfully but how do I do it with the :name? :( I just want to be complete and explicit :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ash.moran at patchspace.co.uk Thu Oct 13 06:05:37 2011 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Thu, 13 Oct 2011 11:05:37 +0100 Subject: [rspec-users] rspec 2.7.0.rc1 is released! In-Reply-To: <5B592195-0844-48D8-AD6F-7045F2ABA58B@gmail.com> References: <5FF64527-657A-4F67-86A8-ECD9DC47AD60@gmail.com> <61683929-2C97-48A6-8756-49540E83BC1B@patchspace.co.uk> <5B592195-0844-48D8-AD6F-7045F2ABA58B@gmail.com> Message-ID: On 10 Oct 2011, at 15:22, David Chelimsky wrote: > Nope. Wanna add one? > > The basic idea is: > > shared_examples Enumerable do Aye, that's what I figured :-) I've wished for that for a long time. I'm away for a bit but I'll see if I get chance soon. Ash -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From dchelimsky at gmail.com Thu Oct 13 07:39:18 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Oct 2011 06:39:18 -0500 Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) In-Reply-To: References: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> <72998C63-A7AF-4A7D-8CDB-47E1710E08B4@gmail.com> Message-ID: <6D404312-1E3E-48EF-BD86-2AB5622CBE57@gmail.com> On Oct 13, 2011, at 4:40 AM, Gordon Yeong wrote: > > This ^^ does include :name => "....". > > What happens when you just run > > assert_select "input#brand_created_by", false > > this runs successfully but how do I do it with the :name? :( I just want to be complete and explicit :) I don't know if you can. Maybe somebody on the Rails list knows. http://groups.google.com/group/rubyonrails-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From alex at stinky.com Thu Oct 13 15:52:00 2011 From: alex at stinky.com (Alex Chaffee) Date: Thu, 13 Oct 2011 12:52:00 -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: FYI, I've just released Wrong 0.6.0 with eventually "as is" -- i.e. no extra exception message fiddling. I also added a message param to Wrong's "d" method, e.g. d("math is hard") { 2 + 2 } prints math is hard: (2 + 2) is 4 to the console. Useful for debugging (which is what "d" stands for) when you don't want the test flow to stop with an assert or should. - A -- Alex Chaffee - alex at stinky.com http://alexchaffee.com http://twitter.com/alexch On Sun, Oct 2, 2011 at 2:02 PM, Matt Wynne wrote: > > On 28 Sep 2011, at 01:09, Alex Chaffee wrote: > >> 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... > > I haven't used it, but this looks good to me. > >> >> -- >> Alex Chaffee - alex at stinky.com >> http://alexchaffee.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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From patrick at collinatorstudios.com Thu Oct 13 20:47:36 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Thu, 13 Oct 2011 17:47:36 -0700 (PDT) Subject: [rspec-users] instance variables from outer before blocks don't persist? In-Reply-To: <11A8BD8B-C7F1-4952-9615-301E3F7E328B@me.com> References: <11A8BD8B-C7F1-4952-9615-301E3F7E328B@me.com> Message-ID: > > ... But I just tried doing this in RSpec with before :each, and it seems that > > my @foo ivar is non existant inside the inner context...... Is this the way > > it's supposed to be? > > post the whole example Nevermind.. I figured out what I was doing wrong. Patrick J. Collins http://collinatorstudios.com From anexiole at gmail.com Thu Oct 13 21:35:39 2011 From: anexiole at gmail.com (Gordon) Date: Thu, 13 Oct 2011 18:35:39 -0700 (PDT) Subject: [rspec-users] Scope problems for before hooks using helper methods? Message-ID: Hi, there, I believe I have some problem with scoping. I have a controller spec file which tests a brands resource. At the start of the file, I test the resource's access for different users in a context block a) not signed in b) non-admin user signed in- I call my own helper method, login_user c) admin user signed in - I call my own helper method, login_admin_user Specs there do pass successfully. I then create another context block to just test the resource for an admin user that's signed in. I tried calling login_admin_user in a before hook as per the previous specs . It fails and I suspect that the current scope within the before hook does not see my custom helper method, login_admin_user. Here is the error message: --------- Extract start ----------------- /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `load': /Users/anexiole/projects/ try_rails/spec/controllers/brands_controller_spec.rb:164: syntax error, unexpected keyword_end, expecting $end (SyntaxError) from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `block in load' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:227:in `load_dependency' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `load' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/configuration.rb:419:in `block in load_spec_files' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/configuration.rb:419:in `map' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/configuration.rb:419:in `load_spec_files' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/command_line.rb:18:in `run' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/runner.rb:80:in `run_in_process' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/runner.rb:69:in `run' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/runner.rb:11:in `block in autorun' ---------- Extract end ------------------ My specs is as follows: --------- spec/controllers/brands_controller_spec.rb (start) -------------- require 'spec_helper' describe BrandsController do # This should return the minimal set of attributes required to create a valid # Brand. As you add validations to Brand, be sure to # update the return value of this method accordingly. def valid_attributes { 'name' => 'J Speed', 'description' => 'From gunsai province' } end context 'checking access for varying users' do describe 'brands access is not available to users who have not signed in' do it 'users that are not logged in will be sent to the sign in page' do get :index response.should redirect_to(new_user_session_path) end end describe 'brands access is not available to regular users' do login_user it 'regular users that are logged in will be sent to home page' do get :index response.should redirect_to(root_path) end end describe 'brands access is available only to admin users' do login_admin_user it 'admin users that are logged in can access the index page' do get :index response.should render_template('index') end end end context 'with an admin user signed in' do # <----- starts failing in this context before(:each) do login_admin_user end describe "creates a new brand entry" do it "assigns a new brand as @brand" do get :new assigns(:brand).should be_a_new(Brand) end end end end --------- spec/controllers/brands_controller_spec.rb (end) -------------- What am I doing wrong? From anexiole at gmail.com Thu Oct 13 21:56:10 2011 From: anexiole at gmail.com (Gordon) Date: Thu, 13 Oct 2011 18:56:10 -0700 (PDT) Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) In-Reply-To: <6D404312-1E3E-48EF-BD86-2AB5622CBE57@gmail.com> References: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> <72998C63-A7AF-4A7D-8CDB-47E1710E08B4@gmail.com> <6D404312-1E3E-48EF-BD86-2AB5622CBE57@gmail.com> Message-ID: > > I don't know if you can. Maybe somebody on the Rails list knows. If it can't, it means that people can't use assert_select to expect NOT to find a given element with extra attributes (such as :name) being defined. If that's the case, i think assert_select was either poorly written OR not completed yet. It's like saying that "if" conditional works but "if not" only works to a simple extend only :( I am sure it can be done. Can someone please show us how? From jko170 at gmail.com Thu Oct 13 22:51:47 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 13 Oct 2011 20:51:47 -0600 Subject: [rspec-users] Scope problems for before hooks using helper methods? In-Reply-To: References: Message-ID: <3DC6CB62-8FE5-4A63-9D7C-0814C2F623DB@gmail.com> On Oct 13, 2011, at 7:35 PM, Gordon wrote: > > > Hi, there, > > > I believe I have some problem with scoping. > > I have a controller spec file which tests a brands resource. > At the start of the file, I test the resource's access for different > users in a context block > a) not signed in > b) non-admin user signed in- I call my own helper method, login_user > c) admin user signed in - I call my own helper method, > login_admin_user > Specs there do pass successfully. > > I then create another context block to just test the resource for an > admin user that's signed in. > I tried calling login_admin_user in a before hook as per the previous > specs . > > It fails and I suspect that the current scope within the before hook > does not see my custom helper method, login_admin_user. > Here is the error message: > --------- Extract start ----------------- > > /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `load': /Users/anexiole/projects/ > try_rails/spec/controllers/brands_controller_spec.rb:164: syntax > error, unexpected keyword_end, expecting $end (SyntaxError) > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `block in load' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:227:in `load_dependency' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `load' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/configuration.rb:419:in `block in load_spec_files' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/configuration.rb:419:in `map' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/configuration.rb:419:in `load_spec_files' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/command_line.rb:18:in `run' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/runner.rb:80:in `run_in_process' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/runner.rb:69:in `run' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/runner.rb:11:in `block in autorun' > ---------- Extract end ------------------ > > > My specs is as follows: > > --------- spec/controllers/brands_controller_spec.rb (start) > -------------- > > > require 'spec_helper' > > describe BrandsController do > > # This should return the minimal set of attributes required to > create a valid > # Brand. As you add validations to Brand, be sure to > # update the return value of this method accordingly. > def valid_attributes > { > 'name' => 'J Speed', > 'description' => 'From gunsai province' > } > end > > > context 'checking access for varying users' do > describe 'brands access is not available to users who have not > signed in' do > it 'users that are not logged in will be sent to the sign > in page' do > get :index > response.should redirect_to(new_user_session_path) > end > end > > describe 'brands access is not available to regular users' do > login_user > > it 'regular users that are logged in will be sent to home > page' do > get :index > response.should redirect_to(root_path) > end > end > > describe 'brands access is available only to admin users' do > login_admin_user > > it 'admin users that are logged in can access the index > page' do > get :index > response.should render_template('index') > end > end > end > > context 'with an admin user signed in' do # <----- starts > failing in this context > before(:each) do > login_admin_user > end > > describe "creates a new brand entry" do > it "assigns a new brand as @brand" do > get :new > assigns(:brand).should be_a_new(Brand) > end > end > end > end > > --------- spec/controllers/brands_controller_spec.rb (end) > -------------- > > What am I doing wrong? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Let's see the helper method please. From anexiole at gmail.com Thu Oct 13 22:59:36 2011 From: anexiole at gmail.com (Gordon) Date: Thu, 13 Oct 2011 19:59:36 -0700 (PDT) Subject: [rspec-users] Helper methods can't be called within before hooks. Help, please. Message-ID: <12d57043-21c6-4a69-89ff-50dbb14c4e8d@v15g2000vbm.googlegroups.com> Hi, there, I believe I have some problem with scoping. I have a controller spec file which tests a brands resource. At the start of the file, I test the resource's access for different users in a context block a) not signed in b) non-admin user signed in- I call my own helper method, login_user c) admin user signed in - I call my own helper method, login_admin_user Specs there do pass successfully. I then create another context block to just test the resource for an admin user that's signed in. I tried calling login_admin_user in a before hook as per the previous specs . It fails and I suspect that the current scope within the before hook does not see my custom helper method, login_admin_user. Here is the error message: --------- Extract start ----------------- /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `load': /Users/anexiole/ projects/ try_rails/spec/controllers/brands_controller_spec.rb:164: syntax error, unexpected keyword_end, expecting $end (SyntaxError) from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `block in load' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ activesupport-3.0.9/lib/ active_support/dependencies.rb:227:in `load_dependency' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `load' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ lib/ rspec/core/configuration.rb:419:in `block in load_spec_files' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ lib/ rspec/core/configuration.rb:419:in `map' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ lib/ rspec/core/configuration.rb:419:in `load_spec_files' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ lib/ rspec/core/command_line.rb:18:in `run' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ lib/ rspec/core/runner.rb:80:in `run_in_process' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ lib/ rspec/core/runner.rb:69:in `run' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ lib/ rspec/core/runner.rb:11:in `block in autorun' ---------- Extract end ------------------ My specs is as follows: --------- spec/controllers/brands_controller_spec.rb (start) -------------- require 'spec_helper' describe BrandsController do # This should return the minimal set of attributes required to create a valid # Brand. As you add validations to Brand, be sure to # update the return value of this method accordingly. def valid_attributes { 'name' => 'J Speed', 'description' => 'From gunsai province' } end context 'checking access for varying users' do describe 'brands access is not available to users who have not signed in' do it 'users that are not logged in will be sent to the sign in page' do get :index response.should redirect_to(new_user_session_path) end end describe 'brands access is not available to regular users' do login_user it 'regular users that are logged in will be sent to home page' do get :index response.should redirect_to(root_path) end end describe 'brands access is available only to admin users' do login_admin_user it 'admin users that are logged in can access the index page' do get :index response.should render_template('index') end end end context 'with an admin user signed in' do # <----- starts failing in this context before(:each) do login_admin_user end describe "creates a new brand entry" do it "assigns a new brand as @brand" do get :new assigns(:brand).should be_a_new(Brand) end end end end --------- spec/controllers/brands_controller_spec.rb (end) -------------- What am I doing wrong? From mikerin.slava at gmail.com Thu Oct 13 23:43:26 2011 From: mikerin.slava at gmail.com (slavix) Date: Thu, 13 Oct 2011 20:43:26 -0700 (PDT) Subject: [rspec-users] running rspec causes errror => no such file to load -- rspec/rails Message-ID: <21f1006a-a4fd-4ef7-95b3-c9797e3b9a62@k2g2000yqh.googlegroups.com> strange install related problems in my rails 3.1 app gemfile group :test, :development do .. gem "rspec" gem "rspec-rails" gem 'rspec-rails-ext' gem 'rspec-rails-matchers' .. end >>bundle show rspec-rails /home/slava/.rvm/gems/ruby-1.9.2-p290/gems/rspec-rails-1.3.2 >>rails generate rspec:install Could not find generator rspec:install. spec_helper file i created manually ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'remarkable/active_record' Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } RSpec.configure do |config| config.mock_with :rspec config.use_transactional_fixtures = true end RSpec::Matchers.define :have_valid_factory do |factory_name| match do |model| Factory(factory_name).new_record?.should be_false end end Trying to run rspec on my models I get loading error for rspec-rails and rspec generator seems missing.. From jko170 at gmail.com Fri Oct 14 00:17:24 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 13 Oct 2011 22:17:24 -0600 Subject: [rspec-users] running rspec causes errror => no such file to load -- rspec/rails In-Reply-To: <21f1006a-a4fd-4ef7-95b3-c9797e3b9a62@k2g2000yqh.googlegroups.com> References: <21f1006a-a4fd-4ef7-95b3-c9797e3b9a62@k2g2000yqh.googlegroups.com> Message-ID: <9759F95C-7299-477E-AD89-3044BE732408@gmail.com> On Oct 13, 2011, at 9:43 PM, slavix wrote: > strange install related problems in my rails 3.1 app > gemfile > group :test, :development do > .. > gem "rspec" > gem "rspec-rails" > gem 'rspec-rails-ext' > gem 'rspec-rails-matchers' > .. > end > >>> bundle show rspec-rails > /home/slava/.rvm/gems/ruby-1.9.2-p290/gems/rspec-rails-1.3.2 You need RSpec 2+, not RSpec 1 (which does not work with Rails 3). > >>> rails generate rspec:install > Could not find generator rspec:install. > > spec_helper file i created manually > > ENV["RAILS_ENV"] ||= 'test' > require File.expand_path("../../config/environment", __FILE__) > require 'rspec/rails' > require 'remarkable/active_record' > > Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } > > > RSpec.configure do |config| > config.mock_with :rspec > config.use_transactional_fixtures = true > end > > RSpec::Matchers.define :have_valid_factory do |factory_name| > match do |model| > Factory(factory_name).new_record?.should be_false > end > end > > Trying to run rspec on my models I get loading error for rspec-rails > and rspec generator seems missing.. > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From anexiole at gmail.com Fri Oct 14 00:40:31 2011 From: anexiole at gmail.com (Gordon) Date: Thu, 13 Oct 2011 21:40:31 -0700 (PDT) Subject: [rspec-users] How do we include support helpers in request specs? Message-ID: <8779978c-4d74-44dd-b4e1-35363e5faf85@o14g2000vbd.googlegroups.com> Hi, all :) I have some working support helpers defined in spec/support/ controller_macros.rb. I'm running "rake spec" before a 'git commit' and observed that the spec request for my 'brands' controller, spec/requests/brands_spec.rb fails because a support helper method I defined in spec/support/controller_macros.rb is not recognised. I got the following error: ----------------- Error extract: start --------------------------- spec/requests/brands_spec.rb:4:in `block in ': undefined local variable or method `login_admin_user' for # (NameError) from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/example_group.rb:142:in `module_eval' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/example_group.rb:142:in `subclass' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/example_group.rb:129:in `describe' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/dsl.rb:5:in `describe' from /Users/anexiole/projects/try_rails/spec/requests/brands_spec.rb: 3:in `' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `load' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `block in load' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:227:in `load_dependency' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:in `load' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/configuration.rb:419:in `block in load_spec_files' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/configuration.rb:419:in `map' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/configuration.rb:419:in `load_spec_files' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/command_line.rb:18:in `run' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/runner.rb:80:in `run_in_process' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/runner.rb:69:in `run' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ rspec/core/runner.rb:11:in `block in autorun' rake aborted! ----------------- Error extract: end --------------------------- I noticed that in the stack, the helper file, spec/support/ controller_macros.rb was never called. My model, view and controller specs all pass. This is what my spec/spec_helper.rb file looks like: ---------- spec/spec_helper.rb start ------------------- ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'webrat' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| # == Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr #: config.mock_with :rspec config.include Devise::TestHelpers, :type => :controller config.extend ControllerMacros, :type => :controller config.before(:suite) do DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) end config.before(:each) do DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean end # # Rspec 2-https://github.com/plataformatec/devise # config.include Devise::TestHelpers, :type => :controller # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. # config.use_transactional_fixtures = true end ---------- spec/spec_helper.rb end ------------------- This is what the failing request spec, spec/request/brands_spec.rb looks like. As this resource will not be available to non-admin users, it will redirect non-admin users to the root url. To have this spec passing, I am calling the method, login_admin_user which uses factory girl to create an admin user object (and sign in). This works without any problems in the controller specs, spec/controller, brands_controller_spec.rb. Strangely, it fails to work here regardless of where I put the call to login_admin_user right after 'describe "Brands" do' or ' describe "GET /brands" do'. ------------ spec/request/brands_spec.rb start ------------------ require 'spec_helper' describe "Brands" do login_admin_user describe "GET /brands" do it "works! (now write some real specs)" do get brands_path response.status.should be(200) end end end ------------ spec/request/brands_spec.rb end ------------------ Can someone please show me how do I ensure that helper methods defined in spec/support get called in spec/request specs? thank you :) From jko170 at gmail.com Fri Oct 14 00:49:56 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 13 Oct 2011 22:49:56 -0600 Subject: [rspec-users] How do we include support helpers in request specs? In-Reply-To: <8779978c-4d74-44dd-b4e1-35363e5faf85@o14g2000vbd.googlegroups.com> References: <8779978c-4d74-44dd-b4e1-35363e5faf85@o14g2000vbd.googlegroups.com> Message-ID: <3195EB7B-D2C0-4884-9D37-193DE1AF5342@gmail.com> On Oct 13, 2011, at 10:40 PM, Gordon wrote: > Hi, all :) > > I have some working support helpers defined in spec/support/ > controller_macros.rb. > > I'm running "rake spec" before a 'git commit' and observed that the > spec request for my 'brands' controller, > spec/requests/brands_spec.rb fails because a support helper method I > defined in spec/support/controller_macros.rb is not > recognised. > > I got the following error: > > ----------------- Error extract: start --------------------------- > > spec/requests/brands_spec.rb:4:in `block in ': > undefined local variable or method `login_admin_user' for # 0x00000103bdf9a8> (NameError) > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/example_group.rb:142:in `module_eval' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/example_group.rb:142:in `subclass' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/example_group.rb:129:in `describe' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/dsl.rb:5:in `describe' > from /Users/anexiole/projects/try_rails/spec/requests/brands_spec.rb: > 3:in `' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `load' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `block in load' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:227:in `load_dependency' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `load' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/configuration.rb:419:in `block in load_spec_files' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/configuration.rb:419:in `map' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/configuration.rb:419:in `load_spec_files' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/command_line.rb:18:in `run' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/runner.rb:80:in `run_in_process' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/runner.rb:69:in `run' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/ > rspec/core/runner.rb:11:in `block in autorun' > rake aborted! > > > ----------------- Error extract: end --------------------------- > > > I noticed that in the stack, the helper file, spec/support/ > controller_macros.rb was never called. > My model, view and controller specs all pass. > > This is what my spec/spec_helper.rb file looks like: > > ---------- spec/spec_helper.rb start ------------------- > > ENV["RAILS_ENV"] ||= 'test' > require File.expand_path("../../config/environment", __FILE__) > require 'rspec/rails' > require 'webrat' > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| > # == Mock Framework > # > # If you prefer to use mocha, flexmock or RR, uncomment the > appropriate line: > # > # config.mock_with :mocha > # config.mock_with :flexmock > # config.mock_with :rr > #: config.mock_with :rspec > config.include Devise::TestHelpers, :type => :controller > config.extend ControllerMacros, :type => :controller :type => :controller will only include it in controller specs. If you want to include them in requests, you need to add this: config.extend ControllerMacros, :type => :requests > > config.before(:suite) do > DatabaseCleaner.strategy = :transaction > DatabaseCleaner.clean_with(:truncation) > end > > config.before(:each) do > DatabaseCleaner.start > end > > config.after(:each) do > DatabaseCleaner.clean > end > > # # Rspec 2-https://github.com/plataformatec/devise > # config.include Devise::TestHelpers, :type => :controller > > # Remove this line if you're not using ActiveRecord or ActiveRecord > fixtures > # config.fixture_path = "#{::Rails.root}/spec/fixtures" > > # If you're not using ActiveRecord, or you'd prefer not to run each > of your > # examples within a transaction, remove the following line or assign > false > # instead of true. > # config.use_transactional_fixtures = true > > end > > ---------- spec/spec_helper.rb end ------------------- > > > This is what the failing request spec, spec/request/brands_spec.rb > looks like. As this resource will not be available to non-admin users, > it will redirect non-admin users to the root url. To have this spec > passing, I am calling the method, login_admin_user which uses factory > girl to create an admin user object (and sign in). This works without > any problems in the controller specs, spec/controller, > brands_controller_spec.rb. Strangely, it fails to work here regardless > of where I put the call to login_admin_user right after 'describe > "Brands" do' or ' describe "GET /brands" do'. > > ------------ spec/request/brands_spec.rb start ------------------ > require 'spec_helper' > > describe "Brands" do > login_admin_user > > describe "GET /brands" do > it "works! (now write some real specs)" do > get brands_path > response.status.should be(200) > end > end > end > > ------------ spec/request/brands_spec.rb end ------------------ > > > Can someone please show me how do I ensure that helper methods defined > in spec/support get called in spec/request specs? > > thank you :) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jko170 at gmail.com Fri Oct 14 01:01:05 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 13 Oct 2011 23:01:05 -0600 Subject: [rspec-users] Helper methods can't be called within before hooks. Help, please. In-Reply-To: <12d57043-21c6-4a69-89ff-50dbb14c4e8d@v15g2000vbm.googlegroups.com> References: <12d57043-21c6-4a69-89ff-50dbb14c4e8d@v15g2000vbm.googlegroups.com> Message-ID: On Oct 13, 2011, at 8:59 PM, Gordon wrote: > > > Hi, there, > > > I believe I have some problem with scoping. > > I have a controller spec file which tests a brands resource. > At the start of the file, I test the resource's access for different > users in a context block > a) not signed in > b) non-admin user signed in- I call my own helper method, login_user > c) admin user signed in - I call my own helper method, > login_admin_user > Specs there do pass successfully. > > I then create another context block to just test the resource for an > admin user that's signed in. > I tried calling login_admin_user in a before hook as per the previous > specs . > > It fails and I suspect that the current scope within the before hook > does not see my custom helper method, login_admin_user. > Here is the error message: > --------- Extract start ----------------- > > /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `load': /Users/anexiole/ > projects/ > try_rails/spec/controllers/brands_controller_spec.rb:164: syntax > error, unexpected keyword_end, expecting $end (SyntaxError) > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ > activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `block in load' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ > activesupport-3.0.9/lib/ > active_support/dependencies.rb:227:in `load_dependency' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ > activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `load' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > lib/ > rspec/core/configuration.rb:419:in `block in load_spec_files' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > lib/ > rspec/core/configuration.rb:419:in `map' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > lib/ > rspec/core/configuration.rb:419:in `load_spec_files' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > lib/ > rspec/core/command_line.rb:18:in `run' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > lib/ > rspec/core/runner.rb:80:in `run_in_process' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > lib/ > rspec/core/runner.rb:69:in `run' > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > lib/ > rspec/core/runner.rb:11:in `block in autorun' > ---------- Extract end ------------------ > > > My specs is as follows: > > --------- spec/controllers/brands_controller_spec.rb (start) > -------------- > > > require 'spec_helper' > > describe BrandsController do > > # This should return the minimal set of attributes required to > create a valid > # Brand. As you add validations to Brand, be sure to > # update the return value of this method accordingly. > def valid_attributes > { > 'name' => 'J Speed', > 'description' => 'From gunsai province' > } > end > > > context 'checking access for varying users' do > describe 'brands access is not available to users who have not > signed in' do > it 'users that are not logged in will be sent to the sign > in page' do > get :index > response.should redirect_to(new_user_session_path) > end > end > > describe 'brands access is not available to regular users' do > login_user > > it 'regular users that are logged in will be sent to home > page' do > get :index > response.should redirect_to(root_path) > end > end > > describe 'brands access is available only to admin users' do > login_admin_user > > it 'admin users that are logged in can access the index > page' do > get :index > response.should render_template('index') > end > end > end > > context 'with an admin user signed in' do # <----- starts > failing in this context > before(:each) do > login_admin_user > end > > describe "creates a new brand entry" do > it "assigns a new brand as @brand" do > get :new > assigns(:brand).should be_a_new(Brand) > end > end > end > end > > --------- spec/controllers/brands_controller_spec.rb (end) > -------------- > > What am I doing wrong? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users WARNING: Posting duplicates (with a different subject) will get you banned. From anexiole at gmail.com Fri Oct 14 01:01:19 2011 From: anexiole at gmail.com (Gordon) Date: Thu, 13 Oct 2011 22:01:19 -0700 (PDT) Subject: [rspec-users] Scope problems for before hooks using helper methods? In-Reply-To: <3DC6CB62-8FE5-4A63-9D7C-0814C2F623DB@gmail.com> References: <3DC6CB62-8FE5-4A63-9D7C-0814C2F623DB@gmail.com> Message-ID: <21047a14-f42a-446c-9134-ace2942a4304@a25g2000yqi.googlegroups.com> > Let's see the helper method please. ---------------spec/support/controller_macros.rb: start ---------- module ControllerMacros include Devise::TestHelpers # sets up an instance of a non-admin user def login_user before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] @user = FactoryGirl.create(:user) sign_in @user end end # sets up an instance of a admin user def login_admin_user before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] @admin_user = FactoryGirl.create(:admin) sign_in @admin_user end end end ---------------spec/support/controller_macros.rb: end ---------- It works for my existing controller specs and it's based on https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3-(and-rspec) From anexiole at gmail.com Fri Oct 14 03:10:57 2011 From: anexiole at gmail.com (Gordon Yeong) Date: Fri, 14 Oct 2011 18:10:57 +1100 Subject: [rspec-users] Helper methods can't be called within before hooks. Help, please. In-Reply-To: References: <12d57043-21c6-4a69-89ff-50dbb14c4e8d@v15g2000vbm.googlegroups.com> Message-ID: It's just that I did not find my reply surface after 20 mins and was wondering if it was lost. Sorry about that, everyone :( my apologies. On 14 October 2011 16:01, Justin Ko wrote: > > On Oct 13, 2011, at 8:59 PM, Gordon wrote: > > > > > > > Hi, there, > > > > > > I believe I have some problem with scoping. > > > > I have a controller spec file which tests a brands resource. > > At the start of the file, I test the resource's access for different > > users in a context block > > a) not signed in > > b) non-admin user signed in- I call my own helper method, login_user > > c) admin user signed in - I call my own helper method, > > login_admin_user > > Specs there do pass successfully. > > > > I then create another context block to just test the resource for an > > admin user that's signed in. > > I tried calling login_admin_user in a before hook as per the previous > > specs . > > > > It fails and I suspect that the current scope within the before hook > > does not see my custom helper method, login_admin_user. > > Here is the error message: > > --------- Extract start ----------------- > > > > /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > > active_support/dependencies.rb:235:in `load': /Users/anexiole/ > > projects/ > > try_rails/spec/controllers/brands_controller_spec.rb:164: syntax > > error, unexpected keyword_end, expecting $end (SyntaxError) > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ > > activesupport-3.0.9/lib/ > > active_support/dependencies.rb:235:in `block in load' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ > > activesupport-3.0.9/lib/ > > active_support/dependencies.rb:227:in `load_dependency' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/ > > activesupport-3.0.9/lib/ > > active_support/dependencies.rb:235:in `load' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > > lib/ > > rspec/core/configuration.rb:419:in `block in load_spec_files' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > > lib/ > > rspec/core/configuration.rb:419:in `map' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > > lib/ > > rspec/core/configuration.rb:419:in `load_spec_files' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > > lib/ > > rspec/core/command_line.rb:18:in `run' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > > lib/ > > rspec/core/runner.rb:80:in `run_in_process' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > > lib/ > > rspec/core/runner.rb:69:in `run' > > from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/ > > lib/ > > rspec/core/runner.rb:11:in `block in autorun' > > ---------- Extract end ------------------ > > > > > > My specs is as follows: > > > > --------- spec/controllers/brands_controller_spec.rb (start) > > -------------- > > > > > > require 'spec_helper' > > > > describe BrandsController do > > > > # This should return the minimal set of attributes required to > > create a valid > > # Brand. As you add validations to Brand, be sure to > > # update the return value of this method accordingly. > > def valid_attributes > > { > > 'name' => 'J Speed', > > 'description' => 'From gunsai province' > > } > > end > > > > > > context 'checking access for varying users' do > > describe 'brands access is not available to users who have not > > signed in' do > > it 'users that are not logged in will be sent to the sign > > in page' do > > get :index > > response.should redirect_to(new_user_session_path) > > end > > end > > > > describe 'brands access is not available to regular users' do > > login_user > > > > it 'regular users that are logged in will be sent to home > > page' do > > get :index > > response.should redirect_to(root_path) > > end > > end > > > > describe 'brands access is available only to admin users' do > > login_admin_user > > > > it 'admin users that are logged in can access the index > > page' do > > get :index > > response.should render_template('index') > > end > > end > > end > > > > context 'with an admin user signed in' do # <----- starts > > failing in this context > > before(:each) do > > login_admin_user > > end > > > > describe "creates a new brand entry" do > > it "assigns a new brand as @brand" do > > get :new > > assigns(:brand).should be_a_new(Brand) > > end > > end > > end > > end > > > > --------- spec/controllers/brands_controller_spec.rb (end) > > -------------- > > > > What am I doing wrong? > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > WARNING: Posting duplicates (with a different subject) will get you banned. > > _______________________________________________ > 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 evgeni.dzhelyov at gmail.com Fri Oct 14 04:34:12 2011 From: evgeni.dzhelyov at gmail.com (Evgeni Dzhelyov) Date: Fri, 14 Oct 2011 11:34:12 +0300 Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) In-Reply-To: References: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> <72998C63-A7AF-4A7D-8CDB-47E1710E08B4@gmail.com> <6D404312-1E3E-48EF-BD86-2AB5622CBE57@gmail.com> Message-ID: See this https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/assertions/selector.rb#L186 seems the syntax is "[name=...]" From dchelimsky at gmail.com Fri Oct 14 08:26:10 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Oct 2011 07:26:10 -0500 Subject: [rspec-users] assert_select - to do negative tests - need help with syntax please :) In-Reply-To: References: <86b31da3-a125-4cf3-a28c-fda66a9ab9b4@u4g2000prl.googlegroups.com> <735CD4A8-0F32-4961-893D-0A5E81E72D20@gmail.com> <72998C63-A7AF-4A7D-8CDB-47E1710E08B4@gmail.com> <6D404312-1E3E-48EF-BD86-2AB5622CBE57@gmail.com> Message-ID: On Oct 13, 2011, at 8:56 PM, Gordon wrote: >> I don't know if you can. Maybe somebody on the Rails list knows. > > If it can't, it means that people can't use assert_select to expect > NOT to find a given element with extra attributes (such as :name) > being defined. If that's the case, i think assert_select was either > poorly written OR not completed yet. It's like saying that "if" > conditional works but "if not" only works to a simple extend only :( I > am sure it can be done. > Can someone please show us how? This is the main benefit of should and should_not vs assertions. Virtually every matcher works in with both should and should_not (unless it's author explicitly makes it not work that way). Again, assert_select is part of the Rails library, not RSpec. Please post this question to http://groups.google.com/group/rubyonrails-talk and I'm sure you'll find someone who uses assert_select and can either help you figure out how to do this, or help you work towards making it work better. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Oct 14 08:50:05 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Oct 2011 07:50:05 -0500 Subject: [rspec-users] Scope problems for before hooks using helper methods? In-Reply-To: References: Message-ID: <16D8EB82-2502-44C4-9C6F-F6013FC07909@gmail.com> On Oct 13, 2011, at 8:35 PM, Gordon wrote: > Hi, there, > > I believe I have some problem with scoping. > Here is the error message: > --------- Extract start ----------------- > > /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/ > active_support/dependencies.rb:235:in `load': /Users/anexiole/projects/ > try_rails/spec/controllers/brands_controller_spec.rb:164: syntax > error, unexpected keyword_end, expecting $end (SyntaxError) This is a syntax error. Please fix that first, and then we can talk about scoping :) Cheers, David From dchelimsky at gmail.com Fri Oct 14 08:52:45 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Oct 2011 07:52:45 -0500 Subject: [rspec-users] Scope problems for before hooks using helper methods? In-Reply-To: <21047a14-f42a-446c-9134-ace2942a4304@a25g2000yqi.googlegroups.com> References: <3DC6CB62-8FE5-4A63-9D7C-0814C2F623DB@gmail.com> <21047a14-f42a-446c-9134-ace2942a4304@a25g2000yqi.googlegroups.com> Message-ID: On Oct 14, 2011, at 12:01 AM, Gordon wrote: >> Let's see the helper method please. > > # sets up an instance of a admin user > def login_admin_user > before(:each) do > @request.env["devise.mapping"] = Devise.mappings[:user] > @admin_user = FactoryGirl.create(:admin) > sign_in @admin_user > end > end > end > context 'with an admin user signed in' do # <----- starts failing in this context > before(:each) do > login_admin_user > end login_admin_user creates a before hook, but here it's _in a before hook_. That doesn't work. Try: context 'with an admin user signed in' do login_admin_user # not inside a before hook it '...' do # .... end end > > describe "creates a new brand entry" do > it "assigns a new brand as @brand" do > get :new > assigns(:brand).should be_a_new(Brand) > end > end > end > end HTH, David From dchelimsky at gmail.com Sun Oct 16 16:30:55 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Oct 2011 15:30:55 -0500 Subject: [rspec-users] rspec 2.7.0 is released! Message-ID: <20832F85-9205-401C-9D98-A5FE74E8C692@gmail.com> We're pleased to announce the release of rspec-2.7.0. Release notes for each gem are listed below, but here are a couple of highlights: ## Just type `rspec` With the the 2.7.0 release, if you keep all of your specs in the conventional `spec` directory, you don't need to follow the `rspec` command with a path. Just type `rspec`. If you keep your specs in a different directory, just set the `--default_path` option to that directory on the command line, or in a `.rspec` config file. ## The rake task now lets Bundler manage Bundler The `RSpec::Core::RakeTask` invokes the `rspec` command in a subshell. In recent releases, it assumed that you wanted it prefixed with `bundle exec` if it saw a `Gemfile`. We then added `gemfile` and `skip_bundler` options to the task, so you could manage this in different ways. It turns out that Bundler manages this quite well without any help from RSpec. If you activate Bundler in the parent shell, via the command line or `Bundler.setup`, it sets environment variables that activate Bundler in the subshell with the correct gemfile. The `gemfile` and `skip_bundler` options are therefore deprecated and have no effect. ## Release Notes ### rspec-core-2.7.0 [full changelog](http://github.com/rspec/rspec-core/compare/v2.6.4...v2.7.0) NOTE: RSpec's release policy dictates that there should not be any backward incompatible changes in minor releases, but we're making an exception to release a change to how RSpec interacts with other command line tools. As of 2.7.0, you must explicity `require "rspec/autorun"` unless you use the `rspec` command (which already does this for you). * Enhancements * Add example.exception (David Chelimsky) * `--default_path` command line option (Justin Ko) * support multiple `--line_number` options (David J. Hamilton) * also supports `path/to/file.rb:5:9` (runs examples on lines 5 and 9) * Allow classes/modules to be used as shared example group identifiers (Arthur Gunn) * Friendly error message when shared context cannot be found (S?awosz S?awi?ski) * Clear formatters when resetting config (John Bintz) * Add `xspecify` and xexample as temp-pending methods (David Chelimsky) * Add `--no-drb` option (Iain Hecker) * Provide more accurate run time by registering start time before code is loaded (David Chelimsky) * Rake task default pattern finds specs in symlinked dirs (Kelly Felkins) * Rake task no longer does anything to invoke bundler since Bundler already handles it for us. Thanks to Andre Arko for the tip. * Add `--failure-exit-code` option (Chris Griego) * Bug fixes * Include `Rake::DSL` to remove deprecation warnings in Rake > 0.8.7 (Pivotal Casebook) * Only eval `let` block once even if it returns `nil` (Adam Meehan) * Fix `--pattern` option (wasn't being recognized) (David Chelimsky) * Only implicitly `require "rspec/autorun"` with the `rspec` command (David Chelimsky) * Ensure that rspec's `at_exit` defines the exit code (Daniel Doubrovkine) * Show the correct snippet in the HTML and TextMate formatters (Brian Faherty) ### rspec-expectations-2.7.0 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.6.0...v2.7.0) * Enhancements * HaveMatcher converts argument using `to_i` (Alex Bepple & Pat Maddox) * Improved failure message for the `have_xxx` matcher (Myron Marston) * HaveMatcher supports `count` (Matthew Bellantoni) * Change matcher dups `Enumerable` before the action, supporting custom `Enumerable` types like `CollectionProxy` in Rails (David Chelimsky) * Bug fixes * Fix typo in `have(n).xyz` documentation (Jean Boussier) * fix `safe_sort` for ruby 1.9.2 (`Kernel` now defines `<=>` for Object) (Peter van Hardenberg) ### rspec-mocks-2.7.0 [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.6.0...v2.7.0) * Enhancements * Use `__send__` rather than `send` (alextk) * Add support for `any_instance.stub_chain` (Sidu Ponnappa) * Add support for `any_instance` argument matching based on `with` (Sidu Ponnappa and Andy Lindeman) * Changes * Check for `failure_message_for_should` or `failure_message` instead of `description` to detect a matcher (Tibor Claassen) * Bug fixes * pass a hash to `any_instance.stub`. (Justin Ko) * allow `to_ary` to be called without raising `NoMethodError` (Mikhail Dieterle) * `any_instance` properly restores private methods (Sidu Ponnappa) ### rspec-rails-2.7.0 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.6.1...v2.7.0) * Enhancments * `ActiveRecord::Relation` can use the `=~` matcher (Andy Lindeman) * Make generated controller spec more consistent with regard to ids (Brent J. Nordquist) * Less restrictive autotest mapping between spec and implementation files (Jos? Valim) * `require 'rspec/autorun'` from generated `spec_helper.rb` (David Chelimsky) * add `bypass_rescue` (Lenny Marks) * `route_to` accepts query string (Marc Weil) * Internal * Added specs for generators using ammeter (Alex Rothenberg) * Bug fixes * Fix configuration/integration bug with rails 3.0 (fixed in 3.1) in which `fixure_file_upload` reads from `ActiveSupport::TestCase.fixture_path` and misses RSpec's configuration (David Chelimsky) * Support nested resource in view spec generator (David Chelimsky) * Define `primary_key` on class generated by `mock_model("WithAString")` (David Chelimsky) From m.veldthuis at gmail.com Sun Oct 16 05:47:09 2011 From: m.veldthuis at gmail.com (Marten Veldthuis) Date: Sun, 16 Oct 2011 02:47:09 -0700 (PDT) Subject: [rspec-users] Ignoring certain files? Message-ID: <826053.2007.1318758429770.JavaMail.geo-discussion-forums@vbmh5> Hey guys, Is there any way I can get rspec to ignore all files in spec/fixtures when it does a recursive search for all spec/**/*_spec.rb files? The problem I'm facing is that the fixtures for my code are project structures on disk, so I thought I'd make a spec/fixtures with a bunch of different project structures. That works, except obviously those can contain _spec.rb files, which rspec picks up when I try to run it for my gem. So my library Soundcheck has this in it's spec directory: spec/soundcheck_spec.rb spec/fixtures/ruby/rspec/spec/with_bundler_spec.rb spec/fixtures/ruby/rspec/spec/without_bundler_spec.rb When I run "rspec spec" it'll try to execute with_bundler_spec.rb too, but those files shouldn't be run. I'd rather keep everything spec-related within "spec/", so I'm hoping this is possible. I know I can run "rspec spec/soundcheck_spec.rb" but obviously as I add more stuff that's not going to be so feasible... Thanks, Marten -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Sun Oct 16 23:48:06 2011 From: jko170 at gmail.com (Justin Ko) Date: Sun, 16 Oct 2011 21:48:06 -0600 Subject: [rspec-users] Ignoring certain files? In-Reply-To: <826053.2007.1318758429770.JavaMail.geo-discussion-forums@vbmh5> References: <826053.2007.1318758429770.JavaMail.geo-discussion-forums@vbmh5> Message-ID: <54A892EB-6248-4425-B024-988ED4ED84F2@gmail.com> On Oct 16, 2011, at 3:47 AM, Marten Veldthuis wrote: > Hey guys, > > Is there any way I can get rspec to ignore all files in spec/fixtures when it does a recursive search for all spec/**/*_spec.rb files? > > The problem I'm facing is that the fixtures for my code are project structures on disk, so I thought I'd make a spec/fixtures with a bunch of different project structures. That works, except obviously those can contain _spec.rb files, which rspec picks up when I try to run it for my gem. So my library Soundcheck has this in it's spec directory: > > spec/soundcheck_spec.rb > spec/fixtures/ruby/rspec/spec/with_bundler_spec.rb > spec/fixtures/ruby/rspec/spec/without_bundler_spec.rb > > When I run "rspec spec" it'll try to execute with_bundler_spec.rb too, but those files shouldn't be run. > > I'd rather keep everything spec-related within "spec/", so I'm hoping this is possible. I know I can run "rspec spec/soundcheck_spec.rb" but obviously as I add more stuff that's not going to be so feasible... > > Thanks, > > Marten > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users RSpec.configure do |config| config.pattern = FileList[config.pattern].exclude('fixtures') end From anexiole at gmail.com Wed Oct 19 01:30:38 2011 From: anexiole at gmail.com (Gordon) Date: Tue, 18 Oct 2011 22:30:38 -0700 (PDT) Subject: [rspec-users] View spec for 'new' keeps failing despite generated html has expected attribute Message-ID: <8f52cfac-a660-4005-b3c2-3c95e1d2e00d@g27g2000pro.googlegroups.com> Hi guys, I have created a new resource, brands and here's the spec for 'new' which is failing. I do not know what's going on despite checking it out for a few times already ------ app/views/brands/new.html.erb - start -------------

New brand

<%= render 'form' %> <%= link_to 'Back', brands_path %> ------ app/views/brands/new.html.erb - start -------------

New brand

<%= render 'form' %> <%= link_to 'Back', brands_path %> ------ app/views/brands/new.html.erb - end ------------- ------ app/views/brands/_form.html.erb - start ------------- <%= form_for(@brand) do |f| %> <% if @brand.errors.any? %>

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

    <% @brand.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
<% end %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :description %>
<%= f.text_field :description %>
<%= f.submit %>
<% end %> ------ app/views/brands/_form.html.erb - end ------------- --------spec/views/parts/new.html.erb_spec.rb - start -------- require 'spec_helper' describe "brands/new.html.erb" do include Devise::TestHelpers before(:each) do @brand = assign( :brand, stub_model( Brand, :name => 'Apple', :description => 'OS X and Ipods' ) ) end it "renders new brand form" do render rendered.should have_selector( 'form', :method => 'post', :action => brands_path ) do |form| form.should have_selector("input", :type => "submit") end end end --------spec/views/parts/new.html.erb_spec.rb - end -------- My spec, spec/views/brands/new.html.erb_spec.rb fails with the following error: -------- Error message - start ------------------------ 1) brands/new.html.erb renders new brand form Failure/Error: form.should have_selector("input", :type => "submit") expected following output to contain a tag: # ./spec/views/brands/new.html.erb_spec.rb:21 # ./spec/views/brands/new.html.erb_spec.rb:17 -------- Error message - end ------------------------ When I do a view source on the page, I could very well see the submit button in the form. ----------- html form extract - start ---------------------


----------- html form extract - end --------------------- What am I missing? thanks :) From anexiole at gmail.com Wed Oct 19 03:36:11 2011 From: anexiole at gmail.com (Gordon) Date: Wed, 19 Oct 2011 00:36:11 -0700 (PDT) Subject: [rspec-users] View spec for 'new' keeps failing despite generated html has expected attribute In-Reply-To: <8f52cfac-a660-4005-b3c2-3c95e1d2e00d@g27g2000pro.googlegroups.com> References: <8f52cfac-a660-4005-b3c2-3c95e1d2e00d@g27g2000pro.googlegroups.com> Message-ID: Fixed the issue as soon as I walked off my desk. Thought it was because of the resource object, @brand in spec/views/ parts/new.html.erb_spec.rb not being stubbed properly. Checked and I was right :) So, before(:each) do @brand = assign( :brand, stub_model( Brand, :name => 'Apple', :description => 'OS X and Ipods' ) ) end should have also had the ".as_new_record" method there. Reading below, my view specs pass :) before(:each) do @brand = assign( :brand, stub_model( Brand, :name => 'Apple', :description => 'OS X and Ipods' ).as_new_record ) end Case closed :) From dchelimsky at gmail.com Wed Oct 19 14:07:32 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Oct 2011 13:07:32 -0500 Subject: [rspec-users] rspec 2 and rails engines Message-ID: <330A34CB-A31D-419F-A4FF-0C9963EA079C@gmail.com> Anybody successfully working with rails 3 engines and rspec 2? If so, please weigh in on https://github.com/dchelimsky/rspec/issues/41. TIA, David From dchelimsky at gmail.com Thu Oct 20 08:07:21 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 20 Oct 2011 07:07:21 -0500 Subject: [rspec-users] rspec-core 2.7.1 is released! Message-ID: rspec-core 2.7.1 is released! ### rspec-core-2.7.1 / 2011-10-20 [full changelog](http://github.com/rspec/rspec-core/compare/v2.7.0...v2.7.1) * Bug fixes * tell autotest the correct place to find the rspec executable From jcfischer at gmail.com Tue Oct 18 10:02:03 2011 From: jcfischer at gmail.com (Jens-Christian Fischer) Date: Tue, 18 Oct 2011 07:02:03 -0700 (PDT) Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading Message-ID: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> Hi there I have a weird situation. I have inherited a project in Rails 1.2.3 that has been upgraded to Rails 2.3.14 (and is running). I have installed Cucumber and Rspec to start to write features/tests for the new code that needs to be written. In my Gemfile, these Gems are loaded: group :test do gem 'rspec-rails', '~> 1.3.4', :require => 'spec/rails' gem 'rspec', '~> 1.3.2', :require => 'spec' gem "capybara", "0.3.9" gem "cucumber", "0.9.4" gem "cucumber-rails", "0.3.2" gem 'database_cleaner' end When I run the specs (bundle exec spec spec), I get error messages because the plugins of the application aren't loaded. Indeed, if I bundle the gems in "group :test, :development do ", then script/server and script/console fail to start as well because the plugins aren't loaded. Anyone seen this problem or can give me a hint of why the plugins suddenly aren't loaded (and where I should poke to find the cause)? thanks Jens-Christian From bill.christian at gmail.com Tue Oct 18 11:03:51 2011 From: bill.christian at gmail.com (Bill Christian) Date: Tue, 18 Oct 2011 08:03:51 -0700 (PDT) Subject: [rspec-users] Database custom formatter Message-ID: <32548201.647.1318950231695.JavaMail.geo-discussion-forums@vbmh5> I am trying to write a custom formatter to update a database record based on example results. Having a lot of trouble, so I thought to ask if anyone has a custom formatter that writes results to a database or outputs results in JSON or some other programmatic format. A working example will go a long way in helping me work thru my own use case. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Fri Oct 21 04:01:10 2011 From: jko170 at gmail.com (Justin Ko) Date: Fri, 21 Oct 2011 02:01:10 -0600 Subject: [rspec-users] Database custom formatter In-Reply-To: <32548201.647.1318950231695.JavaMail.geo-discussion-forums@vbmh5> References: <32548201.647.1318950231695.JavaMail.geo-discussion-forums@vbmh5> Message-ID: On Oct 18, 2011, at 9:03 AM, Bill Christian wrote: > I am trying to write a custom formatter to update a database record based on example results. Having a lot of trouble, so I thought to ask if anyone has a custom formatter that writes results to a database or outputs results in JSON or some other programmatic format. A working example will go a long way in helping me work thru my own use case. > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users There are RSpec's own formatters: https://github.com/rspec/rspec-core/tree/master/lib/rspec/core/formatters And also Fuubar, an external one: https://github.com/jeffkreeftmeijer/fuubar From matt at mattwynne.net Fri Oct 21 05:26:10 2011 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 21 Oct 2011 10:26:10 +0100 Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading In-Reply-To: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> References: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> Message-ID: <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> On 18 Oct 2011, at 15:02, Jens-Christian Fischer wrote: > Hi there > > I have a weird situation. I have inherited a project in Rails 1.2.3 > that has been upgraded to Rails 2.3.14 (and is running). I have > installed Cucumber and Rspec to start to write features/tests for the > new code that needs to be written. In my Gemfile, these Gems are > loaded: > > group :test do > gem 'rspec-rails', '~> 1.3.4', :require => 'spec/rails' > gem 'rspec', '~> 1.3.2', :require => 'spec' > gem "capybara", "0.3.9" > gem "cucumber", "0.9.4" > gem "cucumber-rails", "0.3.2" > gem 'database_cleaner' > end > > When I run the specs (bundle exec spec spec), I get error messages > because the plugins of the application aren't loaded. > > Indeed, if I bundle the gems in "group :test, :development do ", then > script/server and script/console fail to start as well because the > plugins aren't loaded. > > Anyone seen this problem or can give me a hint of why the plugins > suddenly aren't loaded (and where I should poke to find the cause)? > > thanks > Jens-Christian My guess is that, because this is an older Rails app, it doesn't use Bundler as you'd expect. In a Rails 3 app, your config/application.rb will have something like this near the top: Bundler.require(:default, Rails.env) if defined?(Bundler) That's the magic that tells Bundler to require all the plugins for the test environment when you run the tests. You'll need to stick something like that into your Rails 1 app. One other problem you'll probably hit: Capybara won't work with Rails apps that old, so you'll need to use Webrat for integration testing instead. 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 apremdas at gmail.com Fri Oct 21 11:05:19 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 21 Oct 2011 16:05:19 +0100 Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading In-Reply-To: <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> References: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> Message-ID: On 21 October 2011 10:26, Matt Wynne wrote: > > On 18 Oct 2011, at 15:02, Jens-Christian Fischer wrote: > >> Hi there >> >> I have a weird situation. I have inherited a project in Rails 1.2.3 >> that has been upgraded to Rails 2.3.14 (and is running). I have >> installed Cucumber and Rspec to start to write features/tests for the >> new code that needs to be written. In my Gemfile, these Gems are >> loaded: >> >> group :test do >> ?gem 'rspec-rails', '~> 1.3.4', :require => 'spec/rails' >> ?gem 'rspec', '~> 1.3.2', :require => 'spec' >> ?gem "capybara", "0.3.9" >> ?gem "cucumber", "0.9.4" >> ?gem "cucumber-rails", "0.3.2" >> ?gem 'database_cleaner' >> end >> >> When I run the specs (bundle exec spec spec), I get error messages >> because the plugins of the application aren't loaded. >> >> Indeed, if I bundle the gems in "group :test, :development do ", then >> script/server and script/console fail to start as well because the >> plugins aren't loaded. >> >> Anyone seen this problem or can give me a hint of why the plugins >> suddenly aren't loaded (and where I should poke to find the cause)? >> >> thanks >> Jens-Christian > > My guess is that, because this is an older Rails app, it doesn't use Bundler as you'd expect. In a Rails 3 app, your config/application.rb will have something like this near the top: > > ? ?Bundler.require(:default, Rails.env) if defined?(Bundler) > > That's the magic that tells Bundler to require all the plugins for the test environment when you run the tests. You'll need to stick something like that into your Rails 1 app. > > One other problem you'll probably hit: Capybara won't work with Rails apps that old, so you'll need to use Webrat for integration testing instead. The op said the app had been upgraded to 2.3.14 which supports capybara (has rack). The Rails 2.3.12 that (for my sins) I'm currently working on has some code near the bottom of config/boot.rb to load bundler. class Rails::Boot def run load_initializer Rails::Initializer.class_eval do def load_gems @bundler_loaded ||= begin result = Bundler.require :default Bundler.require(Rails.env) unless Rails.env.test? result end end end Rails::Initializer.run(:set_load_path) end end HTH All best Andrew > > 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 > -- ------------------------ Andrew Premdas blog.andrew.premdas.org From lenny at aps.org Fri Oct 21 16:18:05 2011 From: lenny at aps.org (Lenny Marks) Date: Fri, 21 Oct 2011 16:18:05 -0400 Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading In-Reply-To: References: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> Message-ID: On Oct 21, 2011, at 11:05 AM, Andrew Premdas wrote: > On 21 October 2011 10:26, Matt Wynne wrote: >> >> On 18 Oct 2011, at 15:02, Jens-Christian Fischer wrote: >> >>> Hi there >>> >>> I have a weird situation. I have inherited a project in Rails 1.2.3 >>> that has been upgraded to Rails 2.3.14 (and is running). I have >>> installed Cucumber and Rspec to start to write features/tests for the >>> new code that needs to be written. In my Gemfile, these Gems are >>> loaded: >>> >>> group :test do >>> gem 'rspec-rails', '~> 1.3.4', :require => 'spec/rails' >>> gem 'rspec', '~> 1.3.2', :require => 'spec' >>> gem "capybara", "0.3.9" >>> gem "cucumber", "0.9.4" >>> gem "cucumber-rails", "0.3.2" >>> gem 'database_cleaner' >>> end >>> >>> When I run the specs (bundle exec spec spec), I get error messages >>> because the plugins of the application aren't loaded. >>> >>> Indeed, if I bundle the gems in "group :test, :development do ", then >>> script/server and script/console fail to start as well because the >>> plugins aren't loaded. >>> >>> Anyone seen this problem or can give me a hint of why the plugins >>> suddenly aren't loaded (and where I should poke to find the cause)? >>> >>> thanks >>> Jens-Christian >> >> My guess is that, because this is an older Rails app, it doesn't use Bundler as you'd expect. In a Rails 3 app, your config/application.rb will have something like this near the top: >> >> Bundler.require(:default, Rails.env) if defined?(Bundler) >> >> That's the magic that tells Bundler to require all the plugins for the test environment when you run the tests. You'll need to stick something like that into your Rails 1 app. >> >> One other problem you'll probably hit: Capybara won't work with Rails apps that old, so you'll need to use Webrat for integration testing instead. > > The op said the app had been upgraded to 2.3.14 which supports > capybara (has rack). The Rails 2.3.12 that (for my sins) I'm currently > working on has some code near the bottom of config/boot.rb to load > bundler. > > > class Rails::Boot > def run > load_initializer > > Rails::Initializer.class_eval do > def load_gems > @bundler_loaded ||= begin > result = Bundler.require :default > Bundler.require(Rails.env) unless Rails.env.test? > result > end > end > end > > Rails::Initializer.run(:set_load_path) > end > end > > HTH > If Bundler is the issue, you have to have followed these instructions(probably where the snippet above came from) to get things set up with Rails 2.3 http://gembundler.com/rails23.html -lenny > > All best > > Andrew > >> >> 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 >> > > > > -- > ------------------------ > Andrew Premdas > blog.andrew.premdas.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jcfischer at gmail.com Mon Oct 24 04:12:22 2011 From: jcfischer at gmail.com (Jens-Christian Fischer) Date: Mon, 24 Oct 2011 01:12:22 -0700 (PDT) Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading In-Reply-To: References: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> Message-ID: <3a5b8041-4807-4dfb-866d-8e51e681ded4@n18g2000vbv.googlegroups.com> Thanks for all the hints. I'm pretty sure however, that Bundler ist NOT the issue. Both boot.rb and config/preinitializer.rb are as expected and the app itself starts fine both with script/server or script/console. However, as soon as rspec is loaded (when running the tests), then the plugins aren't loaded anymore. A wild guess is that Rspec causes the loading of plugins to fail in mysterious ways, but I don't enough of either the Rails 2.3 booting process nor the Rspec magic to pinpoint the location where I should put my finger on. Any further ideas that I could look into? thanks jc On 21 Okt., 22:18, Lenny Marks wrote: > On Oct 21, 2011, at 11:05 AM, Andrew Premdas wrote: > > > > > > > > > > > On 21 October 2011 10:26, Matt Wynne wrote: > > >> On 18 Oct 2011, at 15:02, Jens-Christian Fischer wrote: > > >>> Hi there > > >>> I have a weird situation. I have inherited a project in Rails 1.2.3 > >>> that has been upgraded to Rails 2.3.14 (and is running). I have > >>> installed Cucumber and Rspec to start to write features/tests for the > >>> new code that needs to be written. In my Gemfile, these Gems are > >>> loaded: > > >>> group :test do > >>> ?gem 'rspec-rails', '~> 1.3.4', :require => 'spec/rails' > >>> ?gem 'rspec', '~> 1.3.2', :require => 'spec' > >>> ?gem "capybara", "0.3.9" > >>> ?gem "cucumber", "0.9.4" > >>> ?gem "cucumber-rails", "0.3.2" > >>> ?gem 'database_cleaner' > >>> end > > >>> When I run the specs (bundle exec spec spec), I get error messages > >>> because the plugins of the application aren't loaded. > > >>> Indeed, if I bundle the gems in "group :test, :development do ", then > >>> script/server and script/console fail to start as well because the > >>> plugins aren't loaded. > > >>> Anyone seen this problem or can give me a hint of why the plugins > >>> suddenly aren't loaded (and where I should poke to find the cause)? > > >>> thanks > >>> Jens-Christian > > >> My guess is that, because this is an older Rails app, it doesn't use Bundler as you'd expect. In a Rails 3 app, your config/application.rb will have something like this near the top: > > >> ? ?Bundler.require(:default, Rails.env) if defined?(Bundler) > > >> That's the magic that tells Bundler to require all the plugins for the test environment when you run the tests. You'll need to stick something like that into your Rails 1 app. > > >> One other problem you'll probably hit: Capybara won't work with Rails apps that old, so you'll need to use Webrat for integration testing instead. > > > The op said the app had been upgraded to 2.3.14 which supports > > capybara (has rack). The Rails 2.3.12 that (for my sins) I'm currently > > working on has some code near the bottom of config/boot.rb to load > > bundler. > > > class Rails::Boot > > ?def run > > ? ?load_initializer > > > ? ?Rails::Initializer.class_eval do > > ? ? ?def load_gems > > ? ? ? ?@bundler_loaded ||= begin > > ? ? ? ? ?result = Bundler.require :default > > ? ? ? ? ?Bundler.require(Rails.env) unless Rails.env.test? > > ? ? ? ? ?result > > ? ? ? ?end > > ? ? ?end > > ? ?end > > > ? ?Rails::Initializer.run(:set_load_path) > > ?end > > end > > > HTH > > If Bundler is the issue, you have to have followed these instructions(probably where the snippet above came from) to get things set up with Rails 2.3 > > http://gembundler.com/rails23.html > > -lenny > > > > > > > > > > > > > All best > > > Andrew > > >> 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-us... at rubyforge.org > >>http://rubyforge.org/mailman/listinfo/rspec-users > > > -- > > ------------------------ > > Andrew Premdas > > blog.andrew.premdas.org > > _______________________________________________ > > 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 apremdas at gmail.com Mon Oct 24 05:57:16 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Mon, 24 Oct 2011 10:57:16 +0100 Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading In-Reply-To: <3a5b8041-4807-4dfb-866d-8e51e681ded4@n18g2000vbv.googlegroups.com> References: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> <3a5b8041-4807-4dfb-866d-8e51e681ded4@n18g2000vbv.googlegroups.com> Message-ID: On 24 October 2011 09:12, Jens-Christian Fischer wrote: > Thanks for all the hints. I'm pretty sure however, that Bundler ist > NOT the issue. Both boot.rb and config/preinitializer.rb are as > expected and the app itself starts fine both with script/server or > script/console. > > However, as soon as rspec is loaded (when running the tests), then the > plugins aren't loaded anymore. A wild guess is that Rspec causes the > loading of plugins to fail in mysterious ways, but I don't enough of > either the Rails 2.3 booting process nor the Rspec magic to pinpoint > the location where I should put my finger on. > > Any further ideas that I could look into? > Its far more likely that your application is wrong than RSpec is wrong, especially with an effect that is so large. You don't really know much about your application (you stated that you've only just inherited it. Something odd is going on with bundler (you stated that in your original post. Best advice I can give is question your assumptions and assume you have made a mistake - generally when something doesn't work its usually my fault :) After that creating a new rails project with the same gemset (ideally using RVM) might help isolate the issue. Also publishing the error messages in a gist, or even publishing the whole project on Github might help. All best Andrew > thanks > jc > > On 21 Okt., 22:18, Lenny Marks wrote: >> On Oct 21, 2011, at 11:05 AM, Andrew Premdas wrote: >> >> >> >> >> >> >> >> >> >> > On 21 October 2011 10:26, Matt Wynne wrote: >> >> >> On 18 Oct 2011, at 15:02, Jens-Christian Fischer wrote: >> >> >>> Hi there >> >> >>> I have a weird situation. I have inherited a project in Rails 1.2.3 >> >>> that has been upgraded to Rails 2.3.14 (and is running). I have >> >>> installed Cucumber and Rspec to start to write features/tests for the >> >>> new code that needs to be written. In my Gemfile, these Gems are >> >>> loaded: >> >> >>> group :test do >> >>> ?gem 'rspec-rails', '~> 1.3.4', :require => 'spec/rails' >> >>> ?gem 'rspec', '~> 1.3.2', :require => 'spec' >> >>> ?gem "capybara", "0.3.9" >> >>> ?gem "cucumber", "0.9.4" >> >>> ?gem "cucumber-rails", "0.3.2" >> >>> ?gem 'database_cleaner' >> >>> end >> >> >>> When I run the specs (bundle exec spec spec), I get error messages >> >>> because the plugins of the application aren't loaded. >> >> >>> Indeed, if I bundle the gems in "group :test, :development do ", then >> >>> script/server and script/console fail to start as well because the >> >>> plugins aren't loaded. >> >> >>> Anyone seen this problem or can give me a hint of why the plugins >> >>> suddenly aren't loaded (and where I should poke to find the cause)? >> >> >>> thanks >> >>> Jens-Christian >> >> >> My guess is that, because this is an older Rails app, it doesn't use Bundler as you'd expect. In a Rails 3 app, your config/application.rb will have something like this near the top: >> >> >> ? ?Bundler.require(:default, Rails.env) if defined?(Bundler) >> >> >> That's the magic that tells Bundler to require all the plugins for the test environment when you run the tests. You'll need to stick something like that into your Rails 1 app. >> >> >> One other problem you'll probably hit: Capybara won't work with Rails apps that old, so you'll need to use Webrat for integration testing instead. >> >> > The op said the app had been upgraded to 2.3.14 which supports >> > capybara (has rack). The Rails 2.3.12 that (for my sins) I'm currently >> > working on has some code near the bottom of config/boot.rb to load >> > bundler. >> >> > class Rails::Boot >> > ?def run >> > ? ?load_initializer >> >> > ? ?Rails::Initializer.class_eval do >> > ? ? ?def load_gems >> > ? ? ? ?@bundler_loaded ||= begin >> > ? ? ? ? ?result = Bundler.require :default >> > ? ? ? ? ?Bundler.require(Rails.env) unless Rails.env.test? >> > ? ? ? ? ?result >> > ? ? ? ?end >> > ? ? ?end >> > ? ?end >> >> > ? ?Rails::Initializer.run(:set_load_path) >> > ?end >> > end >> >> > HTH >> >> If Bundler is the issue, you have to have followed these instructions(probably where the snippet above came from) to get things set up with Rails 2.3 >> >> http://gembundler.com/rails23.html >> >> -lenny >> >> >> >> >> >> >> >> >> >> >> >> > All best >> >> > Andrew >> >> >> 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-us... at rubyforge.org >> >>http://rubyforge.org/mailman/listinfo/rspec-users >> >> > -- >> > ------------------------ >> > Andrew Premdas >> > blog.andrew.premdas.org >> > _______________________________________________ >> > 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- ------------------------ Andrew Premdas blog.andrew.premdas.org From anexiole at gmail.com Tue Oct 25 02:56:50 2011 From: anexiole at gmail.com (Gordon) Date: Mon, 24 Oct 2011 23:56:50 -0700 (PDT) Subject: [rspec-users] upgraded to rails 3.1.0 and found that string value of id has to be used instead of the integer value. Message-ID: <32eea15f-6896-4f43-b6f8-43527124d01e@p20g2000prm.googlegroups.com> My advance apologies if the title/subject is not too descriptive. Pre: I have just upgraded from rails 3.0.9 to rails 3.1.0 Before the upgrade, running 'rake spec' sees all my specs pass. After the upgrade, I seem to encounter some errors: -------------- Error extracts start ------------------------------- controller_spec.rb ./spec/controllers/parts_controller_spec.rb ............................FFF Failures: 1) PartsController saves updates to an existing part object successfully by finding the existing part and returning it for update Failure/Error: put :update, :id => "1", :part => { received :find with unexpected arguments expected: (1) got: ("1") # ./app/controllers/parts_controller.rb:131:in `check_authorisation' # ./spec/controllers/parts_controller_spec.rb:74:in `block (3 levels) in ' 2) PartsController saves updates to an existing part object successfully does its job in saving the update Failure/Error: put :update, :id => 1, :part => { received :find with unexpected arguments expected: (1) got: ("1") # ./app/controllers/parts_controller.rb:131:in `check_authorisation' # ./spec/controllers/parts_controller_spec.rb:81:in `block (3 levels) in ' 3) PartsController saves updates to an existing part object successfully communicates the successful update via the flash Failure/Error: put :update, :id => 1, :part => {'title' => 'Brake pads'} received :find with unexpected arguments expected: (1) got: ("1") # ./app/controllers/parts_controller.rb:131:in `check_authorisation' # ./spec/controllers/parts_controller_spec.rb:87:in `block (3 levels) in ' Finished in 8.02 seconds 31 examples, 3 failures Failed examples: rspec ./spec/controllers/parts_controller_spec.rb:72 # PartsController saves updates to an existing part object successfully by finding the existing part and returning it for update rspec ./spec/controllers/parts_controller_spec.rb:79 # PartsController saves updates to an existing part object successfully does its job in saving the update rspec ./spec/controllers/parts_controller_spec.rb:86 # PartsController saves updates to an existing part object successfully communicates the successful update via the flash rake aborted! -------------- Error extracts end ------------------------------- My parts' controller spec reads: ------------ /spec/controllers/parts_controller_spec.rb start ------------- 63 context 'saves updates to an existing part object successfully' do 64 @new_title = 'Brake pads' 65 66 before(:each) do 67 @part = mock_model(Part, :update_attributes! => true, :created_by => @user.id) 68 Part.stub!('check_authorisation').and_return(true) 69 Part.stub!(:find).with(1).and_return(@part) 70 end 71 72 it 'by finding the existing part and returning it for update' do 73 Part.should_receive(:find).with(1).and_return(@part) 74 put :update, :id => "1", :part => { 75 'title' => @new_title 76 } 77 end 78 79 it 'does its job in saving the update' do 80 @part.should_receive(:update_attributes!).and_return(true) 81 put :update, :id => 1, :part => { 82 'title' => @new_title 83 } 84 end 85 86 it 'communicates the successful update via the flash' do 87 put :update, :id => 1, :part => {'title' => 'Brake pads'} 88 flash[:notice].should eql('Part was successfully updated.') 89 end 90 end ------------ /spec/controllers/parts_controller_spec.rb end ------------- What I did: By changing the argument value from 1 to '1' in the lines that deal with the a) stubbing of the find method (with a value of 1) b) should_receive test Here's how the lines look like after the change: 69 Part.stub!(:find).with('1').and_return(@part) 73 Part.should_receive(:find).with('1').and_return(@part) The result is that all specs pass. --------- Extract of run - start ---------------------- 192-168-1-2:script anexiole$ rake spec:controllers (in /Users/ct9a/projects/try_rails) /usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby -S rspec ./spec/ controllers/application_controller_spec.rb ./spec/controllers/ brands_controller_spec.rb ./spec/controllers/home_controller_spec.rb ./ spec/controllers/parts_controller_spec.rb ............................... Finished in 8.49 seconds 31 examples, 0 failures --------- Extract of run - end ---------------------- I can't think of a good reason of why putting the quotes worked after the upgrade to rails 3.1? It's worked fine all this while circa rails 3.1 Why should I have to pass a string of '1' instead of using the integer value, 1 of the id to the stubbing definition for the find method (As argument) and the expected id value in the should_receive test? Would like to hear some thoughts on this behaviour. Thank you Gorodn Yeong From dchelimsky at gmail.com Tue Oct 25 08:54:32 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 25 Oct 2011 07:54:32 -0500 Subject: [rspec-users] upgraded to rails 3.1.0 and found that string value of id has to be used instead of the integer value. In-Reply-To: <32eea15f-6896-4f43-b6f8-43527124d01e@p20g2000prm.googlegroups.com> References: <32eea15f-6896-4f43-b6f8-43527124d01e@p20g2000prm.googlegroups.com> Message-ID: <5C255550-4802-4E63-A076-7BA0FED744CC@gmail.com> On Oct 25, 2011, at 1:56 AM, Gordon wrote: > My advance apologies if the title/subject is not too descriptive. > > > Pre: I have just upgraded from rails 3.0.9 to rails 3.1.0 > > Before the upgrade, running 'rake spec' sees all my specs pass. > > After the upgrade, I seem to encounter some errors: > -------------- Error extracts start ------------------------------- > controller_spec.rb ./spec/controllers/parts_controller_spec.rb > ............................FFF > > Failures: > > 1) PartsController saves updates to an existing part object > successfully by finding the existing part and returning it for update > Failure/Error: put :update, :id => "1", :part => { > created_by: integer, updated_by: integer, created_at: datetime, > updated_at: datetime) (class)> received :find with unexpected > arguments > expected: (1) > got: ("1") > # ./app/controllers/parts_controller.rb:131:in > `check_authorisation' > # ./spec/controllers/parts_controller_spec.rb:74:in `block (3 > levels) in ' > I can't think of a good reason of why putting the quotes worked after > the upgrade to rails 3.1? It's worked fine all this while circa rails > 3.1 I can, but not because it's an rspec issue. I just happened to submit the patch to Rails that made this change. [1] The problem is that Rails functional tests, which power rspec controller specs, don't go through rack. This means that you used to be able to do this in a controller spec: it "does one thing if :some_number is > 5" do get :some_action, :some_number = 6 end And this in the controller: def some_action if params[:some_number] > 5 do_this else do_that end end And the spec would pass, but it would fail when running through rack, as it does when you run a server. That's because all parameters are 'to_param'd before they make it to a controller when running through rack, but they weren't getting the same treatment in Rails functional tests. This was true whether you were using rspec, minitest, test/unit, etc, and was happening because the Rails test framework was letting Fixnums in the specs make it directly to the controllers. So the upside of this change is that we decrease the likelihood of false positives. The downside is that you have to change stubs and message expectations that are constrained on non-strings to expect strings. The upside of the downside is that your specs are now telling the truth, and are correctly aligned with the reality of the running application. HTH, David [1] https://github.com/rails/rails/pull/1203 > Why should I have to pass a string of '1' instead of using the integer > value, 1 of the id to the stubbing definition for the find method (As > argument) and the expected id value in the should_receive test? > > Would like to hear some thoughts on this behaviour. > > Thank you > > > Gorodn Yeong From jcfischer at gmail.com Wed Oct 26 11:09:03 2011 From: jcfischer at gmail.com (Jens-Christian Fischer) Date: Wed, 26 Oct 2011 08:09:03 -0700 (PDT) Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading In-Reply-To: References: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> <3a5b8041-4807-4dfb-866d-8e51e681ded4@n18g2000vbv.googlegroups.com> Message-ID: <0cb7dace-9d16-47a8-9bdc-b482204255d8@h24g2000yqm.googlegroups.com> Ok - I have created a brand new Rails 2.3.14 app, made it bundler aware (as of http://gembundler.com/rails23.html) and installed one plugin. This reproduces the problem described above. Here's the app: (it does nothing, the only change is the use of the "history" DSL keyword in application controller. History is coming from the "rails_history" plugin): https://github.com/jcfischer/rails2314_rspec_plugin If I enable rspec in Gemfile for the development environment, this is what I get: ? ?l_p_test git:(master) ? script/server=> Booting WEBrick=> Rails 2.3.14 application starting on http://0.0.0.0:3000NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.Gem.source_index called from /Users/jcf/.rvm/ gems/ruby-1.8.7-p352 at bla/gems/rails-2.3.14/lib/rails/gem_dependency.rb: 21./Users/jcf/dev/work/LENA/l_p_test/app/controllers/ application_controller.rb:13: undefined method `history' for ApplicationController:Class (NoMethodError) from /Users/jcf/.rvm/gems/ ruby-1.8.7-p352 at bla/gems/activesupport-2.3.14/lib/active_support/ dependencies.rb:406:in `load_without_new_constant_marking' from /Users/ jcf/.rvm/gems/ruby-1.8.7-p352 at bla/gems/activesupport-2.3.14/lib/ active_support/dependencies.rb:406:in `load_file' from /Users/jcf/.rvm/ gems/ruby-1.8.7-p352 at bla/gems/activesupport-2.3.14/lib/active_support/ dependencies.rb:547:in `new_constants_in' from /Users/jcf/.rvm/gems/ ruby-1.8.7-p352 at bla/gems/activesupport-2.3.14/lib/active_support/ dependencies.rb:405:in `load_file' from /Users/jcf/.rvm/gems/ ruby-1.8.7-p352 at bla/gems/activesupport-2.3.14/lib/active_support/ dependencies.rb:285:in `require_or_load' from /Users/jcf/.rvm/gems/ ruby-1.8.7-p352 at bla/gems/activesupport-2.3.14/lib/active_support/ dependencies.rb:250:in `depend_on' from /Users/jcf/.rvm/gems/ ruby-1.8.7-p352 at bla/gems/activesupport-2.3.14/lib/active_support/ dependencies.rb:162:in `require_dependency' from /Users/jcf/.rvm/gems/ ruby-1.8.7-p352 at bla/gems/rspec-rails-1.3.4/lib/spec/rails.rb:2 from / Users/jcf/.rvm/gems/ruby-1.8.7-p352 at global/gems/bundler-1.0.18/lib/ bundler/runtime.rb:68:in `require' from /Users/jcf/.rvm/gems/ ruby-1.8.7-p352 at global/gems/bundler-1.0.18/lib/bundler/runtime.rb: 68:in `require' from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at global/gems/ bundler-1.0.18/lib/bundler/runtime.rb:66:in `each' from /Users/ jcf/.rvm/gems/ruby-1.8.7-p352 at global/gems/bundler-1.0.18/lib/bundler/ runtime.rb:66:in `require' from /Users/jcf/.rvm/gems/ruby-1.8.7- p352 at global/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `each' from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at global/gems/bundler-1.0.18/ lib/bundler/runtime.rb:55:in `require' from /Users/jcf/.rvm/gems/ ruby-1.8.7-p352 at global/gems/bundler-1.0.18/lib/bundler.rb:120:in `require' from /Users/jcf/dev/work/LENA/l_p_test/config/boot.rb:119:in `load_gems' from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at bla/gems/ rails-2.3.14/lib/initializer.rb:164:in `process' from /Users/jcf/.rvm/ gems/ruby-1.8.7-p352 at bla/gems/rails-2.3.14/lib/initializer.rb:113:in `send' from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at bla/gems/rails-2.3.14/ lib/initializer.rb:113:in `run' from /Users/jcf/dev/work/LENA/l_p_test/ config/environment.rb:9 from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at bla/ gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require' from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at bla/gems/ activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require' from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at bla/gems/ activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in' from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at bla/gems/ activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require' from /Users/jcf/.rvm/gems/ruby-1.8.7-p352 at bla/gems/ rails-2.3.14/lib/commands/server.rb:84 from script/server:3:in `require' from script/server:3 If rspec is disabled, then the server starts fine So, while I understand the "your application is wrong" approach, I think I have just successfully eliminated that possibility. cheersjc On 24 Okt., 11:57, Andrew Premdas wrote: > On 24 October 2011 09:12, Jens-Christian Fischer wrote:> Thanks for all the hints. I'm pretty sure however, that Bundler ist > > NOT the issue. Both boot.rb and config/preinitializer.rb are as > > expected and the app itself starts fine both with script/server or > > script/console. > > > However, as soon as rspec is loaded (when running the tests), then the > > plugins aren't loaded anymore. A wild guess is that Rspec causes the > > loading of plugins to fail in mysterious ways, but I don't enough of > > either the Rails 2.3 booting process nor the Rspec magic to pinpoint > > the location where I should put my finger on. > > > Any further ideas that I could look into? > > Its far more likely that your application is wrong than RSpec is > wrong, especially with an effect that is so large. > You don't really know much about your application (you stated that > you've only just inherited it. > Something odd is going on with bundler (you stated that in your original post. > > Best advice I can give is question your assumptions and assume you > have made a mistake - generally when something doesn't work its > usually my fault :) After that creating a new rails project with the > same gemset (ideally using RVM) might help isolate the issue. Also > publishing the error messages in a gist, or even publishing the whole > project on Github might help. > > All best > > Andrew > > > > > > > > > > > thanks > > jc > > > On 21 Okt., 22:18, Lenny Marks wrote: > >> On Oct 21, 2011, at 11:05 AM, Andrew Premdas wrote: > > >> > On 21 October 2011 10:26, Matt Wynne wrote: > > >> >> On 18 Oct 2011, at 15:02, Jens-Christian Fischer wrote: > > >> >>> Hi there > > >> >>> I have a weird situation. I have inherited a project in Rails 1.2.3 > >> >>> that has been upgraded to Rails 2.3.14 (and is running). I have > >> >>> installed Cucumber and Rspec to start to write features/tests for the > >> >>> new code that needs to be written. In my Gemfile, these Gems are > >> >>> loaded: > > >> >>> group :test do > >> >>> ?gem 'rspec-rails', '~> 1.3.4', :require => 'spec/rails' > >> >>> ?gem 'rspec', '~> 1.3.2', :require => 'spec' > >> >>> ?gem "capybara", "0.3.9" > >> >>> ?gem "cucumber", "0.9.4" > >> >>> ?gem "cucumber-rails", "0.3.2" > >> >>> ?gem 'database_cleaner' > >> >>> end > > >> >>> When I run the specs (bundle exec spec spec), I get error messages > >> >>> because the plugins of the application aren't loaded. > > >> >>> Indeed, if I bundle the gems in "group :test, :development do ", then > >> >>> script/server and script/console fail to start as well because the > >> >>> plugins aren't loaded. > > >> >>> Anyone seen this problem or can give me a hint of why the plugins > >> >>> suddenly aren't loaded (and where I should poke to find the cause)? > > >> >>> thanks > >> >>> Jens-Christian > > >> >> My guess is that, because this is an older Rails app, it doesn't use Bundler as you'd expect. In a Rails 3 app, your config/application.rb will have something like this near the top: > > >> >> ? ?Bundler.require(:default, Rails.env) if defined?(Bundler) > > >> >> That's the magic that tells Bundler to require all the plugins for the test environment when you run the tests. You'll need to stick something like that into your Rails 1 app. > > >> >> One other problem you'll probably hit: Capybara won't work with Rails apps that old, so you'll need to use Webrat for integration testing instead. > > >> > The op said the app had been upgraded to 2.3.14 which supports > >> > capybara (has rack). The Rails 2.3.12 that (for my sins) I'm currently > >> > working on has some code near the bottom of config/boot.rb to load > >> > bundler. > > >> > class Rails::Boot > >> > ?def run > >> > ? ?load_initializer > > >> > ? ?Rails::Initializer.class_eval do > >> > ? ? ?def load_gems > >> > ? ? ? ?@bundler_loaded ||= begin > >> > ? ? ? ? ?result = Bundler.require :default > >> > ? ? ? ? ?Bundler.require(Rails.env) unless Rails.env.test? > >> > ? ? ? ? ?result > >> > ? ? ? ?end > >> > ? ? ?end > >> > ? ?end > > >> > ? ?Rails::Initializer.run(:set_load_path) > >> > ?end > >> > end > > >> > HTH > > >> If Bundler is the issue, you have to have followed these instructions(probably where the snippet above came from) to get things set up with Rails 2.3 > > >>http://gembundler.com/rails23.html > > >> -lenny > > >> > All best > > >> > Andrew > > >> >> cheers, > >> >> Matt > > >> >> -- > >> >> Freelance programmer & coach > >> >> Author,http://pragprog.com/book/hwcuc/the-cucumber-book(withAslak Helles?y) > >> >> Founder,http://relishapp.com > >> >> +44(0)7974430184 |http://twitter.com/mattwynne > > >> >> _______________________________________________ > >> >> rspec-users mailing list > >> >> rspec-us... at rubyforge.org > >> >>http://rubyforge.org/mailman/listinfo/rspec-users > > >> > -- > >> > ------------------------ > >> > Andrew Premdas > >> > blog.andrew.premdas.org > >> > _______________________________________________ > >> > 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 > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > -- > ------------------------ > Andrew Premdas > blog.andrew.premdas.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jcfischer at gmail.com Wed Oct 26 11:16:29 2011 From: jcfischer at gmail.com (Jens-Christian Fischer) Date: Wed, 26 Oct 2011 08:16:29 -0700 (PDT) Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading In-Reply-To: References: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> <3a5b8041-4807-4dfb-866d-8e51e681ded4@n18g2000vbv.googlegroups.com> Message-ID: <2caf94b3-66e4-4f1c-8f30-8b5e236619b4@a12g2000vbz.googlegroups.com> Ha - I think I found the problem: In my Gemfile I had: group :test, :cucumber do # , :development (till we work out why plugins don't load with rspec) gem 'rspec-rails', '~> 1.3.4' , :require => 'spec/rails' gem 'rspec', '~> 1.3.2', :require => 'spec' gem "capybara", "0.3.9" gem "cucumber", "0.9.4" gem "cucumber-rails", "0.3.2" gem 'database_cleaner' end removing the :require => ... lines seemed to fix the problem So you were right - it was all my fault ;) thanks for prodding me in the right direction. cheers jc From jlabarge at gmail.com Wed Oct 26 14:02:24 2011 From: jlabarge at gmail.com (jefflab) Date: Wed, 26 Oct 2011 11:02:24 -0700 (PDT) Subject: [rspec-users] problem profiling rspec boot time with ruby-prof Message-ID: <1f8aaae7-05a5-422f-b3ca-3adad496085a@d37g2000prg.googlegroups.com> We recently upgraded to rspec2 / rails 3 and our specs are taking a very long time to run. It takes nearly 12 minutes before the first dot comes out. Before the upgrade, our entire suite of 6000+ specs would run in about 6 minutes. The majority of the delay seems to be during the loading of the spec files. Adding instrumentation to the rspec-core lib/rspec/core/ command_line.rb, you can see that a large portion of the time is spent in the load_spec_files method puts "after options.configure #{Time.now}" @configuration.load_spec_files puts "after loading spec files stream #{Time.now}" after options.configure Tue Oct 25 15:34:18 -0700 2011 after loading spec files stream Tue Oct 25 15:46:20 -0700 2011 As you can see, 12 min and 2 seconds were spent in the load_spec_files method. I'm trying to use ruby-prof to characterize the problem, but I keep getting the following error: /Library/Ruby/Gems/1.8/gems/ruby-prof-0.10.8/lib/ruby-prof.rb:62:in `measure_mode=': can't set measure_mode while profiling (RuntimeError) from /Library/Ruby/Gems/1.8/gems/ruby-prof-0.10.8/lib/ruby-prof.rb: 62:in `figure_measure_mode' from /Library/Ruby/Gems/1.8/gems/ruby-prof-0.10.8/lib/ruby-prof.rb:67 from /Library/Ruby/Gems/1.8/gems/bundler-1.0.18/lib/bundler/ runtime.rb:68:in `require' from /Library/Ruby/Gems/1.8/gems/bundler-1.0.18/lib/bundler/ runtime.rb:68:in `require' from /Library/Ruby/Gems/1.8/gems/bundler-1.0.18/lib/bundler/ runtime.rb:66:in `each' from /Library/Ruby/Gems/1.8/gems/bundler-1.0.18/lib/bundler/ runtime.rb:66:in `require' from /Library/Ruby/Gems/1.8/gems/bundler-1.0.18/lib/bundler/ runtime.rb:55:in `each' from /Library/Ruby/Gems/1.8/gems/bundler-1.0.18/lib/bundler/ runtime.rb:55:in `require' from /Library/Ruby/Gems/1.8/gems/bundler-1.0.18/lib/bundler.rb:120:in `require' from /Users/myusername/code/mycompany/www/config/application.rb:7 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `require' from /Users/myusername/code/mycompany/www/config/environment.rb:2 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `require' from /Users/myusername/code/mycompany/www/spec/spec_helper.rb:9 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `require' from /Users/myusername/code/mycompany/www/spec/models/user_spec.rb:7 from ./twospecs.rb:5:in `load' from ./twospecs.rb:5 from ./twospecs.rb:5:in `map' from ./twospecs.rb:5 from /Library/Ruby/Gems/1.8/gems/ruby-prof-0.10.8/bin/ruby-prof: 243:in `load' from /Library/Ruby/Gems/1.8/gems/ruby-prof-0.10.8/bin/ruby-prof:243 from /usr/bin/ruby-prof:19:in `load' from /usr/bin/ruby-prof:19 My setup is the following: I have a script RAILS_ROOT/twospecs.rb that contains the following: $LOAD_PATH.unshift( "/Users/myusername/code/mycompany/www/spec" ) files_to_run = ["spec/models/user_spec.rb", "spec/models/kid_spec.rb"] files_to_run.map {|f| load File.expand_path(f) } Then I run it with ruby-prof: ruby-prof twospecs.rb The gem versions I'm using are: bundle show rspec /Library/Ruby/Gems/1.8/gems/rspec-2.6.0 bundle show ruby-prof /Library/Ruby/Gems/1.8/gems/ruby-prof-0.10.8 bundle show rails /Library/Ruby/Gems/1.8/gems/rails-3.0.10 I'm hoping the group can either tell me a) the root of my performance problems if this is a known problem or b) how to profile the boot time of an rspec suite (where boot time is the time before the first dot is printed). From jlabarge at gmail.com Wed Oct 26 18:41:42 2011 From: jlabarge at gmail.com (jefflab) Date: Wed, 26 Oct 2011 15:41:42 -0700 (PDT) Subject: [rspec-users] problem profiling rspec boot time with ruby-prof In-Reply-To: <1f8aaae7-05a5-422f-b3ca-3adad496085a@d37g2000prg.googlegroups.com> References: <1f8aaae7-05a5-422f-b3ca-3adad496085a@d37g2000prg.googlegroups.com> Message-ID: I ended up solving the ruby-prof conflict. The problem was that I had included the ruby-prof gem in my Gemfile. After removing it and doing a `bundle install` everything worked. I will start a new thread if the profiling results lead to performance opportunities in rspec boot time. From apremdas at gmail.com Fri Oct 28 15:10:23 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 28 Oct 2011 20:10:23 +0100 Subject: [rspec-users] rspec 1.3.2, Rails 2.3.14 - plugins not loading In-Reply-To: <2caf94b3-66e4-4f1c-8f30-8b5e236619b4@a12g2000vbz.googlegroups.com> References: <14bf1cd3-0fe0-40b0-b483-688847dd23fe@q12g2000yqe.googlegroups.com> <4165CDBF-5D0C-43ED-B27D-F0C6FF895554@mattwynne.net> <3a5b8041-4807-4dfb-866d-8e51e681ded4@n18g2000vbv.googlegroups.com> <2caf94b3-66e4-4f1c-8f30-8b5e236619b4@a12g2000vbz.googlegroups.com> Message-ID: On 26 October 2011 16:16, Jens-Christian Fischer wrote: > Ha - I think I found the problem: > > In my Gemfile I had: > > group :test, :cucumber do # , :development (till we work out why > plugins don't load with rspec) > ?gem 'rspec-rails', '~> 1.3.4' , :require => 'spec/rails' > ?gem 'rspec', '~> 1.3.2', :require => 'spec' > ?gem "capybara", "0.3.9" > ?gem "cucumber", "0.9.4" > ?gem "cucumber-rails", "0.3.2" > ?gem 'database_cleaner' > end > > removing the :require => ... lines seemed to fix the problem > > So you were right - it was all my fault ;) > > thanks for prodding me in the right direction. > > cheers > jc your welcome all best Andrew > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- ------------------------ Andrew Premdas blog.andrew.premdas.org From darthdeus at gmail.com Mon Oct 31 05:59:53 2011 From: darthdeus at gmail.com (Jakub Arnold) Date: Mon, 31 Oct 2011 02:59:53 -0700 (PDT) Subject: [rspec-users] Specs failing when run outside Spork with TypeError: superclass mismatch for class Attribute Message-ID: When I run my specs inside spork, they all just pass without any problems, but once I try to run them without spork, I end up with Failure/Error: Unable to find matching line from backtrace TypeError: superclass mismatch for class Attribute on each request spec. Here's a gist with the whole stack trace, request specs & spec_helper.rb https://gist.github.com/1327141 I'm running Rails 3.1.1 on Ruby 1.9.2 From internetchris1 at gmail.com Fri Oct 28 12:16:54 2011 From: internetchris1 at gmail.com (internetchris) Date: Fri, 28 Oct 2011 09:16:54 -0700 (PDT) Subject: [rspec-users] Noob (mock/stub) ActiveMerchant.. Message-ID: Hi Group I'm still waiting for the light to come on with stubbing/mocking and the syntax for each. I have simple method in my Order class like so.... def credit_card ActiveMerchant::Billing::CreditCard.new( :type => card_type, :number => card_number, :verification_value => card_verification, :month => card_expires_on.blank? ? Time.now.month : card_expires_on.month, :year => card_expires_on.blank? ? Time.now.year : card_expires_on.year, :first_name => first_name, :last_name => last_name ) end This method should return valid if the card is valid. http://activemerchant.rubyforge.org/classes/ActiveMerchant/Billing/CreditCard.html I started out like this but then confusion set in. If anyone has the time to help me understand or write the proper spec for this method I think it will help me better understand how to stub or mock a 3rd party item like this. I just watched the peepcode screencast and I've watched the railscasts. I'm just trying to apply my meager understanding to my own project now. it "should validate credit card" do gateway = stub('gateway') gateway.should_recieve(:valid) ActiveMerchant::Billing::CreditCard.stub(:new).and_return gateway end I also have a credit card Factory setup, but I'm not sure where or how I apply this to the stub. Thanks in advance! From dchelimsky at gmail.com Mon Oct 31 10:37:05 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 31 Oct 2011 09:37:05 -0500 Subject: [rspec-users] Specs failing when run outside Spork with TypeError: superclass mismatch for class Attribute In-Reply-To: References: Message-ID: <45B48F6D-0BEC-4B7C-88E4-FB61B17D2433@gmail.com> On Oct 31, 2011, at 4:59 AM, Jakub Arnold wrote: > When I run my specs inside spork, they all just pass without any > problems, but once I try to run them without spork, I end up with > > Failure/Error: Unable to find matching line from backtrace > TypeError: > superclass mismatch for class Attribute > > on each request spec. > > Here's a gist with the whole stack trace, request specs & > spec_helper.rb https://gist.github.com/1327141 > > I'm running Rails 3.1.1 on Ruby 1.9.2 Hey Jakub, I started to look at this yesterday but got nowhere, and it's going to be a while before I can look at it again. My theory is that there is a another Attribute class defined by one of the gems in your app, and due to differences in load order, the right one is winning when you use spork, but the wrong one is winning when when you don't. Please investigate that and report what you find back here. HTH, David From jko170 at gmail.com Mon Oct 31 14:59:02 2011 From: jko170 at gmail.com (Justin Ko) Date: Mon, 31 Oct 2011 12:59:02 -0600 Subject: [rspec-users] Noob (mock/stub) ActiveMerchant.. In-Reply-To: References: Message-ID: <6AB0B427-D65F-4648-ACEF-561EDA7BD9FC@gmail.com> On Oct 28, 2011, at 10:16 AM, internetchris wrote: > Hi Group > > I'm still waiting for the light to come on with stubbing/mocking and > the syntax for each. I have simple method in my Order class like > so.... > > def credit_card > ActiveMerchant::Billing::CreditCard.new( > :type => card_type, > :number => card_number, > :verification_value => card_verification, > :month => card_expires_on.blank? ? Time.now.month : > card_expires_on.month, > :year => card_expires_on.blank? ? Time.now.year : > card_expires_on.year, > :first_name => first_name, > :last_name => last_name > ) > end > > This method should return valid if the card is valid. > http://activemerchant.rubyforge.org/classes/ActiveMerchant/Billing/CreditCard.html > > I started out like this but then confusion set in. If anyone has the > time to help me understand or write the proper spec for this method I > think it will help me better understand how to stub or mock a 3rd > party item like this. I just watched the peepcode screencast and I've > watched the railscasts. I'm just trying to apply my meager > understanding to my own project now. > > it "should validate credit card" do > gateway = stub('gateway') > gateway.should_recieve(:valid) > ActiveMerchant::Billing::CreditCard.stub(:new).and_return > gateway > end This RSpec example has nothing to do with a gateway. Also, it is a credit card object, which does not talk to any third party service. You don't need to use any mocking here. You probably want to make sure the credit_card *can* be valid. So to do so, you'll need to create a valid user (or whatever model this credit_card method is in: describe User do describe '#credit_card' do context 'with a valid user' do let(:user) { create(:user) } it 'returns a valid credit card instance' do user.credit_card.should be_an_instance_of(ActiveMerchant::Billing::CreditCard) user.credit_card.should be_valid end end end end Now, your User factory would fill in all the credit card fields so the credit card is able to be valid. I would also check that the credit card has the correct attributes: describe User do describe '#credit_card' do context 'with a valid user' do let(:user) { create(:user, card_type: 'Visa') } describe 'the returned credit card instance' do it 'has the correct card_type' do user.credit_card.card_type.should eq('Visa') end end end end end As far as mocking third party gateway services, ActiveMerchant provides built in support to switch a gateway to its "test" mode, which you would do in your test.rb environment. ActiveMerchant has good documentation for all of this. Hope that helps. > > I also have a credit card Factory setup, but I'm not sure where or how > I apply this to the stub. > > Thanks in advance! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users