From robert.dober at gmail.com Wed Dec 1 06:57:17 2010 From: robert.dober at gmail.com (Robert Dober) Date: Wed, 1 Dec 2010 12:57:17 +0100 Subject: [rspec-users] ActionController::RoutingError Assistance In-Reply-To: References: Message-ID: On Tue, Nov 30, 2010 at 3:27 PM, Andrew Davis wrote: Andrew I am not completely sure, but this looks awfully like this: https://github.com/rspec/rspec-rails/issues#issue/273 Do you use rails3 and is criterion a route embedded into task, or any other for that matter? HTH Robert From lists at ruby-forum.com Wed Dec 1 08:29:06 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Wed, 01 Dec 2010 14:29:06 +0100 Subject: [rspec-users] ActionController::RoutingError Assistance In-Reply-To: References: Message-ID: <45417b93efba7014798b6ab9bf9d2de6@ruby-forum.com> I'm on Rails 2.3.8. A task order can have many criterion, and a criterion can have many evaluations. "/task_orders/24/criteria/13/evaluations/" Thanks! Andy -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Dec 1 09:09:24 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Dec 2010 08:09:24 -0600 Subject: [rspec-users] rspec-rails-2.2.1 is released! Message-ID: <86548AE1-AC9D-449B-B5F0-95CE9BA29CD7@gmail.com> ### rspec-rails-2.2.1 / 2010-12-01 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.2.0...v2.2.1) * Bug fixes * Depend on railties, activesupport, and actionpack instead of rails (Piotr Solnica) * Got webrat integration working properly across different types of specs * Deprecations * --webrat-matchers flag for generators is deprecated. use --webrat instead. From cremes.devlist at mac.com Wed Dec 1 09:53:36 2010 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 01 Dec 2010 08:53:36 -0600 Subject: [rspec-users] rspec-2.2 is released! In-Reply-To: <8B7F0C81-8836-4FD9-853A-7EEEB0C53709@gmail.com> References: <8B7F0C81-8836-4FD9-853A-7EEEB0C53709@gmail.com> Message-ID: <5EF59665-4F9D-4A87-AB97-B2D488779847@mac.com> On Nov 29, 2010, at 9:27 AM, David Chelimsky wrote: > On Nov 29, 2010, at 8:04 AM, Chuck Remes wrote: > >> >> On Nov 28, 2010, at 4:35 PM, David Chelimsky wrote: >> >>> ### rspec-core-2.2.0 >>> >>> >>> * Performance improvments (see [Upgrade.markdown](https://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)) >> >> Wow, the perf improvements are *much* appreciated! >> >> My test suite (MRI 1.9.2p0) with 3300 examples went from 7.4s under 2.1.0 to 3.2s with 2.2.1. Most excellent! > > Glad to hear it. My benchmarks were based on an essentially empty spec suite (so no overhead from the implementation code). Hearing that with a real app we're still getting 1k examples per second makes me very happy :) I'm assuming, however, this is not a Rails app, correct? Correct, this is not a rails app. I write straight-up ruby code. :) cr From matthewcalebsmith at gmail.com Wed Dec 1 12:30:05 2010 From: matthewcalebsmith at gmail.com (Matt Smith) Date: Wed, 1 Dec 2010 09:30:05 -0800 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 Message-ID: Hello all. Just a little frustration moment here and hoping someone can explain to me what is going on. I had a passing view spec using >= rspec-rails2. Then after updating to 2.1.0-2.2.1 it always fails. Thinking I was crazy I built the example in the rspec book, and I get the same thing. Here is the full source: https://github.com/matthewcalebsmith/rspec_issue.git If I switch out the message.stub(:title => "the title") in "it 'renders a text field for the message title' do" with assign(:message, mock_model("Message",:title => "the title").as_new_record), everything passes. Why does the stub not work anymore? Using the stub gives this: 1) messages/new.html.erb renders a text field for the message title Failure/Error: form.should have_selector("input", expected following output to contain a tag:
Note the value="Message_#<RSpec::Core::ExampleGroup::Nested_1:0x0000010312db68>", which must be why the test fails. Is this an intentional change on how stub or assign works? Much thanks! Matt Smith -- matthewcalebsmith at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Dec 1 13:17:00 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Dec 2010 12:17:00 -0600 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: Message-ID: On Dec 1, 2010, at 11:30 AM, Matt Smith wrote: > Hello all. > > Just a little frustration moment here and hoping someone can explain to me what is going on. > > I had a passing view spec using >= rspec-rails2. Then after updating to 2.1.0-2.2.1 it always fails. Thinking I was crazy I built the example in the rspec book, and I get the same thing. Here is the full source: https://github.com/matthewcalebsmith/rspec_issue.git The repo appears to be gone. Have you resolved the issue? > If I switch out the message.stub(:title => "the title") in "it 'renders a text field for the message title' do" with assign(:message, mock_model("Message",:title => "the title").as_new_record), everything passes. Why does the stub not work anymore? > > Using the stub gives this: > 1) messages/new.html.erb renders a text field for the message title > Failure/Error: form.should have_selector("input", > expected following output to contain a tag: > >
> > > Note the value="Message_#<RSpec::Core::ExampleGroup::Nested_1:0x0000010312db68>", which must be why the test fails. Is this an intentional change on how stub or assign works? > > Much thanks! > > Matt Smith > > -- > matthewcalebsmith at gmail.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From pub at kaorukobo.net Thu Dec 2 00:46:05 2010 From: pub at kaorukobo.net (Kaoru Kobo) Date: Thu, 2 Dec 2010 14:46:05 +0900 Subject: [rspec-users] Rspec2 - Absolutely brilliant! (at breaking stuff) - Is there a downgrade path ? In-Reply-To: <9b5d915c-88b8-4802-b380-d6656b32134f@f20g2000vbc.googlegroups.com> References: <9b5d915c-88b8-4802-b380-d6656b32134f@f20g2000vbc.googlegroups.com> Message-ID: <7F2E5981-A107-4ADF-94BF-68A0C36E355C@kaorukobo.net> You can uninstall RSpec2 by: gem uninstall -v '>= 2.0.0' rspec So RSpec-1 will be automatically activated. If you did 'gem cleanup', you can re-install RSpec-1 by: gem install -v '< 2.0.0' rspec ---- Antoher way, you can specify which version of RSpec to be used in your code. (If you don't use 'spec' command to launch test) Change: gem "rspec" to gem "rspec", "< 2.0.0" Best Regards. -- Kaoru Kobo http://rubygems.org/profiles/kaorukobo On 2010/12/01, at 9:13, itsterry wrote: > Just installed Rspec2 and noticed an immediate improvement in speed: > it broke all 899 passing tests on an important project in a matter of > seconds. > > Sadly, I don't have the time to work my way through the multitude > upgrade errors (it's not just one error repeated), so I tried to > remove rspec2 and the new rspec-rails and downgrade to the previous > version. > > It didn't work, and I'm still getting the following message when I > autospec: > > ************************************************************ > REMOVAL NOTICE: you are using behaviour that has been > removed from rspec-2. > > * The 'autospec' command is no longer supported. > * Please use 'autotest' insted. > > This message will be removed from a future version of rspec. > ************************************************************ > > Running autotest rather than autospec gives the following: > > Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. > > > I'm proud to be a good little BDD developer: I just don't need an > upgrade to give me headaches right now, so.... > > Does anyone have any idea how to get back to a previous Rspec version > so I can work properly again? > > > (Not saying Rspec2 isn't fantastic. I'm sure it is. I'll try to make > it work again over the Xmas break, when I have lots of hours free) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sbellware at gmail.com Thu Dec 2 02:44:35 2010 From: sbellware at gmail.com (Scott Bellware) Date: Wed, 1 Dec 2010 23:44:35 -0800 (PST) Subject: [rspec-users] Test Spies for RSpec 2 Message-ID: <0a6bb4e6-775d-41ff-aaad-ce2f5e08c708@j29g2000yqm.googlegroups.com> I've tried three test spy mocking frameworks for RSpec that I know of. Presently, all three (Not A Mock, RR, rspec-spies) don't work with RSpec 2. Does anyone have a line on any other mocking frameworks for RSpec 2 that allow the AAA style to be supported? I'm really hoping to not have to roll off everything I've learned and put into practice about test/spec structure over the past four years and fall back to traditional mocking. Any pointers to any hint of a possible solution would be greatly helpful. Many Thanks, Scott From dchelimsky at gmail.com Thu Dec 2 08:53:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Dec 2010 07:53:45 -0600 Subject: [rspec-users] Test Spies for RSpec 2 In-Reply-To: <0a6bb4e6-775d-41ff-aaad-ce2f5e08c708@j29g2000yqm.googlegroups.com> References: <0a6bb4e6-775d-41ff-aaad-ce2f5e08c708@j29g2000yqm.googlegroups.com> Message-ID: <68DE6630-29C4-4B64-B94E-E0DC9C331853@gmail.com> On Dec 2, 2010, at 1:44 AM, Scott Bellware wrote: > I've tried three test spy mocking frameworks for RSpec that I know of. > Presently, all three (Not A Mock, RR, rspec-spies) don't work with > RSpec 2. Have you contacted the maintainers of the projects that offer spies? I'm a bit surprised they haven't updated to support RSpec-2, which was in beta since March (plenty of time for downstream libs to update). > Does anyone have a line on any other mocking frameworks for RSpec 2 > that allow the AAA style to be supported? I was only aware of those three. > I'm really hoping to not have to roll off everything I've learned and > put into practice about test/spec structure over the past four years > and fall back to traditional mocking. Any pointers to any hint of a > possible solution would be greatly helpful. Have you considered contributing a patch to your preferred spy extension? The frameworks they depend on (expectations and mocks) didn't really change in any significant way, so I doubt it would be that complicated to get any of them working. FWIW, David From lists at ruby-forum.com Thu Dec 2 11:08:37 2010 From: lists at ruby-forum.com (Ollivier Robert) Date: Thu, 02 Dec 2010 17:08:37 +0100 Subject: [rspec-users] RSpec 2.x and bundler Message-ID: <9cfbc99f1c1d7f0ba04a3c0080ec3761@ruby-forum.com> I use bundler to create and manage my own Ruby gems. I recently stumble upon this really weird behaviour. If I just do "rspec spec/*" then everything is fine. If I "take test_specs", it complains that Article (see below) is not a class! The code itself is at http://dev.keltia.net/projects/news-article/ Thanks for any idea. 1168 [16:43] roberto at roberto-al:HG/news-article> rake --trace test_specs (in /Volumes/Users/roberto/Src/Perso/HG/news-article) ** Invoke test_specs (first_time) ** Execute test_specs /Volumes/Users/roberto/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S bundle exec rspec --format documentation "spec/article_spec.rb" "spec/spec_helper.rb" /Volumes/Users/roberto/Src/Perso/HG/news-article/lib/news/article.rb:28:in `': Article is not a class (TypeError) from /Volumes/Users/roberto/Src/Perso/HG/news-article/lib/news/article.rb:22:in `' from /Volumes/Users/roberto/Src/Perso/HG/news-article/spec/article_spec.rb:5:in `require' from /Volumes/Users/roberto/Src/Perso/HG/news-article/spec/article_spec.rb:5:in `' from /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/configuration.rb:317:in `load' from /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/configuration.rb:317:in `block in load_spec_files' from /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/configuration.rb:317:in `map' from /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/configuration.rb:317:in `load_spec_files' from /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/command_line.rb:18:in `run' from /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/runner.rb:55:in `run_in_process' from /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/runner.rb:46:in `run' from /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/runner.rb:10:in `block in autorun' rake aborted! ruby -S bundle exec rspec --format documentation "spec/article_spec.rb" "spec/spec_helper.rb" failed /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/rake_task.rb:139:in `rescue in block (2 levels) in initialize' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/rake_task.rb:135:in `block (2 levels) in initialize' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1112:in `verbose' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.2.0/lib/rspec/core/rake_task.rb:131:in `block in initialize' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in `call' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in `each' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in `execute' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain' /Volumes/Users/roberto/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/bin/rake:31:in `' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `load' /Volumes/Users/roberto/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `
' Rakefile: desc "Run basic specs" RSpec::Core::RakeTask.new(:test_specs) do |t| t.pattern = 'spec/**/*.rb' t.rspec_opts = '--format documentation' t.rcov_opts = %q[--exclude "spec"] t.rcov = false end -- Posted via http://www.ruby-forum.com/. From andy.koch at pc-doctor.com Thu Dec 2 14:34:52 2010 From: andy.koch at pc-doctor.com (Andy Koch) Date: Thu, 2 Dec 2010 11:34:52 -0800 (PST) Subject: [rspec-users] configuration options Message-ID: is there a listing of the Spec::Runner configuration options somewhere? I'm looking for a document (code is ok) that lists all the available options and their purpose. example, I can see from my code that these exist... Spec::Runner.configure do |config| config.use_transactional_fixtures = true config.use_instantiated_fixtures = false config.fixture_path = Rails.root + '/spec/fixtures/' end but I'm curious to see what else is available. I've googled and searched in rdoc but I can't find even these options listed. thanks From dchelimsky at gmail.com Thu Dec 2 15:08:24 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Dec 2010 14:08:24 -0600 Subject: [rspec-users] configuration options In-Reply-To: References: Message-ID: <00635BDB-72BF-473D-90EF-DB9CF1A8CF93@gmail.com> On Dec 2, 2010, at 1:34 PM, Andy Koch wrote: > is there a listing of the Spec::Runner configuration options > somewhere? For RSpec-1: http://rdoc.info/gems/rspec/1.3.1/Spec/Runner/Configuration For RSpec 2, the options get defined via metaprogramming (a great example of the downside of metaprogramming), and are not well documented. That said, if you do this: RSpec.configure do |config| p config.settings.keys end HTH, David > > I'm looking for a document (code is ok) that lists all the available > options and their purpose. > > example, > > I can see from my code that these exist... > > Spec::Runner.configure do |config| > config.use_transactional_fixtures = true > config.use_instantiated_fixtures = false > config.fixture_path = Rails.root + '/spec/fixtures/' > end > > but I'm curious to see what else is available. > > I've googled and searched in rdoc but I can't find even these options > listed. > > thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matthewcalebsmith at gmail.com Thu Dec 2 18:06:46 2010 From: matthewcalebsmith at gmail.com (Matthew Smith) Date: Thu, 2 Dec 2010 15:06:46 -0800 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 Message-ID: <1BE77C3A-F124-4BDA-BFAC-2222C85C8391@gmail.com> David, Sorry, I didn't specify what the url was for! That was the url to pull from, not the github page.... Github Page: https://github.com/matthewcalebsmith/rspec_issue git clone: https://github.com/matthewcalebsmith/rspec_issue.git git://github.com/matthewcalebsmith/rspec_issue.git By the way, I'm using 1.9.2-p0. Let me know if you have any questions. Thanks again! Matt Smith -- matthewcalebsmith at gmail.com On Dec 1, 2010, at 11:30 AM, Matt Smith wrote: > Hello all. > > Just a little frustration moment here and hoping someone can explain to me what is going on. > > I had a passing view spec using >= rspec-rails2. Then after updating to 2.1.0-2.2.1 it always fails. Thinking I was crazy I built the example in the rspec book, and I get the same thing. Here is the full source: https://github.com/matthewcalebsmith/rspec_issue.git The repo appears to be gone. Have you resolved the issue? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Dec 3 01:57:30 2010 From: lists at ruby-forum.com (Michael Bean) Date: Fri, 03 Dec 2010 07:57:30 +0100 Subject: [rspec-users] Rspec Textmate bundle errors In-Reply-To: <2E61B430-A2FC-4588-B35A-95AE51254512@kozmo.co.uk> References: <2E61B430-A2FC-4588-B35A-95AE51254512@kozmo.co.uk> Message-ID: <03ce549be25b8bd139adb69e7ee1fd06@ruby-forum.com> I am having the same problem with the lastest version 4.2.3 (and most of the other 4.2's on windows) version 3 installs fine. -- Posted via http://www.ruby-forum.com/. From zhiqiang.lei at gmail.com Fri Dec 3 06:37:53 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Fri, 3 Dec 2010 19:37:53 +0800 Subject: [rspec-users] stub! does not work Message-ID: Hi, This piece of code does not work. Does anybody know the cause? describe "/loan-events/{source-id}-lend.json" do describe "GET" do it "should call all method of LoanEvent with source_id" do source_id = rand(1000) LoanEvent.should_receive(:all).with(:source_id => source_id.to_s).once get "/loan-events/#{source_id}-lend.json" end it "should return the JSON of this LoanEvent collection" do collection = mock("collection") LoadEvent.stub!(:all).and_return(collection) collection.should_receive(:to_json).with(no_args).once get "/loan-events/#{rand(1000)}-lend.json" end end end 1) EIOU::CoreApplication /loan-events/{source-id}-lend.json GET should return the JSON of this LoanEvent collection Failure/Error: LoadEvent.should_receive(:all).and_return({}) uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_1::LoadEvent # ./spec/core_application_spec.rb:42:in `block (4 levels) in ' Best regards, Zhi-Qiang Lei zhiqiang.lei at gmail.com From dchelimsky at gmail.com Fri Dec 3 07:18:25 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Dec 2010 06:18:25 -0600 Subject: [rspec-users] stub! does not work In-Reply-To: References: Message-ID: <44252B6A-217F-4C7E-A2DF-D1E4AA947466@gmail.com> On Dec 3, 2010, at 5:37 AM, Zhi-Qiang Lei wrote: > Hi, > > This piece of code does not work. Does anybody know the cause? > > > describe "/loan-events/{source-id}-lend.json" do > describe "GET" do > it "should call all method of LoanEvent with source_id" do > source_id = rand(1000) > LoanEvent.should_receive(:all).with(:source_id => source_id.to_s).once > get "/loan-events/#{source_id}-lend.json" > end > it "should return the JSON of this LoanEvent collection" do > collection = mock("collection") > LoadEvent.stub!(:all).and_return(collection) > collection.should_receive(:to_json).with(no_args).once > get "/loan-events/#{rand(1000)}-lend.json" > end > end > end > > > 1) EIOU::CoreApplication /loan-events/{source-id}-lend.json GET should return the JSON of this LoanEvent collection > Failure/Error: LoadEvent.should_receive(:all).and_return({}) > uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_1::LoadEvent This failure message ^^ tells you exactly what the problem is. There is no constant named LoadEvent (with a 'd'). I believe you meant to type LoanEvent (with an 'n'). Cheers, David > # ./spec/core_application_spec.rb:42:in `block (4 levels) in ' > > > Best regards, > Zhi-Qiang Lei > zhiqiang.lei at gmail.com From martin.hawkins at gmail.com Fri Dec 3 12:07:19 2010 From: martin.hawkins at gmail.com (Martin Hawkins) Date: Fri, 3 Dec 2010 09:07:19 -0800 (PST) Subject: [rspec-users] Speccing a model class method in Rails produces nil Message-ID: Ruby 1.9.2, Rails 3.0.3, Rspec-rails 2.2.0 I have: Factory.define :season_date do |f| f.season_date Date.new(2011,9,24) f.date_type "season_start" end RSpec.configure do |config| config.mock_with :rspec end Factory.define :season_date do |f| f.season_date Date.new(2011,9,24) f.date_type "season_start" end Factory.define :season_date do |f| f.season_date Date.new(2011,9,24) f.date_type "season_start" end require 'spec_helper' describe SeasonDate do before(:each) do @start_date_record = Factory.create(:season_date) @no_play_date_record = Factory.create(:season_date, season_date: Date.today, date_type: "no_play") end it "responds to the find_start_record method call" do SeasonDate.should respond_to(:find_start_record) end it "returns the record with the season start date" do SeasonDate.find_start_record.should == @start_date_record end end and I get rspec -f d -b spec/models/season_date_spec.rb SeasonDate responds to the find_start_record method call returns the record with the season start date (FAILED - 1) Failures: 1) SeasonDate returns the record with the season start date Failure/Error: SeasonDate.find_start_record.should == @start_date_record expected: #, got: nil (using ==) I'm doing something dumb, but I don't know what. Any assistance much appreciated! From lists at ruby-forum.com Fri Dec 3 17:55:06 2010 From: lists at ruby-forum.com (Ernst Arnold) Date: Fri, 03 Dec 2010 23:55:06 +0100 Subject: [rspec-users] [Sinatra] "tried to create Proc object without a block" In-Reply-To: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> References: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> Message-ID: I get the same error message as Jason. However installing rack-test did not help in my case. (I am new to Ruby, and don't yet know how to use the debugger) Tried with rvm use 1.9.2 and rvm use 1.8.7 Generally I am a bit disappointed that the code from the book needed a number of changes to get even this far. Ernst -- Posted via http://www.ruby-forum.com/. From jtanium at gmail.com Fri Dec 3 18:12:42 2010 From: jtanium at gmail.com (Jason Edwards) Date: Fri, 3 Dec 2010 16:12:42 -0700 Subject: [rspec-users] [Sinatra] "tried to create Proc object without a block" In-Reply-To: References: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> Message-ID: Yeah, that's a major pain... I put my stuff up here: https://gist.github.com/720605 And later on I found: https://github.com/pauldix/service-oriented-design-with-ruby I tried to include comments about what I changed to get it to work. When I found pauldix's, it looked like he had made pretty much all the same changes I had. If my Gist and the GitHub project don't help, post your code... Jason On Fri, Dec 3, 2010 at 3:55 PM, Ernst Arnold wrote: > I get the same error message as Jason. However installing rack-test did > not help in my case. (I am new to Ruby, and don't yet know how to use > the debugger) > > Tried with rvm use 1.9.2 and rvm use 1.8.7 > > Generally I am a bit disappointed that the code from the book needed a > number of changes to get even this far. > > Ernst > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From martin at volerich.com Thu Dec 2 11:12:33 2010 From: martin at volerich.com (Martin Volerich) Date: Thu, 2 Dec 2010 16:12:33 +0000 Subject: [rspec-users] Rspec2 and autotest Message-ID: David: Glad to see that your book was just published. It's been a life-changing read! I'm struggling with the best way to integrate autotest working in a rails project with RSpec 2. The latest autotest 4.4.6 gem seems to retire it as a standalone gem and go back to ZenTest - which I assume doesn't work with RSpec (although I may be wrong). Reverting to autotest 4.4.5 got me back up and running. What's the longer term strategy? watchr? Thanks Martin Volerich -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky.log0 at gmail.com Thu Dec 2 05:31:03 2010 From: ky.log0 at gmail.com (Log0) Date: Thu, 2 Dec 2010 18:31:03 +0800 Subject: [rspec-users] Meaningless stacktrace on RSpec error (no line of error) Message-ID: Hi all, I am new to RSpec, currently using rspec-rails (2.1.0) with rails (2.2.3) and ruby (1.8.7). I can get RSpec running however the stacktrace when it happened is pretty uninformative, always not including the line in which the assertion failed. I tried to google around for some keywords but doesn't seem to yield anything. Could someone please advice on what can I do to post more informative stacktrace and results? Thanks. ========================================================================= 1) 'OrderManager should create an order successfully and returns it if enough information is given' FAILED expected not: == nil, got: nil /home/web/www/bh2/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb:41:in `fail_with' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb:39:in `fail_with_message' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb:72:in `__delegate_operator' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb:51:in `eval_match' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb:29:in `==' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_methods.rb:40:in `instance_eval' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_methods.rb:40:in `execute' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_methods.rb:37:in `execute' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:214:in `run_examples' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:212:in `each' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:212:in `run_examples' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:103:in `run' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:23:in `run' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:22:in `each' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:22:in `run' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/options.rb:151:in `run_examples' /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/command_line.rb:9:in `run' script/spec:10: Finished in 0.132014 seconds ========================================================================= Thank you. -- Best Regards Eric Chio -------------- next part -------------- An HTML attachment was scrubbed... URL: From pzolnierek at gmail.com Thu Dec 2 05:53:37 2010 From: pzolnierek at gmail.com (Piotr Zolnierek) Date: Thu, 2 Dec 2010 02:53:37 -0800 (PST) Subject: [rspec-users] Metadata about formatter being used accessible in spec? Message-ID: Is it possible to read which formatter is being used? For instance if - f d is used to output additional information or is there a better way to do that? From andreas.schacke at gmail.com Thu Dec 2 05:20:47 2010 From: andreas.schacke at gmail.com (Andi Schacke) Date: Thu, 2 Dec 2010 02:20:47 -0800 (PST) Subject: [rspec-users] Global before blocks - filtering by multiple types Message-ID: Hi in the config block of rspec I have a before block to reset my database before each spec: config.before(:each) {DatabaseCleaner.clean} I know I can apply this before to a specific type, e.g. config.before(:each, :type => :model) {DatabaseCleaner.clean} but what I want to achieve is that the database is cleaned for all specs except acceptance specs. Is there a way to define this, e.g. something like: config.before(:each, :except => :acceptance) {DatabaseCleaner.clean} or maybe config.before(:each, :type => [:model, :view, :controller]) {DatabaseCleaner.clean} Thanks Andi From elitwin at rocketmail.com Wed Dec 1 11:43:36 2010 From: elitwin at rocketmail.com (E. Litwin) Date: Wed, 1 Dec 2010 08:43:36 -0800 (PST) Subject: [rspec-users] Routes are not recognized in request specs after upgrading to 2.2 Message-ID: <165cce59-06a5-46ab-8702-f159baf47317@d8g2000yqf.googlegroups.com> I'm getting undefined local variable or method `users_path' (as an example) my request spec tests after upgrading to 2.2.0 from 2.1.0. I haven't really changed these tests from the generated code but am curious as to why they are failing now. require 'spec_helper' describe "Users" do describe "GET /users" do it "works! (now write some real specs)" do get users_path end end end I followed the upgrade steps to regenerate spec_helper.rb (it was identical), so I'm not sure what I am missing. From erik.helin at gmail.com Wed Dec 1 00:47:50 2010 From: erik.helin at gmail.com (helino) Date: Tue, 30 Nov 2010 21:47:50 -0800 (PST) Subject: [rspec-users] How can I use nested "before" functions? Message-ID: <7ee0b47b-9bb3-44cc-a488-784b51e3bb26@c17g2000prm.googlegroups.com> Hi everyone, I've started learning Ruby and RSpec, and I've ran into a small problem. I have one "before" functions which run before all my descriptions and the context in the spec, and then I have another "before" function inside a context, which is set to run once before all the "it" inside that context. My problems is that the outer "before" does not run prior to the "before" inside my context. This creates an error, since the "before" inside the context relies on a variable being created in the outmost "before". Is this how it is supposed to be, or am I doing something wrong? Gists: * "rspec spec --backtrace" output: https://gist.github.com/723021 * router.rb: https://gist.github.com/723020 * router_spec.rb: https://gist.github.com/723015 I'm using Ruby version 1.9.2p0 with rvm on Mac OS X 10.6.5 and RSpec 2.1.0. Thanks for a wonderful framework! Best regards, Erik From matt at mattwynne.net Fri Dec 3 19:43:58 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 4 Dec 2010 00:43:58 +0000 Subject: [rspec-users] How can I use nested "before" functions? In-Reply-To: <7ee0b47b-9bb3-44cc-a488-784b51e3bb26@c17g2000prm.googlegroups.com> References: <7ee0b47b-9bb3-44cc-a488-784b51e3bb26@c17g2000prm.googlegroups.com> Message-ID: <02A9E085-A429-406D-B000-9D911921E906@mattwynne.net> On 1 Dec 2010, at 05:47, helino wrote: > Hi everyone, > > I've started learning Ruby and RSpec, and I've ran into a small > problem. I have one "before" functions which run before all my > descriptions and the context in the spec, and then I have another > "before" function inside a context, which is set to run once before > all the "it" inside that context. > > My problems is that the outer "before" does not run prior to the > "before" inside my context. This creates an error, since the "before" > inside the context relies on a variable being created in the outmost > "before". > > Is this how it is supposed to be, or am I doing something wrong? > > Gists: > * "rspec spec --backtrace" output: https://gist.github.com/723021 > * router.rb: https://gist.github.com/723020 > * router_spec.rb: https://gist.github.com/723015 You're getting before(:each) and before(:all) mixed up. before(:each) is the default. You really don't want to use before(:all) in anything but exceptional circumstances. Right now you have a mix of the two, which I think it why you're getting the suprising behaviour. > > I'm using Ruby version 1.9.2p0 with rvm on Mac OS X 10.6.5 and RSpec > 2.1.0. > > Thanks for a wonderful framework! > > Best regards, > Erik > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From lists at ruby-forum.com Fri Dec 3 19:55:13 2010 From: lists at ruby-forum.com (Ernst Arnold) Date: Sat, 04 Dec 2010 01:55:13 +0100 Subject: [rspec-users] [Sinatra] "tried to create Proc object without a block" In-Reply-To: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> References: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> Message-ID: I adapted the first lines of service_spec.rb according to Jason's code: require File.dirname(__FILE__) + '/../service' require 'rspec' # was 'spec' (Jason) #require 'spec/interop/test' # no idea what this was require 'rack/test' require 'test/unit' # gem install test-unit require 'sinatra' require 'json' set :environment, :test Test::Unit::TestCase.send :include, Rack::Test::Methods RSpec.configure do |conf| #from Jason conf.include Rack::Test::Methods end Also needed to replace JSON.parse(last_response.body) with JSON.parse(last_response.body)["user"] At last rspec spec/service_spec.rb passes ruby service.rb -p 3000 seems to work but telnet locahost 3000 never connects Thank you for sharing your code. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Dec 3 20:57:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Dec 2010 19:57:54 -0600 Subject: [rspec-users] Global before blocks - filtering by multiple types In-Reply-To: References: Message-ID: <2BE590AB-B803-4DEE-8C26-FF736E77E0C7@gmail.com> On Dec 2, 2010, at 4:20 AM, Andi Schacke wrote: > Hi > > in the config block of rspec I have a before block to reset my > database before each spec: > > config.before(:each) {DatabaseCleaner.clean} > > I know I can apply this before to a specific type, e.g. > > config.before(:each, :type => :model) {DatabaseCleaner.clean} > > but what I want to achieve is that the database is cleaned for all > specs except acceptance specs. Is there a way to define this, e.g. > something like: > > config.before(:each, :except => :acceptance) {DatabaseCleaner.clean} > or maybe > config.before(:each, :type => [:model, :view, :controller]) > {DatabaseCleaner.clean} Not exactly, but there is another way: config.before(:each) do DatabaseCleaner.clean unless example.metadata[:type] == :acceptance end HTH, David From dchelimsky at gmail.com Fri Dec 3 21:02:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Dec 2010 20:02:03 -0600 Subject: [rspec-users] Meaningless stacktrace on RSpec error (no line of error) In-Reply-To: References: Message-ID: <606E2315-FBB6-44F1-990F-4785B1354AA8@gmail.com> On Dec 2, 2010, at 4:31 AM, Log0 wrote: > Hi all, > > I am new to RSpec, currently using rspec-rails (2.1.0) with rails (2.2.3) For rails-2 you need to use rspec-rails-1.3.1 (rspec-rails-2.x supports only rails ~> 3.0). > and ruby (1.8.7). I can get RSpec running however the stacktrace when it happened is pretty uninformative, always not including the line in which the assertion failed. I tried to google around for some keywords but doesn't seem to yield anything. > > Could someone please advice on what can I do to post more informative stacktrace and results? Thanks. > > ========================================================================= > 1) > 'OrderManager should create an order successfully and returns it if enough information is given' FAILED > expected not: == nil, > got: nil > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb:41:in `fail_with' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb:39:in `fail_with_message' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb:72:in `__delegate_operator' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb:51:in `eval_match' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb:29:in `==' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_methods.rb:40:in `instance_eval' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_methods.rb:40:in `execute' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_methods.rb:37:in `execute' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:214:in `run_examples' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:212:in `each' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:212:in `run_examples' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:103:in `run' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:23:in `run' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:22:in `each' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:22:in `run' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/options.rb:151:in `run_examples' > /home/web/www/bh2/vendor/plugins/rspec/lib/spec/runner/command_line.rb:9:in `run' > script/spec:10: The backtrace suggests that you're actually using rspec-1 as a plugin. I'd strongly recommend that you remove the plugin and configure your app to use use rspec-rails-1.3.3 and rspec-1.3.1 gems instead. One reason is there is no easy way to tell which version of the rspec plugin you have installed. Cheers, David > > Finished in 0.132014 seconds > ========================================================================= > > Thank you. > > -- > Best Regards > Eric Chio > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Dec 3 21:07:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Dec 2010 20:07:58 -0600 Subject: [rspec-users] Routes are not recognized in request specs after upgrading to 2.2 In-Reply-To: <377a1fd1-7135-41cc-a4eb-3cc77b6e5bce@p7g2000prb.googlegroups.com> References: <377a1fd1-7135-41cc-a4eb-3cc77b6e5bce@p7g2000prb.googlegroups.com> Message-ID: On Nov 29, 2010, at 2:24 PM, E. Litwin wrote: > I'm getting undefined local variable or method `users_path' (as an > example) my request spec tests after upgrading to 2.2.0 from 2.1.0. Grab the rspec-rails-2.2.1 release, which fixed a bug that I think, as a side-effect, will resolve your issue. Cheers, David > > I haven't really changed these tests from the generated code but am > curious as to why they are failing now. > > require 'spec_helper' > > describe "Users" do > describe "GET /users" do > it "works! (now write some real specs)" do > get users_path > end > end > end > > I followed the upgrade steps to regenerate spec_helper.rb (it was > identical), so I'm not sure what I am missing. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Dec 3 21:10:07 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Dec 2010 20:10:07 -0600 Subject: [rspec-users] Rspec2 and autotest In-Reply-To: References: Message-ID: <8F4A7690-11CD-41D5-B32E-3C93BD8E6C8F@gmail.com> On Dec 2, 2010, at 10:12 AM, Martin Volerich wrote: > David: > > Glad to see that your book was just published. It's been a life-changing read! > > I'm struggling with the best way to integrate autotest working in a rails project with RSpec 2. The latest autotest 4.4.6 gem seems to retire it as a standalone gem and go back to ZenTest - which I assume doesn't work with RSpec (although I may be wrong). > > Reverting to autotest 4.4.5 got me back up and running. > > What's the longer term strategy? watchr? > Haven't had time to look at recent changes to autotest. Lately I've been using guard: https://github.com/guard/guard-rspec https://github.com/guard/guard HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From erik.helin at gmail.com Fri Dec 3 21:11:15 2010 From: erik.helin at gmail.com (Erik Helin) Date: Fri, 3 Dec 2010 18:11:15 -0800 Subject: [rspec-users] How can I use nested "before" functions? In-Reply-To: <02A9E085-A429-406D-B000-9D911921E906@mattwynne.net> References: <7ee0b47b-9bb3-44cc-a488-784b51e3bb26@c17g2000prm.googlegroups.com> <02A9E085-A429-406D-B000-9D911921E906@mattwynne.net> Message-ID: On Fri, Dec 3, 2010 at 16:43, Matt Wynne wrote: > > On 1 Dec 2010, at 05:47, helino wrote: > > > Hi everyone, > > > > I've started learning Ruby and RSpec, and I've ran into a small > > problem. I have one "before" functions which run before all my > > descriptions and the context in the spec, and then I have another > > "before" function inside a context, which is set to run once before > > all the "it" inside that context. > > > > My problems is that the outer "before" does not run prior to the > > "before" inside my context. This creates an error, since the "before" > > inside the context relies on a variable being created in the outmost > > "before". > > > > Is this how it is supposed to be, or am I doing something wrong? > > > > Gists: > > * "rspec spec --backtrace" output: https://gist.github.com/723021 > > * router.rb: https://gist.github.com/723020 > > * router_spec.rb: https://gist.github.com/723015 > > You're getting before(:each) and before(:all) mixed up. > > before(:each) is the default. You really don't want to use before(:all) in > anything but exceptional circumstances. Right now you have a mix of the two, > which I think it why you're getting the suprising behaviour. > I know that I'm mixing before(:each) and before(:all). What I'm wondering is the rules for how they interact? Are then any "scoping" rules in RSpec? I think that it makes sense that a before(:all) defined in a context on which a before(:each) is already applied gets run after the before(:each) has run, but that's just my opinion. > > > > > I'm using Ruby version 1.9.2p0 with rvm on Mac OS X 10.6.5 and RSpec > > 2.1.0. > > > > Thanks for a wonderful framework! > > > > Best regards, > > Erik > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Thanks for your answer! Erik -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Dec 3 21:15:52 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Dec 2010 20:15:52 -0600 Subject: [rspec-users] Metadata about formatter being used accessible in spec? In-Reply-To: References: Message-ID: <3A9040AB-0E07-40F2-9607-E3331D7A850B@gmail.com> On Dec 2, 2010, at 4:53 AM, Piotr Zolnierek wrote: > Is it possible to read which formatter is being used? For instance if - > f d is used to output additional information or is there a better way > to do that? For now you can get it from RSpec.configuration.formatter, but that is a) unofficial and b) likely to change in future versions when rspec-core supports multiple formatters. What sort of info are you trying to output? From dchelimsky at gmail.com Fri Dec 3 21:25:06 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Dec 2010 20:25:06 -0600 Subject: [rspec-users] Speccing a model class method in Rails produces nil In-Reply-To: References: Message-ID: On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: > Ruby 1.9.2, Rails 3.0.3, Rspec-rails 2.2.0 > > I have: > > Factory.define :season_date do |f| > f.season_date Date.new(2011,9,24) > f.date_type "season_start" > end > > RSpec.configure do |config| > config.mock_with :rspec > end > > Factory.define :season_date do |f| > f.season_date Date.new(2011,9,24) > f.date_type "season_start" > end > > Factory.define :season_date do |f| > f.season_date Date.new(2011,9,24) > f.date_type "season_start" > end Do you actually have 3 identical factories or was that just a copy/paste error? > require 'spec_helper' > describe SeasonDate do > before(:each) do > @start_date_record = Factory.create(:season_date) > @no_play_date_record = Factory.create(:season_date, season_date: Date.today, date_type: "no_play") > end > it "responds to the find_start_record method call" do > SeasonDate.should respond_to(:find_start_record) > end > it "returns the record with the season start date" do > SeasonDate.find_start_record.should == @start_date_record The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. > end > end > > and I get > > rspec -f d -b spec/models/season_date_spec.rb > SeasonDate > responds to the find_start_record method call > returns the record with the season start date (FAILED - 1) > > Failures: > > 1) SeasonDate returns the record with the season start date > Failure/Error: SeasonDate.find_start_record.should == > @start_date_record > expected: # date_type: "season_start", created_at: "2010-12-03 17:03:58", > updated_at: "2010-12-03 17:03:58">, > got: nil (using ==) > > I'm doing something dumb, but I don't know what. Any assistance much > appreciated! Can't really tell from what you've posted. Please post the implementation of SeasonDate.season_date. From dchelimsky at gmail.com Fri Dec 3 21:54:51 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Dec 2010 20:54:51 -0600 Subject: [rspec-users] How can I use nested "before" functions? In-Reply-To: References: <7ee0b47b-9bb3-44cc-a488-784b51e3bb26@c17g2000prm.googlegroups.com> <02A9E085-A429-406D-B000-9D911921E906@mattwynne.net> Message-ID: On Dec 3, 2010, at 8:11 PM, Erik Helin wrote: > > > On Fri, Dec 3, 2010 at 16:43, Matt Wynne wrote: > > On 1 Dec 2010, at 05:47, helino wrote: > > > Hi everyone, > > > > I've started learning Ruby and RSpec, and I've ran into a small > > problem. I have one "before" functions which run before all my > > descriptions and the context in the spec, and then I have another > > "before" function inside a context, which is set to run once before > > all the "it" inside that context. > > > > My problems is that the outer "before" does not run prior to the > > "before" inside my context. This creates an error, since the "before" > > inside the context relies on a variable being created in the outmost > > "before". > > > > Is this how it is supposed to be, or am I doing something wrong? > > > > Gists: > > * "rspec spec --backtrace" output: https://gist.github.com/723021 > > * router.rb: https://gist.github.com/723020 > > * router_spec.rb: https://gist.github.com/723015 > > You're getting before(:each) and before(:all) mixed up. > > before(:each) is the default. You really don't want to use before(:all) in anything but exceptional circumstances. Right now you have a mix of the two, which I think it why you're getting the suprising behaviour. > > I know that I'm mixing before(:each) and before(:all). What I'm wondering is the rules for how they interact? Are then any "scoping" rules in RSpec? Yep: http://relishapp.com/rspec/rspec-core/v/2-2/dir/hooks/before-and-after-hooks > I think that it makes sense that a before(:all) defined in a context on which a before(:each) is already applied gets run after the before(:each) has run, but that's just my opinion. It's a combination of scoping and ordering, but what you ask runs counter to the rules we have in place. As Matt pointed out, before(:all) is really intended for exceptional circumstances. Also, before(:each)'s are inherited, while before(:all)'s are not (they are only run once). Consider: describe "outer" do before(:all) { puts "outer before all" } before(:each) { puts "outer before each" } example { puts "outer example 1" } example { puts "outer example 2" } after(:each) { puts "outer after each" } after(:all) { puts "outer after all" } context "inner" do before(:all) { puts "inner before all" } before(:each) { puts "inner before each" } example { puts "inner example 1" } example { puts "inner example 2" } after(:each) { puts "inner after each" } after(:all) { puts "inner after all" } end end Here's the output reflecting the order (w/ spacing to provide some context): outer before all outer before each outer example 1 outer after each outer before each outer example 2 outer after each inner before all outer before each inner before each inner example 1 inner after each outer after each outer before each inner before each inner example 2 inner after each outer after each inner after all outer after all That all make sense? Cheers, David > > > > I'm using Ruby version 1.9.2p0 with rvm on Mac OS X 10.6.5 and RSpec > > 2.1.0. > > > > Thanks for a wonderful framework! > > > > Best regards, > > Erik > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Thanks for your answer! > Erik > > _______________________________________________ > 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 wolfmanjm at gmail.com Sat Dec 4 06:07:40 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Sat, 4 Dec 2010 03:07:40 -0800 (PST) Subject: [rspec-users] controller_name replacement? Message-ID: <088d6f6d-3eab-40e6-a15b-b9ef23288cb4@f21g2000prn.googlegroups.com> This his been discussed but the only definitive answer (kinda) was use... describe "a description" do system { SomeController } end However when I do that I get this error... @controller is nil: make sure you set it in your test's setup method. I used to use controller_name :somecontroller in older versions but that does not exist anymore. Thanks Using rspec-core (2.2.1) Using rspec-expectations (2.2.0) Using rspec-mocks (2.2.0) Using rspec (2.2.0) Using rspec-rails (2.2.1) Using webrat (0.7.2) with rails 3.0.3 From lists at ruby-forum.com Sat Dec 4 06:25:53 2010 From: lists at ruby-forum.com (Ernst Arnold) Date: Sat, 04 Dec 2010 12:25:53 +0100 Subject: [rspec-users] [Sinatra] "tried to create Proc object without a block" In-Reply-To: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> References: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> Message-ID: <14d404029dc9053e6471c62720c54ab7@ruby-forum.com> Oops it connects. That was my firewall blocking 3000, sorry. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sat Dec 4 06:38:46 2010 From: lists at ruby-forum.com (Ernst Arnold) Date: Sat, 04 Dec 2010 12:38:46 +0100 Subject: [rspec-users] [Sinatra] "tried to create Proc object without a block" In-Reply-To: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> References: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> Message-ID: Next step, testing the client: rspec spec/client_spec.rb /home/ernsta/.rvm/gems/ruby-1.9.2-p0/gems/typhoeus-0.2.0/lib/typhoeus/multi.rb:21: [BUG] Segmentation fault ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux] -- Posted via http://www.ruby-forum.com/. From martin.hawkins at gmail.com Sat Dec 4 09:34:35 2010 From: martin.hawkins at gmail.com (Martin Hawkins) Date: Sat, 4 Dec 2010 06:34:35 -0800 (PST) Subject: [rspec-users] Speccing a model class method in Rails produces nil In-Reply-To: References: Message-ID: <1c1a5362-c802-4a21-9a3c-92807ff65139@i25g2000prd.googlegroups.com> I can't believe I did that... No, there is only one Factory; copy and paste error. The SeasonDate class is: class SeasonDate < ActiveRecord::Base def self.find_start_record where(["date_type = ?", "start_date"]).first end end Agreed regarding the redundant test - I just put that in when things went wrong. Thanks for responding On Dec 4, 2:25?am, David Chelimsky wrote: > On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: > > > > > > > Ruby 1.9.2, Rails 3.0.3, Rspec-rails 2.2.0 > > > I have: > > > Factory.define :season_date do |f| > > ?f.season_date Date.new(2011,9,24) > > ?f.date_type "season_start" > > end > > > RSpec.configure do |config| > > ?config.mock_with :rspec > > end > > > Factory.define :season_date do |f| > > ?f.season_date Date.new(2011,9,24) > > ?f.date_type "season_start" > > end > > > Factory.define :season_date do |f| > > ?f.season_date Date.new(2011,9,24) > > ?f.date_type "season_start" > > end > > Do you actually have 3 identical factories or was that just a copy/paste error? > > > require 'spec_helper' > > describe SeasonDate do > > ?before(:each) do > > ? ?@start_date_record = Factory.create(:season_date) > > ? ?@no_play_date_record = Factory.create(:season_date, season_date: Date.today, date_type: "no_play") > > ?end > > ?it "responds to the find_start_record method call" do > > ? ?SeasonDate.should respond_to(:find_start_record) > > ?end > > ?it "returns the record with the season start date" do > > ? ?SeasonDate.find_start_record.should == @start_date_record > > The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. > > > > > > > ?end > > end > > > and I get > > > rspec -f d -b spec/models/season_date_spec.rb > > SeasonDate > > ?responds to the find_start_record method call > > ?returns the record with the season start date (FAILED - 1) > > > Failures: > > > ?1) SeasonDate returns the record with the season start date > > ? ? Failure/Error: SeasonDate.find_start_record.should == > > @start_date_record > > ? ? expected: # > date_type: "season_start", created_at: "2010-12-03 17:03:58", > > updated_at: "2010-12-03 17:03:58">, > > ? ? ? ? ?got: nil (using ==) > > > I'm doing something dumb, but I don't know what. Any assistance much > > appreciated! > > Can't really tell from what you've posted. Please post the implementation of SeasonDate.season_date. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From martin.hawkins at gmail.com Sat Dec 4 09:58:46 2010 From: martin.hawkins at gmail.com (Martin Hawkins) Date: Sat, 4 Dec 2010 06:58:46 -0800 (PST) Subject: [rspec-users] Speccing a model class method in Rails produces nil In-Reply-To: References: Message-ID: <553f3818-7d35-4eea-b7b4-002aea9995c8@o23g2000prh.googlegroups.com> Apologies if this is a repeat post but google seemed to ignore my last effort. There is only one Factory - copy, paste and editing error. I can't believe that I didn't include the code being tested... class SeasonDate < ActiveRecord::Base def self.find_start_record where(["date_type = ?", "start_date"]).first end end Agreed re redundant test - I put that in when the 'real' test failed. On Dec 4, 2:25?am, David Chelimsky wrote: > On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: > > > > > > > Ruby 1.9.2, Rails 3.0.3, Rspec-rails 2.2.0 > > > I have: > > > Factory.define :season_date do |f| > > ?f.season_date Date.new(2011,9,24) > > ?f.date_type "season_start" > > end > > > RSpec.configure do |config| > > ?config.mock_with :rspec > > end > > > Factory.define :season_date do |f| > > ?f.season_date Date.new(2011,9,24) > > ?f.date_type "season_start" > > end > > > Factory.define :season_date do |f| > > ?f.season_date Date.new(2011,9,24) > > ?f.date_type "season_start" > > end > > Do you actually have 3 identical factories or was that just a copy/paste error? > > > require 'spec_helper' > > describe SeasonDate do > > ?before(:each) do > > ? ?@start_date_record = Factory.create(:season_date) > > ? ?@no_play_date_record = Factory.create(:season_date, season_date: Date.today, date_type: "no_play") > > ?end > > ?it "responds to the find_start_record method call" do > > ? ?SeasonDate.should respond_to(:find_start_record) > > ?end > > ?it "returns the record with the season start date" do > > ? ?SeasonDate.find_start_record.should == @start_date_record > > The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. > > > > > > > ?end > > end > > > and I get > > > rspec -f d -b spec/models/season_date_spec.rb > > SeasonDate > > ?responds to the find_start_record method call > > ?returns the record with the season start date (FAILED - 1) > > > Failures: > > > ?1) SeasonDate returns the record with the season start date > > ? ? Failure/Error: SeasonDate.find_start_record.should == > > @start_date_record > > ? ? expected: # > date_type: "season_start", created_at: "2010-12-03 17:03:58", > > updated_at: "2010-12-03 17:03:58">, > > ? ? ? ? ?got: nil (using ==) > > > I'm doing something dumb, but I don't know what. Any assistance much > > appreciated! > > Can't really tell from what you've posted. Please post the implementation of SeasonDate.season_date. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sat Dec 4 10:20:47 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Dec 2010 09:20:47 -0600 Subject: [rspec-users] controller_name replacement? In-Reply-To: <088d6f6d-3eab-40e6-a15b-b9ef23288cb4@f21g2000prn.googlegroups.com> References: <088d6f6d-3eab-40e6-a15b-b9ef23288cb4@f21g2000prn.googlegroups.com> Message-ID: On Sat, Dec 4, 2010 at 5:07 AM, Jim Morris wrote: > This his been discussed but the only definitive answer (kinda) was > use... > > ?describe "a description" do > ? system { SomeController } subject {SomeController.new} HTH, David > > ?end > > However when I do that I get this error... > > @controller is nil: make sure you set it in your test's setup method. > > I used to use controller_name :somecontroller in older versions but > that does not exist anymore. > > Thanks > > Using rspec-core (2.2.1) > Using rspec-expectations (2.2.0) > Using rspec-mocks (2.2.0) > Using rspec (2.2.0) > Using rspec-rails (2.2.1) > Using webrat (0.7.2) > > with rails 3.0.3 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Dec 4 11:04:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Dec 2010 10:04:45 -0600 Subject: [rspec-users] Speccing a model class method in Rails produces nil In-Reply-To: <1c1a5362-c802-4a21-9a3c-92807ff65139@i25g2000prd.googlegroups.com> References: <1c1a5362-c802-4a21-9a3c-92807ff65139@i25g2000prd.googlegroups.com> Message-ID: On Sat, Dec 4, 2010 at 8:34 AM, Martin Hawkins wrote: > I can't believe I did that... > No, there is only one Factory; copy and paste error. The SeasonDate > class is: > class SeasonDate < ActiveRecord::Base > ?def self.find_start_record > ? ?where(["date_type = ?", "start_date"]).first I think the problem is "start_date" vs "season_start". The factory says: Factory.define :season_date do |f| f.season_date Date.new(2011,9,24) f.date_type "season_start" end date_type == "start_date" # in the implementation date_type == "season_start" # in the factory HTH, David > ?end > end > Agreed regarding the redundant test - I just put that in when things > went wrong. > Thanks for responding > > On Dec 4, 2:25?am, David Chelimsky wrote: >> On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: >> >> >> >> >> >> > Ruby 1.9.2, Rails 3.0.3, Rspec-rails 2.2.0 >> >> > I have: >> >> > Factory.define :season_date do |f| >> > ?f.season_date Date.new(2011,9,24) >> > ?f.date_type "season_start" >> > end >> >> > RSpec.configure do |config| >> > ?config.mock_with :rspec >> > end >> >> > Factory.define :season_date do |f| >> > ?f.season_date Date.new(2011,9,24) >> > ?f.date_type "season_start" >> > end >> >> > Factory.define :season_date do |f| >> > ?f.season_date Date.new(2011,9,24) >> > ?f.date_type "season_start" >> > end >> >> Do you actually have 3 identical factories or was that just a copy/paste error? >> >> > require 'spec_helper' >> > describe SeasonDate do >> > ?before(:each) do >> > ? ?@start_date_record = Factory.create(:season_date) >> > ? ?@no_play_date_record = Factory.create(:season_date, season_date: Date.today, date_type: "no_play") >> > ?end >> > ?it "responds to the find_start_record method call" do >> > ? ?SeasonDate.should respond_to(:find_start_record) >> > ?end >> > ?it "returns the record with the season start date" do >> > ? ?SeasonDate.find_start_record.should == @start_date_record >> >> The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. >> >> >> >> >> >> > ?end >> > end >> >> > and I get >> >> > rspec -f d -b spec/models/season_date_spec.rb >> > SeasonDate >> > ?responds to the find_start_record method call >> > ?returns the record with the season start date (FAILED - 1) >> >> > Failures: >> >> > ?1) SeasonDate returns the record with the season start date >> > ? ? Failure/Error: SeasonDate.find_start_record.should == >> > @start_date_record >> > ? ? expected: #> > date_type: "season_start", created_at: "2010-12-03 17:03:58", >> > updated_at: "2010-12-03 17:03:58">, >> > ? ? ? ? ?got: nil (using ==) >> >> > I'm doing something dumb, but I don't know what. Any assistance much >> > appreciated! >> >> Can't really tell from what you've posted. Please post the implementation of SeasonDate.season_date. >> _______________________________________________ >> 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 martin.hawkins at gmail.com Sat Dec 4 13:33:36 2010 From: martin.hawkins at gmail.com (Martin Hawkins) Date: Sat, 4 Dec 2010 10:33:36 -0800 (PST) Subject: [rspec-users] Speccing a model class method in Rails produces nil In-Reply-To: References: <1c1a5362-c802-4a21-9a3c-92807ff65139@i25g2000prd.googlegroups.com> Message-ID: I can't believe I did that either... Doh! On Dec 4, 4:04?pm, David Chelimsky wrote: > On Sat, Dec 4, 2010 at 8:34 AM, Martin Hawkins wrote: > > I can't believe I did that... > > No, there is only one Factory; copy and paste error. The SeasonDate > > class is: > > class SeasonDate < ActiveRecord::Base > > ?def self.find_start_record > > ? ?where(["date_type = ?", "start_date"]).first > > I think the problem is "start_date" vs "season_start". The factory says: > > Factory.define :season_date do |f| > ?f.season_date Date.new(2011,9,24) > ?f.date_type "season_start" > end > > date_type == "start_date" # in the implementation > date_type == "season_start" # in the factory > > HTH, > David > > > > > > > ?end > > end > > Agreed regarding the redundant test - I just put that in when things > > went wrong. > > Thanks for responding > > > On Dec 4, 2:25?am, David Chelimsky wrote: > >> On Dec 3, 2010, at 11:07 AM, Martin Hawkins wrote: > > >> > Ruby 1.9.2, Rails 3.0.3, Rspec-rails 2.2.0 > > >> > I have: > > >> > Factory.define :season_date do |f| > >> > ?f.season_date Date.new(2011,9,24) > >> > ?f.date_type "season_start" > >> > end > > >> > RSpec.configure do |config| > >> > ?config.mock_with :rspec > >> > end > > >> > Factory.define :season_date do |f| > >> > ?f.season_date Date.new(2011,9,24) > >> > ?f.date_type "season_start" > >> > end > > >> > Factory.define :season_date do |f| > >> > ?f.season_date Date.new(2011,9,24) > >> > ?f.date_type "season_start" > >> > end > > >> Do you actually have 3 identical factories or was that just a copy/paste error? > > >> > require 'spec_helper' > >> > describe SeasonDate do > >> > ?before(:each) do > >> > ? ?@start_date_record = Factory.create(:season_date) > >> > ? ?@no_play_date_record = Factory.create(:season_date, season_date: Date.today, date_type: "no_play") > >> > ?end > >> > ?it "responds to the find_start_record method call" do > >> > ? ?SeasonDate.should respond_to(:find_start_record) > >> > ?end > >> > ?it "returns the record with the season start date" do > >> > ? ?SeasonDate.find_start_record.should == @start_date_record > > >> The fact that this example ^^ sends SeasonDate the find_start_record message makes the previous example unnecessary. > > >> > ?end > >> > end > > >> > and I get > > >> > rspec -f d -b spec/models/season_date_spec.rb > >> > SeasonDate > >> > ?responds to the find_start_record method call > >> > ?returns the record with the season start date (FAILED - 1) > > >> > Failures: > > >> > ?1) SeasonDate returns the record with the season start date > >> > ? ? Failure/Error: SeasonDate.find_start_record.should == > >> > @start_date_record > >> > ? ? expected: # >> > date_type: "season_start", created_at: "2010-12-03 17:03:58", > >> > updated_at: "2010-12-03 17:03:58">, > >> > ? ? ? ? ?got: nil (using ==) > > >> > I'm doing something dumb, but I don't know what. Any assistance much > >> > appreciated! > > >> Can't really tell from what you've posted. Please post the implementation of SeasonDate.season_date. > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From wolfmanjm at gmail.com Sat Dec 4 18:22:26 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Sat, 4 Dec 2010 15:22:26 -0800 (PST) Subject: [rspec-users] Notes on upgrading from RSpec 1 to RSpec 2 Message-ID: <3e26c20f-cabf-4b1b-b2d6-fd8a9879c16a@z26g2000prf.googlegroups.com> I am trying to upgrade a Rails 2.2.2 app to Rails3, its a pain ;) Part of this is I need to upgrade all my Specs to RSpec2, as this info does not seem to be in any one place, here is a summary of what I needed to do... * needed to rename all my views from .haml to .html.haml, (or .html.erb) although Rails3 seemed ok with the old naming RSpec2 view specs failed to find the templates with the old name. * rewrite all my view specs... - change `@controller.template.` to `view.` - change `have_tag` to `have_selector` and change the parameters - place holders not supported, need to use #{} - add :content => for any text in second parameter - change `assign[:blah]= :blod` to `assign(:blag, :blod)` - change the describe ... do to have the path to the view rather than text description - change the render '/show' to just render or render :file => 'full template spec' - change have_text to matches(/../) - change response.should to rendered.shoul * modify the controller specs - controller_name is no longer supported, so need to nest all my describes under a top level describe that has the controller name. describe 'UsersController' do or use subject {SomeController.new} (not tested yet) - when using post/delete/put :something, :id => 1 passing in an integer id used to work, now it needs to be a string (probably a rails3 thing) delete :destroy, :id => "1" * helper specs only needed minor changes - change have_tag to have_selector From lists at ruby-forum.com Sun Dec 5 16:04:30 2010 From: lists at ruby-forum.com (Paul D.) Date: Sun, 05 Dec 2010 22:04:30 +0100 Subject: [rspec-users] [Sinatra] "tried to create Proc object without a block" In-Reply-To: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> References: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> Message-ID: <008dca11b0923b7479846c12be579c6a@ruby-forum.com> Ok, I've updated the code examples in Chapter 1 to use the latest gem versions. Also, I've included a gemfile so going forward new gem versions shouldn't break anything. You'll just be able to bundle install to get the right ones. Code here: https://github.com/pauldix/service-oriented-design-with-ruby/tree/master/chapter_01 README for chapter 1 code: https://github.com/pauldix/service-oriented-design-with-ruby/blob/master/chapter_01/README I'll be updating the other code examples more today and in the coming week. Let me know if there are any issues. Thanks, Paul jtanium wrote in post #964516: > Hello all, > > I'm a long time Ruby and Rails user, but new to RSpec; I've been using > Shoulda instead. > > I picked up the book "Service-Oriented Design with Ruby and > Rails" (http://amzn.to/9sgx99) which uses RSpec throughout. Despite > being published only a few months ago, it's already out of date. > > Here's the gist with the relevant files: https://gist.github.com/718122 > (you can see where I commented out a few lines trying to get it to > work). > > I'm guessing the book was written using RSpec 1, and some older > (unknown) version of Rack. I've got Rack-1.2.1 and RSpec-2.1.0 > installed. > > This is what I get when I run "rspec spec": > > 1) service should return a user by name > Failure/Error: get '/api/v1/users/jason' > tried to create Proc object without a block > # (__DELEGATE__):2:in `send' > # (__DELEGATE__):2:in `get' > # ./spec/service_spec.rb:23 > > I'm guessing the spec just needs a minor tweak or two to start > working, but I have no idea what that would be. > > Thanks for any help you can provide, > > Jason -- Posted via http://www.ruby-forum.com/. From structuralartistry at gmail.com Sun Dec 5 19:19:55 2010 From: structuralartistry at gmail.com (DK) Date: Sun, 5 Dec 2010 16:19:55 -0800 (PST) Subject: [rspec-users] Rspec: `should': uninitialized constant RSpec::Expectations (NameError) Message-ID: Hi all, anyone have an idea why I am getting an error trying to 'rake spec': 'kernel.rb:27:in `should': uninitialized constant RSpec::Expectations (NameError)'. Can't seem to find a useful reference online to solve. This project I was working on a few months ago and got put aside, meanwhile I rebuilt my mac. So something is off but not sure what. Using rvm, Rails 3.0.3, Ruby 1.9.2, my gemfile.lock installs fine and shows the following for rspec. I actually deleted my rvm gemset and re- installed the bundle just in case but same error. Gemfile.lock rspec (2.2.0) rspec-core (~> 2.2) rspec-expectations (~> 2.2) rspec-mocks (~> 2.2) rspec-core (2.2.1) rspec-expectations (2.2.0) diff-lcs (~> 1.1.2) rspec-mocks (2.2.0) rspec-rails (2.2.1) actionpack (~> 3.0) activesupport (~> 3.0) railties (~> 3.0) rspec (~> 2.2.0) Gemfile: group :development, :test do gem 'ruby-debug19' gem 'cucumber-rails' gem 'cucumber', '>=0.8.5' gem 'capybara' gem 'rspec-rails' gem 'factory_girl_rails' gem 'webrat', '>=0.4.3' gem 'heroku' gem 'database_cleaner' end Thanks, David From bcruparel at yahoo.com Sun Dec 5 22:39:18 2010 From: bcruparel at yahoo.com (Bharat) Date: Sun, 5 Dec 2010 19:39:18 -0800 (PST) Subject: [rspec-users] RSpec 2.1.0 Start up problems Message-ID: <3de2f1c8-e447-4cf2-bd1d-23d4ae167ced@j25g2000yqa.googlegroups.com> I have a simple model as shown below: # == Schema Information # Schema version: 20101101014544 # # Table name: base_folders # # id :integer not null, primary key # name :string(255) # created_at :datetime # updated_at :datetime # class BaseFolder < ActiveRecord::Base attr_accessible :name validates_presence_of :name, :message => "^You must specify a base folder name." end And the spec: spec/models/base_folder.rb which contains require 'spec_helper' describe BaseFoler do describe "failure" do it "Base folder cannot be saved without a name" do base_folder = Factory.build(:base_folder, :name => '') base_folder.should_not be_valid end end describe "success" do it "should be valid with a name attribute" do course = Factory(:course) base_folder = Factory(:base_folder) base_folder.should be_valid end end end When I execute: rspec spec/models/base_folder_spec.rb, I get the following stack trace: ? rspec spec/models/base_folder_spec.rb /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/lib/ rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant BaseFoler (NameError) from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec- expectations-2.1.0/lib/rspec/expectations/backward_compatibility.rb: 6:in `const_missing' from /Users/bruparel/rrw/file_manager3/spec/models/ base_folder_spec.rb:3:in `' from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ lib/rspec/core/configuration.rb:334:in `load' from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ lib/rspec/core/configuration.rb:334:in `block in load_spec_files' from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ lib/rspec/core/configuration.rb:334:in `map' from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ lib/rspec/core/configuration.rb:334:in `load_spec_files' from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ lib/rspec/core/command_line.rb:18:in `run' from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ lib/rspec/core/runner.rb:55:in `run_in_process' from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ lib/rspec/core/runner.rb:46:in `run' from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ lib/rspec/core/runner.rb:10:in `block in autorun' What am I missing? Bharat From dchelimsky at gmail.com Sun Dec 5 23:29:28 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Dec 2010 22:29:28 -0600 Subject: [rspec-users] Rspec: `should': uninitialized constant RSpec::Expectations (NameError) In-Reply-To: References: Message-ID: On Sun, Dec 5, 2010 at 6:19 PM, DK wrote: > Hi all, anyone have an idea why I am getting an error trying to 'rake > spec': > > 'kernel.rb:27:in `should': uninitialized constant RSpec::Expectations > (NameError)'. Looking through the code I can see why this might be happening, but I'm at a loss as to why it's happening to you and not to everybody. I _think_ you can work around it for now by requiring "rspec/matchers" in your spec_helper file. I'd recommend doing so immediately after require "rspec/core". Please report back as to whether this works. While you do that, I'll try to reproduce the error here and resolve it in a definitive way. Cheers, David > Can't seem to find a useful reference online to solve. This project I > was working on a few months ago and got put aside, meanwhile I rebuilt > my mac. So something is off but not sure what. > > Using rvm, Rails 3.0.3, Ruby 1.9.2, my gemfile.lock installs fine and > shows the following for rspec. I actually deleted my rvm gemset and re- > installed the bundle just in case but same error. > > Gemfile.lock > ? ?rspec (2.2.0) > ? ? ?rspec-core (~> 2.2) > ? ? ?rspec-expectations (~> 2.2) > ? ? ?rspec-mocks (~> 2.2) > ? ?rspec-core (2.2.1) > ? ?rspec-expectations (2.2.0) > ? ? ?diff-lcs (~> 1.1.2) > ? ?rspec-mocks (2.2.0) > ? ?rspec-rails (2.2.1) > ? ? ?actionpack (~> 3.0) > ? ? ?activesupport (~> 3.0) > ? ? ?railties (~> 3.0) > ? ? ?rspec (~> 2.2.0) > > > Gemfile: > > ?group :development, :test do > ? ?gem 'ruby-debug19' > ? ?gem 'cucumber-rails' > ? ?gem 'cucumber', '>=0.8.5' > ? ?gem 'capybara' > ? ?gem 'rspec-rails' > ? ?gem 'factory_girl_rails' > ? ?gem 'webrat', '>=0.4.3' > ? ?gem 'heroku' > ? ?gem 'database_cleaner' > ?end > > Thanks, > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Dec 5 23:32:29 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Dec 2010 22:32:29 -0600 Subject: [rspec-users] RSpec 2.1.0 Start up problems In-Reply-To: <3de2f1c8-e447-4cf2-bd1d-23d4ae167ced@j25g2000yqa.googlegroups.com> References: <3de2f1c8-e447-4cf2-bd1d-23d4ae167ced@j25g2000yqa.googlegroups.com> Message-ID: On Sun, Dec 5, 2010 at 9:39 PM, Bharat wrote: > I have a simple model as shown below: > # == Schema Information > # Schema version: 20101101014544 > # > # Table name: base_folders > # > # ?id ? ? ? ? :integer ? ? ? ? not null, primary key > # ?name ? ? ? :string(255) > # ?created_at :datetime > # ?updated_at :datetime > # > > class BaseFolder < ActiveRecord::Base > ?attr_accessible :name > ?validates_presence_of :name, :message => "^You must specify a base > folder name." > end > > And the spec: spec/models/base_folder.rb which contains > > require 'spec_helper' > > describe BaseFoler do > > ?describe "failure" do > ? ?it "Base folder cannot be saved without a name" do > ? ? ?base_folder = Factory.build(:base_folder, :name => '') > ? ? ?base_folder.should_not be_valid > ? ?end > ?end > > ?describe "success" do > ? ?it "should be valid with a name attribute" do > ? ? ?course = Factory(:course) > ? ? ?base_folder = Factory(:base_folder) > ? ? ?base_folder.should be_valid > ? ?end > ?end > > end > > When I execute: > > rspec spec/models/base_folder_spec.rb, I get the following stack > trace: > > > ? rspec spec/models/base_folder_spec.rb > /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/lib/ > rspec/core/backward_compatibility.rb:20:in `const_missing': > uninitialized constant BaseFoler (NameError) This failure message ^^ already tells you what I'm about to tell you: The class name is BaseFolder, but you typed BaseFoler (without a 'd'). Cheers, David > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec- > expectations-2.1.0/lib/rspec/expectations/backward_compatibility.rb: > 6:in `const_missing' > ? ? ? ?from /Users/bruparel/rrw/file_manager3/spec/models/ > base_folder_spec.rb:3:in `' > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ > lib/rspec/core/configuration.rb:334:in `load' > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ > lib/rspec/core/configuration.rb:334:in `block in load_spec_files' > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ > lib/rspec/core/configuration.rb:334:in `map' > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ > lib/rspec/core/configuration.rb:334:in `load_spec_files' > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ > lib/rspec/core/command_line.rb:18:in `run' > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ > lib/rspec/core/runner.rb:55:in `run_in_process' > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ > lib/rspec/core/runner.rb:46:in `run' > ? ? ? ?from /Users/bruparel/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.1.0/ > lib/rspec/core/runner.rb:10:in `block in autorun' > > What am I missing? > > Bharat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From win at wincent.com Mon Dec 6 04:34:44 2010 From: win at wincent.com (Wincent Colaiuta) Date: Mon, 6 Dec 2010 10:34:44 +0100 Subject: [rspec-users] Rspec: `should': uninitialized constant RSpec::Expectations (NameError) In-Reply-To: References: Message-ID: <98657DF0-1B35-4FD9-A54D-49F1FB681B26@wincent.com> El 06/12/2010, a las 01:19, DK escribi?: > Hi all, anyone have an idea why I am getting an error trying to 'rake > spec': > > 'kernel.rb:27:in `should': uninitialized constant RSpec::Expectations > (NameError)'. Can you paste the full backtrace and the code of the spec which is causing this failure? It wouldn't surprise me if you had a naked example -- ie. nested inside a "describe/context" block, without an "it" block. I had one such example in an application with thousands of specs, so it slipped by unnoticed for a long while, but on moving to RSpec 2.1.0 this kind of latent bug is no longer tolerated. If you use a few levels of nesting to organize your specs it is quite possible for this kind of mistake to creep in. Cheers, Wincent From bcruparel at yahoo.com Mon Dec 6 05:29:21 2010 From: bcruparel at yahoo.com (Bharat) Date: Mon, 6 Dec 2010 02:29:21 -0800 (PST) Subject: [rspec-users] RSpec 2.1.0 Start up problems In-Reply-To: References: <3de2f1c8-e447-4cf2-bd1d-23d4ae167ced@j25g2000yqa.googlegroups.com> Message-ID: Thanks David and apologies. I should have looked harder. By the way, I have an extensive Shoulda test suite for my open source Rails 3 project. Do you have any advice on how to port it to RSpec? Here is the link in case you are interested http://www.github.com/bruparel/file_manager3 Currently it uses Shoulda/Webrat/Cucumber stack. I am moving it to Rspec/Capybara/Cucumber, any thoughts? Bharat From genlighten at gmail.com Mon Dec 6 07:29:01 2010 From: genlighten at gmail.com (Dean) Date: Mon, 6 Dec 2010 04:29:01 -0800 (PST) Subject: [rspec-users] Controller specs for sub-controllers Message-ID: <02760c13-69eb-4dff-ba13-cdc576d3b751@35g2000prt.googlegroups.com> I'm completely new to RSpec (and fairly new to Rails, too.) I'm working on an existing application that has an Admin::BaseController and sub-controllers such as Admin:TestimonialsController: class Admin::BaseController < ApplicationController end class Admin::TestimonialsController < Admin::BaseController def new @page_title = "Create New Testimonial" end end I'm trying to write very basic tests for my Testimonials controller, like so: [testimonials_controller_spec.rb] require 'spec_helper' describe Admin::TestimonialsController do integrate_views describe "GET 'new'" do it "should be successful" do get 'new' response.should be_success end it "should have the right title" do get 'testimonials/new' response.should have_tag("title", /Create New Testimonial/) end end end I've created the 'new' view and it gets the right title tag, but the tests fail: 1) 'Admin::TestimonialsController GET 'new' should render the create testimonial template' FAILED expected success? to return true, got false /Users/Lowell/rails_projects/genlighten_dr/spec/controllers/admin/ testimonials_controller_spec.rb:9: 2) 'Admin::TestimonialsController GET 'new' should have the right title' FAILED Expected at least 1 element matching "title", found 0. is not true. /Users/Lowell/rails_projects/genlighten_dr/spec/controllers/admin/ testimonials_controller_spec.rb:14: I suspect it has something to do with the path to my views. Because the testimonials sub-controller inherits from the admin BaseController, both testimonials controllers and views are in subdirectories, e.g.: app/controllers/admin/testimonials_controller.rb and app/views/admin/testimonials/new.html.erb Should my tests say something like: get 'admin/testimonials/new' instead of get 'new'? Or am I making a less subtle mistake? Thanks, Dean From lists at ruby-forum.com Mon Dec 6 15:06:30 2010 From: lists at ruby-forum.com (David K.) Date: Mon, 06 Dec 2010 21:06:30 +0100 Subject: [rspec-users] Rspec: `should': uninitialized constant RSpec::Expectations (NameError) In-Reply-To: References: , Message-ID: David Chelimsky wrote in post #966405: > On Sun, Dec 5, 2010 at 6:19 PM, DK wrote: >> Hi all, anyone have an idea why I am getting an error trying to 'rake >> spec': >> >> 'kernel.rb:27:in `should': uninitialized constant RSpec::Expectations >> (NameError)'. > > Looking through the code I can see why this might be happening, but > I'm at a loss as to why it's happening to you and not to everybody. > > I _think_ you can work around it for now by requiring "rspec/matchers" > in your spec_helper file. I'd recommend doing so immediately after > require "rspec/core". Please report back as to whether this works. > > While you do that, I'll try to reproduce the error here and resolve it > in a definitive way. Thanks so much for the response. For some reason the group would not let me add my correct email (dk at structuralartistry.com) so I did not get advised you had responded. Before I noticed that you responded, I tried creating a new rails app (3.0.3 also) and got the same error, so either it is affecting others or my environment is messed up. Anyhow... based on your feedback: I tried changing my spec_helper to this at the top: # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/matchers' require 'ruby-debug' But to no avail... Also noticed that there is no reference to 'rspec/core', but when I added it, same result. Following is the actual spec (truncated to the failing line): require 'spec_helper' describe User do before(:all) do Factory.create(:sysadmin_role) Factory.create(:practice_admin_role) Factory.create(:practice_user_role) end describe "user authorization - guest role" do user = User.new user.authorize('activations', 'create')[:success].should == true end And the backtrace: /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-expectations-2.2.0/lib/rspec/expectations/extensions/kernel.rb:27:in `should': uninitialized constant RSpec::Expectations (NameError) from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:14:in `block (2 levels) in ' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:131:in `module_eval' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:131:in `subclass' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:118:in `describe' from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:12:in `block in ' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:131:in `module_eval' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:131:in `subclass' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:118:in `describe' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/extensions/object.rb:6:in `describe' from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:3:in `' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in `block in load_spec_files' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in `map' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in `load_spec_files' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/command_line.rb:18:in `run' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:55:in `run_in_process' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:46:in `run' from /Users/DK/.rvm/gems/ruby-1.9.2-p0 at wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:10:in `block in autorun' rake aborted! ruby -S bundle exec rspec "./spec/mailers/system_mailer_spec.rb" "./spec/models/practice_member_spec.rb" "./spec/models/practice_spec.rb" "./spec/models/role_spec.rb" "./spec/models/travel_card_spec.rb" "./spec/models/user_session_spec.rb" "./spec/models/user_spec.rb" failed > > Cheers, > David -- Posted via http://www.ruby-forum.com/. From nicholas.wieland at gmail.com Mon Dec 6 16:49:04 2010 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Mon, 6 Dec 2010 13:49:04 -0800 Subject: [rspec-users] Problem with 1.9.2 Message-ID: <3BCDCD69-7890-4AF7-AF31-9BD800603256@gmail.com> Hi guys, I'm not entirely sure this is a problem with RSpec or cucumber, for sure it's happening after the last gem update under 1.9.2 (rvm). Backtrace: https://gist.github.com/730995 Gemfile: https://gist.github.com/730999 I've tried to search the archives but even if the "circular require considered harmful" seems already well known, it doesn't seem to match my case. Does someone have suggestions about how to solve this ? In ree everything works as expected. ngw -- Nicholas Wieland (ngw) Zooppa CTO 911 Western Avenue, Suite 420 Seattle, WA 98104 US -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.hawkins at gmail.com Mon Dec 6 18:10:41 2010 From: martin.hawkins at gmail.com (Martin Hawkins) Date: Mon, 6 Dec 2010 15:10:41 -0800 (PST) Subject: [rspec-users] Problem with 1.9.2 In-Reply-To: <3BCDCD69-7890-4AF7-AF31-9BD800603256@gmail.com> References: <3BCDCD69-7890-4AF7-AF31-9BD800603256@gmail.com> Message-ID: <882462e0-d339-4813-ab78-a488149821c7@b25g2000vbz.googlegroups.com> I had this problem too. I am in a project that has 1.9.2 and a similar list of gems. I'm afraid I chickened out of using autotest and use watchr instead. On Dec 6, 9:49?pm, Nicholas Wieland wrote: > Hi guys, I'm not entirely sure this is a problem with RSpec or cucumber, for sure it's happening after the last gem update under 1.9.2 (rvm). > > Backtrace:https://gist.github.com/730995 > Gemfile:https://gist.github.com/730999 > > I've tried to search the archives but even if the "circular require considered harmful" seems already well known, it doesn't seem to match my case. > > Does someone have suggestions about how to solve this ? In ree everything works as expected. > > ? ngw > > -- > Nicholas Wieland (ngw) > Zooppa CTO > 911 Western Avenue, Suite 420 > Seattle, WA ?98104 ?US > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From stephen.smithstone at gmail.com Mon Dec 6 16:25:20 2010 From: stephen.smithstone at gmail.com (Stephen Smithstone) Date: Mon, 6 Dec 2010 21:25:20 +0000 Subject: [rspec-users] making sure a model acts_as_authentic Message-ID: <09B92C01-D37D-4C2E-98DB-29B05462ADB9@gmail.com> Is there any way to spec that a model should acts_as_authentic which is from the authlogic plugin im using rspec-1 Stephen Smithstone From dk at structuralartistry.com Mon Dec 6 15:13:43 2010 From: dk at structuralartistry.com (David Kahn) Date: Mon, 6 Dec 2010 14:13:43 -0600 Subject: [rspec-users] Change setting to receive emails when posted? Message-ID: This is an administrative question: I joined this group yesterday and when I try to save my preferences it does not allow me to select "Email (approximately 12 emails per day)".... is it just me or does everyone just get a digest (I would rather have things in real time)... Thanks, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew.m.kasper at gmail.com Mon Dec 6 21:12:14 2010 From: andrew.m.kasper at gmail.com (Andrew Kasper) Date: Mon, 6 Dec 2010 21:12:14 -0500 Subject: [rspec-users] Unexpected before :each behavior. Message-ID: Hi gang. I've come across what I believe to be unexpected behavior for some of my before :each blocks, and I wonder if anyone can enlighten me as to why this is happening. The surprising thing happens when I run a 'before :each' inside of an each block on a Hash. I have a #before_save hook in my ActiveRecord model. When I call @sample_model.save from the before block, the model runs a uniqueness validation. However, when I save from within the example, the save works fine. Below is the minimal test case I was able to put together: class SampleClassMigration < ActiveRecord::Migration def self.up create_table :sample_classes do |t| t.string :sample_field t.string :attrib_1 t.string :attrib_2 end end end class SampleClass < ActiveRecord::Base validates_uniqueness_of :sample_field before_save :prep def prep self.sample_field = 'sample_value' end end describe SampleClass do EXAMPLES = { :attrib_1 => 'foo', :attrib_2 => 'bar' } EXAMPLES.each do |key, value| before(:each) do @sample = SampleClass.new(key => value) #In the passing case, this call to #save #is moved into the 'it' block @sample.save end it "key : #{value}\tvalue : #{key.to_s}" do #in the other case, I call the spec here @sample.should be_valid end end end It was my expectation that calling an instance method in the before block would be the same as calling it within the example block. Instead, I get two different results. When called from within the it block, both examples pass. When called from within the before block, they both fail: 1) 'SampleClass key : bar value : attrib_2' FAILED Expected # to be valid, but it was not Errors: Sample field has already been taken ./spec/models/minimal_spec.rb:20: 2) 'SampleClass key : foo value : attrib_1' FAILED Expected # to be valid, but it was not Errors: Sample field has already been taken ./spec/models/minimal_spec.rb:20: I'm surprised to see that the example fails, but I'm more surprised to see that it fails both times. It is apparently the case that the "before" block is executed on every iteration of the "each" block (but that the examples themselves are executed later). 1) Is this a bug? 2) Is it a known behavior? 3) Is there a "BDD-theoretical" better way to do something like this (assuming a larger hash of examples, for instance)? I'm using: gem 'rails', '2.3.5' gem 'mysql' group :development, :test do gem 'database_cleaner' gem 'rspec-rails', '1.3.2' gem 'rspec', '1.3.0' end DatabaseCleaner is properly configured, and runs for many other specs. (Indeed, it even runs correctly between steps, as demonstrated by the case where the specs pass). Thanks, Andrew Kasper -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Dec 6 21:51:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Dec 2010 20:51:46 -0600 Subject: [rspec-users] Unexpected before :each behavior. In-Reply-To: References: Message-ID: <118E7AAC-63E9-46E4-BADF-58704CC2EBB0@gmail.com> On Dec 6, 2010, at 8:12 PM, Andrew Kasper wrote: > Hi gang. > > I've come across what I believe to be unexpected behavior for some of my before :each blocks, and I wonder if anyone can enlighten me as to why this is happening. > > The surprising thing happens when I run a 'before :each' inside of an each block on a Hash. I have a #before_save hook in my ActiveRecord model. When I call @sample_model.save from the before block, the model runs a uniqueness validation. However, when I save from within the example, the save works fine. > > Below is the minimal test case I was able to put together: > > class SampleClassMigration < ActiveRecord::Migration > def self.up > create_table :sample_classes do |t| > t.string :sample_field > t.string :attrib_1 > t.string :attrib_2 > end > end > end > > class SampleClass < ActiveRecord::Base > validates_uniqueness_of :sample_field > before_save :prep > def prep > self.sample_field = 'sample_value' > end > end > > describe SampleClass do > EXAMPLES = { > :attrib_1 => 'foo', > :attrib_2 => 'bar' > } > EXAMPLES.each do |key, value| > before(:each) do > @sample = SampleClass.new(key => value) > #In the passing case, this call to #save > #is moved into the 'it' block > @sample.save > end > > it "key : #{value}\tvalue : #{key.to_s}" do > #in the other case, I call the spec here > @sample.should be_valid > end > end > end > > It was my expectation that calling an instance method in the before block would be the same as calling it within the example block. Instead, I get two different results. When called from within the it block, both examples pass. When called from within the before block, they both fail: > > 1) > 'SampleClass key : bar value : attrib_2' FAILED > Expected # to be valid, but it was not > Errors: Sample field has already been taken > ./spec/models/minimal_spec.rb:20: > > 2) > 'SampleClass key : foo value : attrib_1' FAILED > Expected # to be valid, but it was not > Errors: Sample field has already been taken > ./spec/models/minimal_spec.rb:20: > > I'm surprised to see that the example fails, but I'm more surprised to see that it fails both times. It is apparently the case that the "before" block is executed on every iteration of the "each" block (but that the examples themselves are executed later). > > 1) Is this a bug? Nope. > 2) Is it a known behavior? Yep. Examples are evaluated _after_ they are _all_ read in and organized. Because each iteration adds a before(:each) block, the code above has the same behavior as this: describe SampleClass do before(:each) do @sample = SampleClass.new(:attrib_1 => 'foo') @sample.save end before(:each) do @sample = SampleClass.new(:attrib_2 => 'bar') @sample.save end it "key : foo\tvalue : attrib_1" do @sample.should be_valid end it "key : bar\tvalue : attrib_2" do @sample.should be_valid end end Seeing it this way, it is clear that there are two before(:each) hooks that both run before each example, and that the 2nd before(:each) hook results in a failure each time. Make sense? > 3) Is there a "BDD-theoretical" better way to do something like this (assuming a larger hash of examples, for instance)? You could create a separate context for each iteration, and each one would have it's own before hook: describe SampleClass do EXAMPLES = { :attrib_1 => 'foo', :attrib_2 => 'bar' } EXAMPLES.each do |key, value| context "with :#{key} => #{value}" do before(:each) do @sample = SampleClass.new(key => value) #In the passing case, this call to #save #is moved into the 'it' block @sample.save end it "key : #{value}\tvalue : #{key.to_s}" do #in the other case, I call the spec here @sample.should be_valid end end end end In terms theory, the trick here is that when you take short-cuts like this you bind all the examples together. That tends to work fine until requirements change such that one of the iterations needs to change in a way that the others don't. HTH, David > > I'm using: > > gem 'rails', '2.3.5' > gem 'mysql' > group :development, :test do > gem 'database_cleaner' > gem 'rspec-rails', '1.3.2' > gem 'rspec', '1.3.0' > end > > DatabaseCleaner is properly configured, and runs for many other specs. (Indeed, it even runs correctly between steps, as demonstrated by the case where the specs pass). > > Thanks, > Andrew Kasper > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Dec 7 09:58:09 2010 From: lists at ruby-forum.com (David Kahn) Date: Tue, 07 Dec 2010 15:58:09 +0100 Subject: [rspec-users] Rspec: `should': uninitialized constant RSpec::Expectations (NameError) In-Reply-To: <98657DF0-1B35-4FD9-A54D-49F1FB681B26@wincent.com> References: , <98657DF0-1B35-4FD9-A54D-49F1FB681B26@wincent.com> Message-ID: <5cb0b73aeaed284e38f4ae4e2e1daa13@ruby-forum.com> Wincent Colaiuta wrote in post #966456: > El 06/12/2010, a las 01:19, DK escribi: > >> Hi all, anyone have an idea why I am getting an error trying to 'rake >> spec': >> >> 'kernel.rb:27:in `should': uninitialized constant RSpec::Expectations >> (NameError)'. > > Can you paste the full backtrace and the code of the spec which is > causing this failure? > > It wouldn't surprise me if you had a naked example -- ie. nested inside > a "describe/context" block, without an "it" block. > > I had one such example in an application with thousands of specs, so it > slipped by unnoticed for a long while, but on moving to RSpec 2.1.0 this > kind of latent bug is no longer tolerated. If you use a few levels of > nesting to organize your specs it is quite possible for this kind of > mistake to creep in. Ahh... Wincent, you are right. Exactly the problem... so it was tolerated on an older version, and I was stuck thinking it was a configuration issue. Appreciated! > > Cheers, > Wincent -- Posted via http://www.ruby-forum.com/. From stephen.smithstone at gmail.com Tue Dec 7 11:46:47 2010 From: stephen.smithstone at gmail.com (ssmithstone) Date: Tue, 7 Dec 2010 08:46:47 -0800 (PST) Subject: [rspec-users] specing a model to make sure it implements act_as_authentic Message-ID: Is it possible to spec that a model should acts_as_authentic which is from the authlogic gem? I'm using rspec-1.3.x Cheers Stephen From me at jbrains.ca Tue Dec 7 21:19:06 2010 From: me at jbrains.ca (J. B. Rainsberger) Date: Wed, 8 Dec 2010 12:19:06 +1000 Subject: [rspec-users] specing a model to make sure it implements act_as_authentic In-Reply-To: References: Message-ID: On Wed, Dec 8, 2010 at 02:46, ssmithstone wrote: Is it possible to spec that a model should acts_as_authentic which is > from the authlogic gem? > > I'm using rspec-1.3.x > Whenever I don't know how to spec something -- or whether to spec something -- I ask, "If the thing I'm worried about failed, how would I know?" Then I try writing a spec to check that. So let me ask you, if your model failed to acts_as_authentic from the authlogic gem, what would go wrong? Could you write a test that fails when that wrong thing happens? -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. -------------- next part -------------- An HTML attachment was scrubbed... URL: From shea at shealevy.com Tue Dec 7 23:40:42 2010 From: shea at shealevy.com (Shea Levy) Date: Tue, 07 Dec 2010 20:40:42 -0800 Subject: [rspec-users] Mocking a Model Class and a View with RSpec-Rails Message-ID: <5a2ebb73fc872efac9e9d809312e8ebf@shealevy.com> Hi all, I'm new to RSpec and to TDD/Agile methods in general (by "new" I mean I'm about 4/5 of the way through _The RSpec Book_ and haven't yet actually implemented the practices in my projects), so this question may seem silly. Suppose I'm using specs to drive the development of a Users controller, but I haven't implemented the User model yet, or I want to keep the spec isolated from the model class as much as possible. Is there any way to modify the following spec file to "mock" out the entire User class both in the spec AND for the controller? Similarly, suppose I haven't implemented a view for users/create (and I'm being unconventional in having a create view instead of a redirect to index) or I just want to keep the controller spec isolated from work done on the views. Is there anyway to modify what follows to "mock" out a view for the controller to render? I view the purpose of a controller as being in charge of sending and receiving messages to and from all of the other aspects of the application, so I just want to test the sending and receiving without worrying about what's on the other end of the communication. spec/controllers/users_controller_spec.rb: require 'spec_helper' describe UsersController do describe "POST create" do it "creates a new user" do User.should_receive(:new).with("name" => "Shea Levy") post :create, :user => { "name" => "Shea Levy"} end end end app/controllers/users_controller.rb: def create User.new(params[:user]) end Cheers, Shea Levy -------------- next part -------------- An HTML attachment was scrubbed... URL: From patmaddox at me.com Wed Dec 8 12:56:41 2010 From: patmaddox at me.com (Pat Maddox) Date: Wed, 08 Dec 2010 09:56:41 -0800 Subject: [rspec-users] Controller specs for sub-controllers In-Reply-To: <02760c13-69eb-4dff-ba13-cdc576d3b751@35g2000prt.googlegroups.com> References: <02760c13-69eb-4dff-ba13-cdc576d3b751@35g2000prt.googlegroups.com> Message-ID: On Dec 6, 2010, at 4:29 AM, Dean wrote: > I'm completely new to RSpec (and fairly new to Rails, too.) I'm > working on an existing application that has an Admin::BaseController > and sub-controllers such as Admin:TestimonialsController: > > class Admin::BaseController < ApplicationController > end > > class Admin::TestimonialsController < Admin::BaseController > > def new > @page_title = "Create New Testimonial" > end > end > > I'm trying to write very basic tests for my Testimonials controller, > like so: > > [testimonials_controller_spec.rb] > > require 'spec_helper' > > describe Admin::TestimonialsController do > integrate_views > > describe "GET 'new'" do > it "should be successful" do > get 'new' > response.should be_success > end > > it "should have the right title" do > get 'testimonials/new' > response.should have_tag("title", /Create New Testimonial/) > end > end > end > > I've created the 'new' view and it gets the right title tag, but the > tests fail: > > 1) > 'Admin::TestimonialsController GET 'new' should render the create > testimonial template' FAILED > expected success? to return true, got false > /Users/Lowell/rails_projects/genlighten_dr/spec/controllers/admin/ > testimonials_controller_spec.rb:9: > > 2) > 'Admin::TestimonialsController GET 'new' should have the right title' > FAILED > Expected at least 1 element matching "title", found 0. > is not true. > /Users/Lowell/rails_projects/genlighten_dr/spec/controllers/admin/ > testimonials_controller_spec.rb:14: > > I suspect it has something to do with the path to my views. Because > the testimonials sub-controller inherits from the admin > BaseController, both testimonials controllers and views are in > subdirectories, e.g.: > > app/controllers/admin/testimonials_controller.rb > > and > > app/views/admin/testimonials/new.html.erb > > Should my tests say something like: > > get 'admin/testimonials/new' instead of get 'new'? Or am I making a > less subtle mistake? > > Thanks, > > Dean > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users No the path shouldn't matter. When you do get 'new' you're saying, "make a GET request to the 'new' action of this controller" -- it has nothing to do with layouts. My two guesses is that there's a 500 error somewhere, or you have a filter that is redirecting a login page and need to do some setup in order to get past it. To check the first guess, tail -f log/test.log when you run your test. See if there's an exception backtrace in there. To check the second guess, inspect the response to see if it's a redirect or something else. Pat From patmaddox at me.com Wed Dec 8 13:00:13 2010 From: patmaddox at me.com (Pat Maddox) Date: Wed, 08 Dec 2010 10:00:13 -0800 Subject: [rspec-users] Mocking a Model Class and a View with RSpec-Rails In-Reply-To: <5a2ebb73fc872efac9e9d809312e8ebf@shealevy.com> References: <5a2ebb73fc872efac9e9d809312e8ebf@shealevy.com> Message-ID: On Dec 7, 2010, at 8:40 PM, Shea Levy wrote: > Hi all, > > I'm new to RSpec and to TDD/Agile methods in general (by "new" I mean I'm about 4/5 of the way through The RSpec Book and haven't yet actually implemented the practices in my projects), so this question may seem silly. Suppose I'm using specs to drive the development of a Users controller, but I haven't implemented the User model yet, or I want to keep the spec isolated from the model class as much as possible. Is there any way to modify the following spec file to "mock" out the entire User class both in the spec AND for the controller? Similarly, suppose I haven't implemented a view for users/create (and I'm being unconventional in having a create view instead of a redirect to index) or I just want to keep the controller spec isolated from work done on the views. Is there anyway to modify what follows to "mock" out a view for the controller to render? I view the purpose of a controller as being in charge of sending and receiving messages to and from all of the other aspects of the application, so I just want to test the sending and receiving without worrying about what's on the other end of the communication. > > spec/controllers/users_controller_spec.rb: > > require 'spec_helper' > describe UsersController do > describe "POST create" do > it "creates a new user" do > User.should_receive(:new).with("name" => "Shea Levy") > post :create, :user => { "name" => "Shea Levy"} > end > end > end > > app/controllers/users_controller.rb: > > def create > User.new(params[:user]) > end > > Cheers, > Shea Levy > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users If you haven't defined the User class, all you need to do to get your tests passing is to define a User constant. If I'm working on a controller and set of views and haven't made the model yet, I'll usually just do class User; end in my spec_helper.rb. That way the constant exists and Ruby is happy. When I'm ready to do the model, I delete that line. re: mocking out views, controller specs are isolated from their views by default. Meaning that in the example you posted, the view won't be rendered at all. If you want the views to be rendered, you call integrate_views from within the controller example group. Pat -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Dec 9 00:22:32 2010 From: lists at ruby-forum.com (Michelle Pace) Date: Thu, 09 Dec 2010 06:22:32 +0100 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: <46a2089e-bcd7-4ebe-adff-ace255afaec4@k39g2000yqb.googlegroups.com> References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com>, <46a2089e-bcd7-4ebe-adff-ace255afaec4@k39g2000yqb.googlegroups.com> Message-ID: <2d16df30d414cb2e8e0b60ad1c57b7e7@ruby-forum.com> Kristian Mandrup wrote in post #917121: > As of beta.4, you?ll have to do add this configuration manually. Just > create an autotest directory in the root of your project, put the > following statement in ./autotest/discover.rb: > > Autotest.add_discovery { "rspec2" } Hi Kristian (or anyone who can shed some light on this), I have followed the above instructions but to no avail. Looking at the output of my command prompt below is there something obvious I am doing incorrectly in getting autospec to work? I really would appreciate any suggestions. Thank-you in advance, Michelle C:\DEVELOPMENT\twits>cat autotest/discover.rb Autotest.add_discovery { ?rspec2? } C:\DEVELOPMENT\twits>ruby -v ruby 1.9.2p0 (2010-08-18) [i386-mingw32] C:\DEVELOPMENT\twits>gem list?local * LOCAL GEMS autotest (4.4.6) bundler (1.0.7) diff-lcs (1.1.2) git (1.2.5) jeweler (1.5.1) minitest (1.6.0) rake (0.8.7) rdiscount (1.6.5) rdoc (2.5.8) redcar (0.9.1) rspec (2.2.0) rspec-core (2.2.1) rspec-expectations (2.2.0) rspec-mocks (2.2.0) rubyzip (0.9.4) ZenTest (4.4.1) C:\DEVELOPMENT\twits>autospec ********************************************************** REMOVAL NOTICE: you are using behaviour that has been removed from rspec-2. * The ?autospec? command is no longer supported. * Please use ?autotest? insted. This message will be removed from a future version of rspec ********************************************************** -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Dec 9 07:19:15 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Dec 2010 06:19:15 -0600 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: <2d16df30d414cb2e8e0b60ad1c57b7e7@ruby-forum.com> References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com>, <46a2089e-bcd7-4ebe-adff-ace255afaec4@k39g2000yqb.googlegroups.com> <2d16df30d414cb2e8e0b60ad1c57b7e7@ruby-forum.com> Message-ID: On Dec 8, 2010, at 11:22 PM, Michelle Pace wrote: > Kristian Mandrup wrote in post #917121: >> As of beta.4, you?ll have to do add this configuration manually. Just >> create an autotest directory in the root of your project, put the >> following statement in ./autotest/discover.rb: >> >> Autotest.add_discovery { "rspec2" } > > > Hi Kristian (or anyone who can shed some light on this), > > I have followed the above instructions but to no avail. Looking at the > output of my command prompt below is there something obvious I am doing > incorrectly in getting autospec to work? I really would appreciate any > suggestions. The ZenTest/autotest gem world is a bit confusing right now. Here's the deal: ZenTest-4.4.1 rolled autotest (mostly) back into ZenTest, but introduced a regression in which Autotest no longer sees ./autotest/discover.rb when running on Ruby 1.9.2. This is because Ruby 1.9.2 does not add "." to the $LOAD_PATH and, while autotest-4.4.5 (before it got rolled back to ZenTest) handled this, ZenTest-4.4.1 does not. Additionally, there is now an autotest-standalone gem (currently at 4.5.2), which _does_ handle the Ruby 1.9.2 situation correctly. In any of these cases, autotest's --style/-s option works correctly. So your options are: # autotest-4.4.5 autotest # requires ./autotest/discover.rb autotest --style rspec2 # autotest-4.4.6 (with ZenTest-4.4.1) autotest --style rspec2 # autotest-standalone-4.5.2 autotest # requires ./autotest/discover.rb autotest --style rspec2 HTH, David > Thank-you in advance, > Michelle > > > C:\DEVELOPMENT\twits>cat autotest/discover.rb > Autotest.add_discovery { ?rspec2? } > > C:\DEVELOPMENT\twits>ruby -v > ruby 1.9.2p0 (2010-08-18) [i386-mingw32] > > C:\DEVELOPMENT\twits>gem list?local > * LOCAL GEMS > autotest (4.4.6) > bundler (1.0.7) > diff-lcs (1.1.2) > git (1.2.5) > jeweler (1.5.1) > minitest (1.6.0) > rake (0.8.7) > rdiscount (1.6.5) > rdoc (2.5.8) > redcar (0.9.1) > rspec (2.2.0) > rspec-core (2.2.1) > rspec-expectations (2.2.0) > rspec-mocks (2.2.0) > rubyzip (0.9.4) > ZenTest (4.4.1) > > C:\DEVELOPMENT\twits>autospec > ********************************************************** > REMOVAL NOTICE: you are using behaviour that has been > removed from rspec-2. > > * The ?autospec? command is no longer supported. > * Please use ?autotest? insted. > > This message will be removed from a future version of rspec > ********************************************************** > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From dchelimsky at gmail.com Thu Dec 9 07:34:23 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Dec 2010 06:34:23 -0600 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com>, <46a2089e-bcd7-4ebe-adff-ace255afaec4@k39g2000yqb.googlegroups.com> <2d16df30d414cb2e8e0b60ad1c57b7e7@ruby-forum.com> Message-ID: <291BBE0C-A04F-4E28-ADF2-6F11142687E1@gmail.com> On Dec 9, 2010, at 6:19 AM, David Chelimsky wrote: > > On Dec 8, 2010, at 11:22 PM, Michelle Pace wrote: > >> Kristian Mandrup wrote in post #917121: >>> As of beta.4, you?ll have to do add this configuration manually. Just >>> create an autotest directory in the root of your project, put the >>> following statement in ./autotest/discover.rb: >>> >>> Autotest.add_discovery { "rspec2" } >> >> >> Hi Kristian (or anyone who can shed some light on this), >> >> I have followed the above instructions but to no avail. Looking at the >> output of my command prompt below is there something obvious I am doing >> incorrectly in getting autospec to work? I really would appreciate any >> suggestions. > > The ZenTest/autotest gem world is a bit confusing right now. Here's the deal: > > ZenTest-4.4.1 rolled autotest (mostly) back into ZenTest, but introduced a regression in which Autotest no longer sees ./autotest/discover.rb when running on Ruby 1.9.2. This is because Ruby 1.9.2 does not add "." to the $LOAD_PATH and, while autotest-4.4.5 (before it got rolled back to ZenTest) handled this, ZenTest-4.4.1 does not. > > Additionally, there is now an autotest-standalone gem (currently at 4.5.2), which _does_ handle the Ruby 1.9.2 situation correctly. > > In any of these cases, autotest's --style/-s option works correctly. So your options are: > > # autotest-4.4.5 > autotest # requires ./autotest/discover.rb > autotest --style rspec2 > > # autotest-4.4.6 (with ZenTest-4.4.1) > autotest --style rspec2 > > # autotest-standalone-4.5.2 > autotest # requires ./autotest/discover.rb > autotest --style rspec2 FYI - I filed a bug report in the ZenTest tracker [1], so hopefully this will get resolved in a future release of ZenTest. [1] http://rubyforge.org/tracker/?func=detail&aid=28775&group_id=419&atid=1678 > HTH, > David > >> Thank-you in advance, >> Michelle >> >> >> C:\DEVELOPMENT\twits>cat autotest/discover.rb >> Autotest.add_discovery { ?rspec2? } >> >> C:\DEVELOPMENT\twits>ruby -v >> ruby 1.9.2p0 (2010-08-18) [i386-mingw32] >> >> C:\DEVELOPMENT\twits>gem list?local >> * LOCAL GEMS >> autotest (4.4.6) >> bundler (1.0.7) >> diff-lcs (1.1.2) >> git (1.2.5) >> jeweler (1.5.1) >> minitest (1.6.0) >> rake (0.8.7) >> rdiscount (1.6.5) >> rdoc (2.5.8) >> redcar (0.9.1) >> rspec (2.2.0) >> rspec-core (2.2.1) >> rspec-expectations (2.2.0) >> rspec-mocks (2.2.0) >> rubyzip (0.9.4) >> ZenTest (4.4.1) >> >> C:\DEVELOPMENT\twits>autospec >> ********************************************************** >> REMOVAL NOTICE: you are using behaviour that has been >> removed from rspec-2. >> >> * The ?autospec? command is no longer supported. >> * Please use ?autotest? insted. >> >> This message will be removed from a future version of rspec >> ********************************************************** >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > > Cheers, David From lists at ruby-forum.com Thu Dec 9 07:43:55 2010 From: lists at ruby-forum.com (Sid W.) Date: Thu, 09 Dec 2010 13:43:55 +0100 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: Message-ID: I'm running into this issue as well. Surely someone has a solution? Seems to be Rails 3.0.3. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Dec 9 07:55:45 2010 From: lists at ruby-forum.com (Sid W.) Date: Thu, 09 Dec 2010 13:55:45 +0100 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: Message-ID: Here is a simple example of the breaking code; ====== CODE ======== describe "payments/new.html.haml" do let(:payment) do mock_model("Payment").as_new_record.as_null_object end before do assign(:payment, payment) end it "renders a form to take payment details" do render rendered.should have_selector("form", :method => "post", :action => payments_path ) do |form| form.should have_selector("input", :type => "submit") end end it "renders a text field for the billing name" do payment.stub(:billing_name => "Mr. Test Pants") render rendered.should have_selector("form") do |form| form.should have_selector("input", :type => "text", :name => "payment[billing_name]", :value => "Mr. Test Pants" ) end end end =================== Here is the error; ====== ERROR ======== Failure/Error: form.should have_selector("input", expected following output to contain a tag:
=================== Attachments: http://www.ruby-forum.com/attachment/5528/example_spec.rb -- Posted via http://www.ruby-forum.com/. From resident.moron at gmail.com Wed Dec 8 23:39:13 2010 From: resident.moron at gmail.com (rails.impaired) Date: Wed, 8 Dec 2010 20:39:13 -0800 (PST) Subject: [rspec-users] displaying a note or comment when --format doc Message-ID: <22e97e49-04dc-4351-8184-66ee59869553@o14g2000yqe.googlegroups.com> I'm new to rspec, so, I might be coloring outside the lines, but, there have been several instances where I have wanted to display a comment or note. for example: describe "truck" do it "should require model" do end end rspec spec --format doc truck should require model What I mean by display a comment or note would be like: truck NOTE: blah, blah, blah... should require model Currently, I'm accomplishing this goal by using a describe with an empty block. Maybe I'm breaking some rules here, but, it just made sense to display a note given the particular spec I'm working on. Is there a way to accomplish the same thing other than using a describe with an empty block?? From dchelimsky at gmail.com Thu Dec 9 07:59:15 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Dec 2010 06:59:15 -0600 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: Message-ID: On Thu, Dec 9, 2010 at 6:43 AM, Sid W. wrote: > I'm running into this issue as well. Surely someone has a solution? > Seems to be Rails 3.0.3. Please be sure to quote relevant parts of the thread to provide context for people who are reading on phones, etc, that don't make it easy to see an entire thread. Here's a snip from the original post: I had a passing view spec using >= rspec-rails2. Then after updating to 2.1.0-2.2.1 it always fails. Thinking I was crazy I built the example in the rspec book, and I get the same thing. Here is the full source: https://github.com/matthewcalebsmith/rspec_issue.git If I switch out the message.stub(:title => "the title") in "it 'renders a text field for the message title' do" with assign(:message, mock_model("Message",:title => "the title").as_new_record), everything passes. Why does the stub not work anymore? Using the stub gives this: 1) messages/new.html.erb renders a text field for the message title Failure/Error: form.should have_selector("input", expected following output to contain a tag:
This is a regression that was introduced by an enhancement in rspec-mocks-2.2. It has been reported, identified, and fixed, but not yet released: https://github.com/rspec/rspec-rails/issues/closed#issue/266 I'll try to get an rspec-rails-2.2.2 release out this weekend with this fix. In the mean time, you can point your Gemfile to the branch on github and get the fix right now: gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails", :branch => "2-2-maintenance" HTH, David From lists at ruby-forum.com Thu Dec 9 08:08:17 2010 From: lists at ruby-forum.com (Michelle Pace) Date: Thu, 09 Dec 2010 14:08:17 +0100 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com>, <46a2089e-bcd7-4ebe-adff-ace255afaec4@k39g2000yqb.googlegroups.com>, <2d16df30d414cb2e8e0b60ad1c57b7e7@ruby-forum.com>, Message-ID: David Chelimsky wrote in post #967405: > # autotest-4.4.6 (with ZenTest-4.4.1) > autotest --style rspec2 Sorry David, truth be told I'm a ruby newbie working my way through the new book "Continuous Testing with Ruby" so I'm a bit in the dark here. For what you mention above, where do I put these settings since obviously not in discover.rb? Thanks in advance, Michelle -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Dec 9 08:18:07 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Dec 2010 07:18:07 -0600 Subject: [rspec-users] displaying a note or comment when --format doc In-Reply-To: <22e97e49-04dc-4351-8184-66ee59869553@o14g2000yqe.googlegroups.com> References: <22e97e49-04dc-4351-8184-66ee59869553@o14g2000yqe.googlegroups.com> Message-ID: <67012A46-1141-4421-A7BE-EB777A199243@gmail.com> On Dec 8, 2010, at 10:39 PM, rails.impaired wrote: > I'm new to rspec, so, I might be coloring outside the lines, but, > there have been several instances where I have wanted to display a > comment or note. > > for example: > > describe "truck" do > it "should require model" do > end > end > > rspec spec --format doc > > truck > should require model > > What I mean by display a comment or note would be like: > > truck > NOTE: blah, blah, blah... > should require model > > Currently, I'm accomplishing this goal by using a describe with an > empty block. Maybe I'm breaking some rules here, but, it just made > sense to display a note given the particular spec I'm working on. > > Is there a way to accomplish the same thing other than using a > describe with an empty block?? There is no direct support for comments _outside_ the documentation strings passed to describe() and it(), but you could use a "here doc": describe "truck" do it(<<-DOCSTRING) do NOTE: blah, blah, blah should require model DOCSTRING ... end end I probably wouldn't do this as it trades off readability in the spec for readability on the command line, but it would get you what you need. Cheers, David From dchelimsky at gmail.com Thu Dec 9 08:30:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Dec 2010 07:30:26 -0600 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> <46a2089e-bcd7-4ebe-adff-ace255afaec4@k39g2000yqb.googlegroups.com> <2d16df30d414cb2e8e0b60ad1c57b7e7@ruby-forum.com> Message-ID: On Thu, Dec 9, 2010 at 7:08 AM, Michelle Pace wrote: > David Chelimsky wrote in post #967405: >> # autotest-4.4.6 (with ZenTest-4.4.1) >> autotest --style rspec2 > > Sorry David, truth be told I'm a ruby newbie working my way > through the new book "Continuous Testing with Ruby" so I'm a bit in the > dark here. > > For what you mention above, where do I put these settings since > obviously not in discover.rb? These are commands you'd run from the command line. If you use the --style option, you don't need to worry about having ./autotest/discover.rb: $ autotest --style rspec2 This works with any of autotest-4.4.5, 4.4.6, and autotest-standalone-4.5.1. If you want to use ./autotest/discover.rb to tell autotest to use rspec instead of typing it on the command line, that only works with autotest-4.4.5 and autotest-standalone-4.5.1 (if you're using ruby-1.9, that is - if you're using ruby 1.8, it works with all three versions): $ autotest HTH, David > > Thanks in advance, Michelle > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Dec 9 09:05:31 2010 From: lists at ruby-forum.com (Sid W.) Date: Thu, 09 Dec 2010 15:05:31 +0100 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: , , Message-ID: <2865ba6bda7e02b2316733a673fbe1d0@ruby-forum.com> David Chelimsky wrote in post #967419: > > I'll try to get an rspec-rails-2.2.2 release out this weekend with > this fix. In the mean time, you can point your Gemfile to the branch > on github and get the fix right now: > > gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails", > :branch => "2-2-maintenance" You're an absolute star David. Thanks! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Dec 9 09:57:09 2010 From: lists at ruby-forum.com (Sid W.) Date: Thu, 09 Dec 2010 15:57:09 +0100 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: , , Message-ID: David Chelimsky wrote in post #967419: > This is a regression that was introduced by an enhancement in > rspec-mocks-2.2. It has been reported, identified, and fixed, but not > yet released: > > https://github.com/rspec/rspec-rails/issues/closed#issue/266 > > I'll try to get an rspec-rails-2.2.2 release out this weekend with > this fix. In the mean time, you can point your Gemfile to the branch > on github and get the fix right now: > > gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails", > :branch => "2-2-maintenance" > > HTH, > David It appears that the fix you mention is in master not 2-2-maintenance. Due to RSpec 2.3 dependancies I've added the following to my Gemfile gem 'rspec', :git => 'git://github.com/rspec/rspec.git' gem 'rspec-expectations', :git => 'git://github.com/rspec/rspec-expectations.git' gem 'rspec-core', :git => 'git://github.com/rspec/rspec-core.git' gem 'rspec-mocks', :git => 'git://github.com/rspec/rspec-mocks.git' gem 'rspec-rails', :git => 'git://github.com/rspec/rspec-rails' Unfortunately, the same error persists. :( -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Dec 9 10:08:42 2010 From: lists at ruby-forum.com (Sid W.) Date: Thu, 09 Dec 2010 16:08:42 +0100 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: , , , Message-ID: Sid W. wrote in post #967432: > gem 'rspec-rails', :git => 'git://github.com/rspec/rspec-rails' Missing .git corrected but still no joy. Sid W. wrote in post #967432: > It appears that the fix you mention is in master not 2-2-maintenance. > Due to RSpec 2.3 dependancies I've added the following to my Gemfile > > gem 'rspec', :git => 'git://github.com/rspec/rspec.git' > gem 'rspec-expectations', :git => > 'git://github.com/rspec/rspec-expectations.git' > gem 'rspec-core', :git => 'git://github.com/rspec/rspec-core.git' > gem 'rspec-mocks', :git => 'git://github.com/rspec/rspec-mocks.git' > gem 'rspec-rails', :git => 'git://github.com/rspec/rspec-rails' > > Unfortunately, the same error persists. :( So my previous code example works with the master branch gems except it breaks with the addition of another test block. The following code breaks with a similar error. ======== CODE ========== describe "payments/new.html.haml" do let(:payment) do mock_model("Payment").as_new_record.as_null_object end before do assign(:payment, payment) end it "renders a form to take payment details" do render rendered.should have_selector("form", :method => "post", :action => payments_path ) do |form| form.should have_selector("input", :type => "submit") end end it "renders a text field for the billing name" do payment.stub(:billing_name => "Mr. Test Pants") render rendered.should have_selector("form") do |form| form.should have_selector("input", :type => "text", :name => "payment[billing_name]", :value => "Mr. Test Pants" ) end end it "renders a text field for the first billing street address line" do payment.stub(:billing_street1 => "Flat 123") render rendered.should have_selector("form") do |form| form.should have_selector("input", :type => 'text', :name => 'payment[billing_address1]', :value => 'Flat 123' ) end end end ====================== Here is the error. ========ERROR========== Failure/Error: form.should have_selector("input", expected following output to contain a tag:
====================== -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Dec 9 10:31:55 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Dec 2010 09:31:55 -0600 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: , , Message-ID: <0347C949-E494-4594-B849-0D1D89E979E3@gmail.com> On Dec 9, 2010, at 8:57 AM, Sid W. wrote: > David Chelimsky wrote in post #967419: >> This is a regression that was introduced by an enhancement in >> rspec-mocks-2.2. It has been reported, identified, and fixed, but not >> yet released: >> >> https://github.com/rspec/rspec-rails/issues/closed#issue/266 >> >> I'll try to get an rspec-rails-2.2.2 release out this weekend with >> this fix. In the mean time, you can point your Gemfile to the branch >> on github and get the fix right now: >> >> gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails", >> :branch => "2-2-maintenance" >> >> HTH, >> David > > It appears that the fix you mention is in master not 2-2-maintenance. > Due to RSpec 2.3 dependancies I've added the following to my Gemfile > > gem 'rspec', :git => 'git://github.com/rspec/rspec.git' > gem 'rspec-expectations', :git => > 'git://github.com/rspec/rspec-expectations.git' > gem 'rspec-core', :git => 'git://github.com/rspec/rspec-core.git' > gem 'rspec-mocks', :git => 'git://github.com/rspec/rspec-mocks.git' > gem 'rspec-rails', :git => 'git://github.com/rspec/rspec-rails' > > Unfortunately, the same error persists. :( I cherry-picked the commit onto the 2-2-maintenance branch. Please try again with only rspec-rails coming from git. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From bploetz at gmail.com Thu Dec 9 15:22:23 2010 From: bploetz at gmail.com (Brian Ploetz) Date: Thu, 9 Dec 2010 12:22:23 -0800 (PST) Subject: [rspec-users] RSpec 2, Rails 3, and SSL routes Message-ID: Hi all, This is probably a stupid question, but I can't figure out how to do this..... If I have some routes which require SSL, how do I test that with RSpec? For example: # routes.rb scope :constraints => { :protocol => "https" } do match '/foos.(:format)' => 'foos#index', :via => :get, :constraints => { :format => /(json|xml)/ } end In my routing spec, I've tried the following variants with no luck: describe "routing to foos" do it "routes /foos.json to foos#index" do { :get => "/foos.json", :protocol => "https" }.should route_to( :controller => "foos", :action => "index", :format => "json" ) end describe "routing to foos" do it "routes /foos.json to foos#index" do { :get => "/foos.json" }.should route_to( :controller => "foos", :action => "index", :format => "json", :protocol => "https" ) end Thanks in advance for any help. BP From lists at ruby-forum.com Thu Dec 9 20:58:13 2010 From: lists at ruby-forum.com (Michelle Pace) Date: Fri, 10 Dec 2010 02:58:13 +0100 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> Message-ID: <78d9d467f863d75d3289d701a32bc301@ruby-forum.com> Hi David, sorry still no coconut. I should have explained myself better, I actually need to run the "autospec" command as the book says: "Thankfully, RSpec comes with a small script named autospec that reconfigures autotest to run specs instead, so try that..." So in the below I tried using your " --style rspec2" command for both autotest and *autospec*. Any ideas how I get autospec to run? C:\DEVELOPMENT\twits>autospec --style rspec2 ************************************************************ REMOVAL NOTICE: you are using behaviour that has been removed from rspec-2. * The 'autospec' command is no longer supported. * Please use 'autotest' insted. This message will be removed from a future version of rspec. ************************************************************ C:\DEVELOPMENT\twits>autotest --style rspec2 loading autotest/rspec2 bundle exec C:\devtools\Ruby192\bin\ruby -S C:/devtools/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2 .2.1/bin/rspec --tty 'C:/DEVELOPMENT/twits/spec/twits_spec.rb' Could not find gem 'rspec (~> 2.1.0, runtime)' in any of the gem sources listed in your Gemfile. Interrupt a second time to quit Terminate batch job (Y/N)? y Another quotation from this book which is sending me crazy: "Using RSpec 2? ----------------- The autospec command has been removed from RSpec 2, so if you?ve upgraded, you?ll need to do something a little different. You?re going to want to create a directory tree in the root of your project named autotest/.autotest. Then inside that you need to create a file named discover.rb. To that file we?ll need to add the statement Autotest.add_discovery { "rspec2" }." http://www.pragprog.com/titles/rcctr/continuous-testing-with-ruby Thanks again, Michelle -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Dec 9 21:38:49 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Dec 2010 20:38:49 -0600 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: <78d9d467f863d75d3289d701a32bc301@ruby-forum.com> References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> <78d9d467f863d75d3289d701a32bc301@ruby-forum.com> Message-ID: On Thu, Dec 9, 2010 at 7:58 PM, Michelle Pace wrote: > Hi David, sorry still no coconut. I should have explained myself better, > I actually need to run the "autospec" command as the book says: > "Thankfully, RSpec comes with a small script named autospec that > reconfigures autotest to run specs instead, so try that..." > > So in the below I tried using your " --style rspec2" command for both > autotest and *autospec*. Any ideas how I get autospec to run? > > > C:\DEVELOPMENT\twits>autospec --style rspec2 > ************************************************************ > REMOVAL NOTICE: you are using behaviour that has been > removed from rspec-2. > > * The 'autospec' command is no longer supported. > * Please use 'autotest' insted. > > This message will be removed from a future version of rspec. > ************************************************************ > > > C:\DEVELOPMENT\twits>autotest --style rspec2 > loading autotest/rspec2 > bundle exec C:\devtools\Ruby192\bin\ruby -S > C:/devtools/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2 > .2.1/bin/rspec --tty 'C:/DEVELOPMENT/twits/spec/twits_spec.rb' > Could not find gem 'rspec (~> 2.1.0, runtime)' in any of the gem sources > listed in your Gemfile. > Interrupt a second time to quit > Terminate batch job (Y/N)? y > > > Another quotation from this book which is sending me crazy: > ?"Using RSpec 2? > ?----------------- > ?The autospec command has been removed from RSpec 2, so > ?if you?ve upgraded, you?ll need to do something a little different. > ?You?re going to want to create a directory tree in the root > ?of your project named autotest/.autotest. This is wrong ^^. The directory should be named autotest, and the file named discover.rb. So if the project is at /home/michelle/my_project, you'd want /home/michelle/my_project/autotest/discover.rb, with: Autotest.add_discovery { "rspec2" } Then, from the /home/michelle/my_project directory, just type this: autotest Try that - it should work with autotest-4.4.5 (make sure you remove the ZenTest gem). HTH, David > Then inside that you > ?need to create a file named discover.rb. To that file we?ll need to > ?add the statement Autotest.add_discovery { "rspec2" }." > ?http://www.pragprog.com/titles/rcctr/continuous-testing-with-ruby > > Thanks again, > Michelle > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Fri Dec 10 02:18:45 2010 From: lists at ruby-forum.com (Michelle Pace) Date: Fri, 10 Dec 2010 08:18:45 +0100 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> Message-ID: Thanks (again) Dave for your reply and the time you've taken. However I think I must be really bad at explaining myself... so I've drawn a picture for you which to show my problem. [One of the requirements in the book is that I have to have ZenTest installed.] http://michellepace.com/pics/autospec-problem.jpg Again, any suggestions on how to get this working would really be appreciated. Michelle -- Posted via http://www.ruby-forum.com/. From kai.schlamp at googlemail.com Fri Dec 10 07:14:57 2010 From: kai.schlamp at googlemail.com (medihack) Date: Fri, 10 Dec 2010 04:14:57 -0800 (PST) Subject: [rspec-users] Transactional fixtures for Gem (not Rails) development Message-ID: Hello. Is it possible to also use the transactional examples feature for gem (not Rails) development. It seems that one has to require "rspec- rails", but I still can't get it to work. I added this to my spec_helper.rb: RSpec.configure do |config| config.use_transactional_fixtures = true end And also required: require 'rubygems' require 'bundler' require 'logger' require 'active_record' require 'rails' require 'rspec-rails' require 'active_support' But I get that error when running a test: undefined method `use_transactional_fixtures=' for # (NoMethodError) although I required rspec-rails and rails as mentioned above Is it simply not possible to use transactional examples for gem development? Best regards, Kai From dchelimsky at gmail.com Fri Dec 10 07:52:47 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Dec 2010 06:52:47 -0600 Subject: [rspec-users] Transactional fixtures for Gem (not Rails) development In-Reply-To: References: Message-ID: On Dec 10, 2010, at 6:14 AM, medihack wrote: > Hello. > > Is it possible to also use the transactional examples feature for gem > (not Rails) development. Nope. That feature is not implemented in RSpec, it is implemented in Rails. RSpec just provides access to it. > It seems that one has to require "rspec- > rails", but I still can't get it to work. > > I added this to my spec_helper.rb: > RSpec.configure do |config| > config.use_transactional_fixtures = true > end > > And also required: > require 'rubygems' > require 'bundler' > require 'logger' > require 'active_record' > require 'rails' > require 'rspec-rails' > require 'active_support' > > But I get that error when running a test: > undefined method `use_transactional_fixtures=' for > # (NoMethodError) > although I required rspec-rails and rails as mentioned above > > Is it simply not possible to use transactional examples for gem > development? You can (and probably should) use the database_cleaner gem. Directions for using it with RSpec are at the bottom of the README on https://github.com/bmabey/database_cleaner. Cheers, David > Best regards, > Kai From dchelimsky at gmail.com Fri Dec 10 07:56:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Dec 2010 06:56:57 -0600 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> Message-ID: On Dec 10, 2010, at 1:18 AM, Michelle Pace wrote: > Thanks (again) Dave for your reply and the time you've taken. > > However I think I must be really bad at explaining myself... so I've > drawn a picture for you which to show my problem. [One of the > requirements in the book is that I have to have ZenTest installed.] You're explaining yourself just fine. The problem is that you're listening 1/2 to the book and 1/2 to me, but you need to just listen to me right now :) The problem is as follows: * the book uses ruby-1.8 * you are using ruby-1.9 * ruby-1.8 includes "." on the $LOAD_PATH * ruby-1.9 does _not_ include "." on the $LOAD_PATH * ZenTest-4.4.1 does _not_ add "." to the $LOAD_PATH * these last two ^^ mean that if you're using ruby-1.9, rspec-2, and ZenTest-4.4.1, the autotest command that ships with ZenTest will not find './autotest/discover.rb' and will not load the correct class * per the error message you got when you ran autospec, autospec has been removed from rspec-2, so you have to use the autotest command Any of the following combinations _will_ work: 1) Run the following commands $ gem uninstall ZenTest $ gem uninstall autotest $ gem install autotest -v 4.4.5 $ autotest Again, use autotest, not autospec. autotest-4.4.5 is a standalone autotest gem that does not require ZenTest. This will work using the autotest/discover.rb file because autotest-4.4.5 adds "." to the $LOAD_PATH. 2) $ gem uninstall autotest $ gem install ZenTest At this point you have the book's recommended setup, but the autotest command will not see autotest/discover.rb. Your options are: a) add "." to the $LOAD_PATH yourself $ ruby -I . -S autotest The -I option tells ruby to add its argument ('.') to the command line. The -S option tells ruby what script to run (autotest). b) Use autotest's --style option $ autotest --style rspec2 This bypasses the search for autotest/discover.rb (so you can delete it if you're using this) and "just works." There are other options, but I don't want to confuse you any further. I really hope this clears things up. Also, I've reported this issue to the ZenTest project, so there is some chance that ZenTest-4.4.2 will add "." to the $LOAD_PATH, at which point the material in the book will work as written (except that the file is "autotest/discover.rb", not "autotest/.autotest/discover.rb") with ruby-1.9. Good luck! Cheers, David > > http://michellepace.com/pics/autospec-problem.jpg > > Again, any suggestions on how to get this working would really be > appreciated. > > Michelle > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From rick.denatale at gmail.com Fri Dec 10 09:25:06 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 10 Dec 2010 09:25:06 -0500 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> Message-ID: Michelle, I think that the problem is that after that setup you want to use the command autotest and NOT autospec The book pages you have in your picture say that autospec has been removed from rspec2 but don't state explicitly that you should use the autotest command rather than autospec. Since "Continuous Testing with Ruby" is a beta book (first time I've heard of it I must say), the authors would probably appreciate it if you posted an erratum to the book's site. On Fri, Dec 10, 2010 at 2:18 AM, Michelle Pace wrote: > Thanks (again) Dave for your reply and the time you've taken. > > However I think I must be really bad at explaining myself... so I've > drawn a picture for you which to show my problem. [One of the > requirements in the book is that I have to have ZenTest installed.] > > http://michellepace.com/pics/autospec-problem.jpg > > Again, any suggestions on how to get this working would really be > appreciated. > > Michelle > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From babitha.augusthy at gmail.com Fri Dec 10 06:43:21 2010 From: babitha.augusthy at gmail.com (Babitha Augusthy) Date: Fri, 10 Dec 2010 05:43:21 -0600 Subject: [rspec-users] RSpec2 not supported in Netbeans Message-ID: Hi All, RSpec2 doesn't seem to be supported in Netbeans. When I try to run RSpec in Netbeans, it says the command 'spec' not found. Does anybody have any information if this will be corrected? Thanks, Babitha -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Fri Dec 10 10:56:36 2010 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 10 Dec 2010 15:56:36 +0000 Subject: [rspec-users] Comparing files Message-ID: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Hello folks, I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: File.read(uploaded_file_path).should == File.read(path_to_expected_file) Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? cheers, Matt matt at mattwynne.net 07974 430184 From dolzenko at gmail.com Fri Dec 10 11:13:17 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Fri, 10 Dec 2010 19:13:17 +0300 Subject: [rspec-users] Comparing files In-Reply-To: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Message-ID: <4D02519D.9090509@gmail.com> I would just compare the size. Or you can get the MD5 and compare that to be 100% sure, and avoid the ugly diff too. On 12/10/2010 6:56 PM, Matt Wynne wrote: > Hello folks, > > I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: > > File.read(uploaded_file_path).should == File.read(path_to_expected_file) > > Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Fri Dec 10 11:27:10 2010 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 10 Dec 2010 16:27:10 +0000 Subject: [rspec-users] Comparing files In-Reply-To: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Message-ID: On 10 Dec 2010, at 15:56, Matt Wynne wrote: > Hello folks, > > I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: > > File.read(uploaded_file_path).should == File.read(path_to_expected_file) > > Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 Too slow people. Jeez! I invented something: https://gist.github.com/736421 cheers, Matt matt at mattwynne.net 07974 430184 From lists at iDIAcomputing.com Fri Dec 10 11:39:35 2010 From: lists at iDIAcomputing.com (George Dinwiddie) Date: Fri, 10 Dec 2010 10:39:35 -0600 Subject: [rspec-users] RSpec2 not supported in Netbeans In-Reply-To: References: Message-ID: <4D0257C7.3020004@iDIAcomputing.com> On 12/10/10 5:43 AM, Babitha Augusthy wrote: > Hi All, > RSpec2 doesn't seem to be supported in Netbeans. When I try to run RSpec > in Netbeans, it says the command 'spec' not found. Does anybody have any > information if this will be corrected? I don't know beans about Netbeans, but try the command 'rspec' instead. -- Dec. 14 - Agile Richmond in Glen Allen, VA http://georgedinwiddie.eventbrite.com/ ---------------------------------------------------------------------- * George Dinwiddie * http://blog.gdinwiddie.com Software Development http://www.idiacomputing.com Consultant and Coach http://www.agilemaryland.org ---------------------------------------------------------------------- From joe at josephwilk.net Fri Dec 10 11:41:19 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Fri, 10 Dec 2010 16:41:19 +0000 Subject: [rspec-users] Comparing files In-Reply-To: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Message-ID: <4D02582F.2030607@josephwilk.net> On 10/12/2010 15:56, Matt Wynne wrote: > Hello folks, > > I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: > > File.read(uploaded_file_path).should == File.read(path_to_expected_file) > > Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? > In the past I've generated a checksum for each file and compare that. -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 From benjamin.lovell at gmail.com Fri Dec 10 11:45:31 2010 From: benjamin.lovell at gmail.com (Ben Lovell) Date: Fri, 10 Dec 2010 16:45:31 +0000 Subject: [rspec-users] Comparing files In-Reply-To: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Message-ID: <777836B6-BFE2-4710-8CF6-D2C054A1B568@gmail.com> Cyclic redundancy check (crc) Sent from my iPhone On 10 Dec 2010, at 15:56, Matt Wynne wrote: > Hello folks, > > I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: > > File.read(uploaded_file_path).should == File.read(path_to_expected_file) > > Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From joe at josephwilk.net Fri Dec 10 11:48:22 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Fri, 10 Dec 2010 16:48:22 +0000 Subject: [rspec-users] Comparing files In-Reply-To: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Message-ID: <4D0259D6.4020208@josephwilk.net> On 10/12/2010 15:56, Matt Wynne wrote: > Hello folks, > > I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: > > File.read(uploaded_file_path).should == File.read(path_to_expected_file) > > Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? > In the past I've generated a checksum for each file and compared that. -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 From joe at josephwilk.net Fri Dec 10 11:23:31 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Fri, 10 Dec 2010 16:23:31 +0000 Subject: [rspec-users] Comparing files In-Reply-To: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Message-ID: On Fri, Dec 10, 2010 at 3:56 PM, Matt Wynne wrote: > Hello folks, > > I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: > > File.read(uploaded_file_path).should == File.read(path_to_expected_file) > > Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? In the past I've generated a checksum for each file and compare that. -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at iDIAcomputing.com Fri Dec 10 11:30:40 2010 From: lists at iDIAcomputing.com (George Dinwiddie) Date: Fri, 10 Dec 2010 10:30:40 -0600 Subject: [rspec-users] Comparing files In-Reply-To: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Message-ID: <4D0255B0.4090503@iDIAcomputing.com> Matt, On 12/10/10 9:56 AM, Matt Wynne wrote: > Hello folks, > > I'm writing some tests for file upload code. The files are binary, > images mostly. I'm futzing around a bit, trying to figure out how to > assert that the uploaded file is the same as some golden master. If I > do this: > > File.read(uploaded_file_path).should == > File.read(path_to_expected_file) > > Then when it fails, I get an ugly diff of the difference between the > binary files. So I'm about to invent something of my own. Has anyone > got a good pattern for doing this already? I don't already have it, but I've long wanted to implement a visual image diff based on an exclusive-or of the two images. This would give a quick visual demonstration of the differences. I once saw (but now cannot find) and image compare library that did a "fuzzy compare" that wasn't fooled by pixel differences. I've looked for this several times, but haven't been able to turn it up again. It's out there, though, in the scientific community (IIRC) rather than the software testing community. - George -- Dec. 14 - Agile Richmond in Glen Allen, VA http://georgedinwiddie.eventbrite.com/ ---------------------------------------------------------------------- * George Dinwiddie * http://blog.gdinwiddie.com Software Development http://www.idiacomputing.com Consultant and Coach http://www.agilemaryland.org ---------------------------------------------------------------------- From joshuachisholm at gmail.com Fri Dec 10 13:07:44 2010 From: joshuachisholm at gmail.com (Josh Chisholm) Date: Fri, 10 Dec 2010 18:07:44 +0000 Subject: [rspec-users] Comparing files In-Reply-To: <4D0255B0.4090503@iDIAcomputing.com> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> <4D0255B0.4090503@iDIAcomputing.com> Message-ID: On Fri, Dec 10, 2010 at 4:30 PM, George Dinwiddie wrote: > Matt, > > On 12/10/10 9:56 AM, Matt Wynne wrote: >> >> Hello folks, >> >> I'm writing some tests for file upload code. The files are binary, >> images mostly. I'm futzing around a bit, trying to figure out how to >> assert that the uploaded file is the same as some golden master. If I >> do this: >> >> File.read(uploaded_file_path).should == >> File.read(path_to_expected_file) >> >> Then when it fails, I get an ugly diff of the difference between the >> binary files. So I'm about to invent something of my own. Has anyone >> got a good pattern for doing this already? > > I don't already have it, but I've long wanted to implement a visual image > diff based on an exclusive-or of the two images. ?This would give a quick > visual demonstration of the differences. > > I once saw (but now cannot find) and image compare library that did a "fuzzy > compare" that wasn't fooled by pixel differences. ?I've looked for this > several times, but haven't been able to turn it up again. ?It's out there, > though, in the scientific community (IIRC) rather than the software testing > community. I think some teams at the BBC have used this tool for that kind of fuzzy image comparison: http://pdiff.sourceforge.net/ Josh > > ?- George > > -- > ?Dec. 14 - Agile Richmond in Glen Allen, VA > ?http://georgedinwiddie.eventbrite.com/ > ?---------------------------------------------------------------------- > ?* George Dinwiddie * ? ? ? ? ? ? ? ? ? ? ?http://blog.gdinwiddie.com > ?Software Development ? ? ? ? ? ? ? ? ? ?http://www.idiacomputing.com > ?Consultant and Coach ? ? ? ? ? ? ? ? ? ?http://www.agilemaryland.org > ?---------------------------------------------------------------------- > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nellboy at gmail.com Fri Dec 10 14:43:36 2010 From: nellboy at gmail.com (Paul Nelligan) Date: Fri, 10 Dec 2010 19:43:36 +0000 Subject: [rspec-users] RSpec2 not supported in Netbeans In-Reply-To: <4D0257C7.3020004@iDIAcomputing.com> References: <4D0257C7.3020004@iDIAcomputing.com> Message-ID: Generally I use the command line for testing. Netbeans can be a little flakey. That said, check the config of your project in netbeans. Some of the defaults applied by netbeans aren't always the correct options. sent via Android mobile On 10 Dec 2010 17:11, "George Dinwiddie" wrote: > On 12/10/10 5:43 AM, Babitha Augusthy wrote: >> Hi All, >> RSpec2 doesn't seem to be supported in Netbeans. When I try to run RSpec >> in Netbeans, it says the command 'spec' not found. Does anybody have any >> information if this will be corrected? > > I don't know beans about Netbeans, but try the command 'rspec' instead. > > -- > Dec. 14 - Agile Richmond in Glen Allen, VA > http://georgedinwiddie.eventbrite.com/ > ---------------------------------------------------------------------- > * George Dinwiddie * http://blog.gdinwiddie.com > Software Development http://www.idiacomputing.com > Consultant and Coach http://www.agilemaryland.org > ---------------------------------------------------------------------- > > _______________________________________________ > 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 Gennady.Bystritsky at quest.com Fri Dec 10 15:25:30 2010 From: Gennady.Bystritsky at quest.com (Gennady Bystritsky) Date: Fri, 10 Dec 2010 20:25:30 +0000 Subject: [rspec-users] RSpec2: How to avoid an example run when previous failed Message-ID: <4E17BA9B-A020-4C52-A089-C4FF4D3786EA@quest.com> Is there a way not to execute an example when another one fails? I want to minimize failure noises in cases when, say, one spec checks that an array has an expected number of elements while the others drill down on a specific element. However, when there's a wrong number of elements in the first place, other failures are just noise. Consider the following spec: 1 class Sample 2 attr_reader :items 3 def initialize(number) 4 @items = (1 .. number).map { |_item| 5 Struct.new(:name).new("ITEM:#{_item}") 6 } 7 end 8 end 9 10 describe Sample, "when creating 2 named items" do 11 let(:items) { Sample.new(2).items } 12 subject { items } 13 14 it { should have(2).entries } 15 16 context "first item" do 17 subject { items.first } 18 its(:name) { should == "ITEM:1" } 19 end 20 21 context "last item" do 22 subject { items.last } 23 its(:name) { should == "ITEM:2" } 24 end 25 end When run, it produces the following: $ rspec -fd sample_spec.rb Sample when creating 2 named items should have 2 entries first item name should == "ITEM:1" last item name should == "ITEM:2" Finished in 0.00158 seconds 3 examples, 0 failures Everything is great until I have an "innocent" bug in the range in line 4, like "(1 ... number)" instead of "(1 .. number)". In which case the above command will produce this: $ rspec -fd sample_spec.rb Sample when creating 2 named items should have 2 entries (FAILED - 1) first item name should == "ITEM:1" last item name should == "ITEM:2" (FAILED - 2) Failures: 1) Sample when creating 2 named items Failure/Error: it { should have(2).entries } expected 2 entries, got 1 # ./sample_spec.rb:14 2) Sample when creating 2 named items last item name Failure/Error: its(:name) { should == "ITEM:2" } expected: "ITEM:2", got: "ITEM:1" (using ==) # ./sample_spec.rb:23 Finished in 0.00167 seconds 3 examples, 2 failures In the above, failure 2) is a direct result of failure 1) and would be great to avoided if possible. Especially if I want to spec much more stuff there with much more noise being displayed. Thank you for your help, Gennady. From ben at benmabey.com Fri Dec 10 11:21:47 2010 From: ben at benmabey.com (Ben Mabey) Date: Fri, 10 Dec 2010 09:21:47 -0700 Subject: [rspec-users] Comparing files In-Reply-To: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> Message-ID: <4D02539B.4060300@benmabey.com> On 12/10/10 8:56 AM, Matt Wynne wrote: > Hello folks, > > I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: > > File.read(uploaded_file_path).should == File.read(path_to_expected_file) > > Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? > > cheers, > Matt I would compare the file's MD5 (or other) hash. It won't tell you what is different.. just that they aren't identical which is what I think you want. So... something like: Digest::MD5.hexdigest(File.read(uploaded_file_path)).should == Digest::MD5.hexdigest(File.read(path_to_expected_file)) -Ben From wagner.andrew at gmail.com Fri Dec 10 17:29:10 2010 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Fri, 10 Dec 2010 17:29:10 -0500 Subject: [rspec-users] "unit" vs. "functional" specs Message-ID: I went back and forth on whether to send this to this list or the ruby-talk list, so feel free to tell me to take a hike... I'm working on a personal project where I'm trying to keep a really high bar on quality. One of the ways I'm doing that is to stick very close to the BDD/TDD cycle as suggested in the RSpec book. However, I'm actually using rspec for both the feature-level (BDD) tests and the unit-level (TDD) tests. I'm also striving for 100% test coverage using Simplecov. That said, I just realized that, to enforce that cycle, it's also important that I ask "do my unit tests by themselves provide 100% test coverage?". Because, otherwise, it's easy to get excited and write code to make the feature past, that isn't TDD'd. Anyway, all that to ask: is there some way to configure Simplecov to emit code coverage stats for just a subset of all the tests that are running? That is, I want to set up my rakefile such that it runs all my tests, but only reports on code coverage for the unit tests. Am I going about this with the right mindset? Any suggestions? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at iDIAcomputing.com Fri Dec 10 20:41:08 2010 From: lists at iDIAcomputing.com (George Dinwiddie) Date: Fri, 10 Dec 2010 19:41:08 -0600 Subject: [rspec-users] Comparing files In-Reply-To: References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> <4D0255B0.4090503@iDIAcomputing.com> Message-ID: <4D02D6B4.6070302@iDIAcomputing.com> On 12/10/10 12:07 PM, Josh Chisholm wrote: > On Fri, Dec 10, 2010 at 4:30 PM, George Dinwiddie > wrote: >> I once saw (but now cannot find) and image compare library that did a "fuzzy >> compare" that wasn't fooled by pixel differences. I've looked for this >> several times, but haven't been able to turn it up again. It's out there, >> though, in the scientific community (IIRC) rather than the software testing >> community. > > I think some teams at the BBC have used this tool for that kind of > fuzzy image comparison: http://pdiff.sourceforge.net/ Josh, thank you for that! - George -- Dec. 14 - Agile Richmond in Glen Allen, VA http://georgedinwiddie.eventbrite.com/ ---------------------------------------------------------------------- * George Dinwiddie * http://blog.gdinwiddie.com Software Development http://www.idiacomputing.com Consultant and Coach http://www.agilemaryland.org ---------------------------------------------------------------------- From matt at mattwynne.net Sat Dec 11 04:03:43 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 11 Dec 2010 09:03:43 +0000 Subject: [rspec-users] Comparing files In-Reply-To: <4D02539B.4060300@benmabey.com> References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> <4D02539B.4060300@benmabey.com> Message-ID: On 10 Dec 2010, at 16:21, Ben Mabey wrote: > On 12/10/10 8:56 AM, Matt Wynne wrote: >> Hello folks, >> >> I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: >> >> File.read(uploaded_file_path).should == File.read(path_to_expected_file) >> >> Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? >> >> cheers, >> Matt > > I would compare the file's MD5 (or other) hash. It won't tell you what is different.. just that they aren't identical which is what I think you want. So... something like: > > Digest::MD5.hexdigest(File.read(uploaded_file_path)).should == Digest::MD5.hexdigest(File.read(path_to_expected_file)) > > -Ben Great minds, Ben :) I ended up with this: https://gist.github.com/736421 cheers, Matt matt at mattwynne.net 07974 430184 From jgadbois at gmail.com Fri Dec 10 17:15:13 2010 From: jgadbois at gmail.com (John Gadbois) Date: Fri, 10 Dec 2010 17:15:13 -0500 Subject: [rspec-users] @current_user in controller specs Message-ID: Hi, I'm an absolute beginner with RSpec, so I apologize if this question doesn't make sense. I'm using RSpec 2, Rails 3. I have a @current_user instance variable that I can access in my controller. I have a controller called PlanOrderController. In the create action of this model, I would like to assign the user_id of the PlanOrder object to be the user_id of the @current_user before saving. I have the generated rails controller specs so I'm starting with those. Basically I want my controller spec for the create action to test to make sure that the newly created PlanOrder has it's user_id property set to @ current_user.id The code I have so far is below but it's not working it "sets the user id to the logged on user" do @current_user = User.new(:id=>27) controller.stub!(:current_user).and_return(@current_user) PlanOrder.stub(:new).with({"days_per_week" => 3, "description"=>"Test", "purpose_id"=>1 }) { mock_plan_order(:save => true) } post :create, :plan_order =>{"days_per_week" => 3, "description"=>"Test", "purpose_id"=>1 } plan_order = assigns(:plan_order) plan_order.user_id.should be(@current_user.id) end Any help would be appreciated. Thanks, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Sat Dec 11 08:04:36 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 11 Dec 2010 13:04:36 +0000 Subject: [rspec-users] "unit" vs. "functional" specs In-Reply-To: References: Message-ID: On 10 Dec 2010, at 22:29, Andrew Wagner wrote: > I went back and forth on whether to send this to this list or the ruby-talk list, so feel free to tell me to take a hike... > > I'm working on a personal project where I'm trying to keep a really high bar on quality. One of the ways I'm doing that is to stick very close to the BDD/TDD cycle as suggested in the RSpec book. However, I'm actually using rspec for both the feature-level (BDD) tests and the unit-level (TDD) tests. I'm also striving for 100% test coverage using Simplecov. > > That said, I just realized that, to enforce that cycle, it's also important that I ask "do my unit tests by themselves provide 100% test coverage?". Because, otherwise, it's easy to get excited and write code to make the feature past, that isn't TDD'd. > > Anyway, all that to ask: is there some way to configure Simplecov to emit code coverage stats for just a subset of all the tests that are running? That is, I want to set up my rakefile such that it runs all my tests, but only reports on code coverage for the unit tests. > > Am I going about this with the right mindset? Any suggestions? I haven't used simplecov myself, but I can answer the mindset question. If I were you, I would want three numbers: the overall coverage from your unit + functional tests, the coverage from your unit tests alone, and the coverage from your functional tests alone. As long as you're consistently working outside in, and driving each change to the code with *some kind of test* I would be happy with that, but it would be interesting to see where the coverage comes from. As you learn to trust yourself to do things test-first, you'll find you need the code coverage figure less and less, because your conscience knows it's 100%. These days, unless I'm rescuing a legacy project, I only really use code coverage to tell me about unused code that I can delete. cheers, Matt matt at mattwynne.net 07974 430184 From matt at mattwynne.net Sat Dec 11 08:14:42 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 11 Dec 2010 13:14:42 +0000 Subject: [rspec-users] RSpec2: How to avoid an example run when previous failed In-Reply-To: <4E17BA9B-A020-4C52-A089-C4FF4D3786EA@quest.com> References: <4E17BA9B-A020-4C52-A089-C4FF4D3786EA@quest.com> Message-ID: <325106E3-545E-4F76-B212-8D57E57442D8@mattwynne.net> On 10 Dec 2010, at 20:25, Gennady Bystritsky wrote: > Is there a way not to execute an example when another one fails? I want to minimize failure noises in cases when, say, one spec checks that an array has an expected number of elements while the others drill down on a specific element. However, when there's a wrong number of elements in the first place, other failures are just noise. > > Consider the following spec: > > 1 class Sample > 2 attr_reader :items > 3 def initialize(number) > 4 @items = (1 .. number).map { |_item| > 5 Struct.new(:name).new("ITEM:#{_item}") > 6 } > 7 end > 8 end > 9 > 10 describe Sample, "when creating 2 named items" do > 11 let(:items) { Sample.new(2).items } > 12 subject { items } > 13 > 14 it { should have(2).entries } > 15 > 16 context "first item" do > 17 subject { items.first } > 18 its(:name) { should == "ITEM:1" } > 19 end > 20 > 21 context "last item" do > 22 subject { items.last } > 23 its(:name) { should == "ITEM:2" } > 24 end > 25 end > > When run, it produces the following: > > $ rspec -fd sample_spec.rb > > Sample when creating 2 named items > should have 2 entries > first item > name > should == "ITEM:1" > last item > name > should == "ITEM:2" > > Finished in 0.00158 seconds > 3 examples, 0 failures > > Everything is great until I have an "innocent" bug in the range in line 4, like "(1 ... number)" instead of "(1 .. number)". In which case the above command will produce this: > > $ rspec -fd sample_spec.rb > > Sample when creating 2 named items > should have 2 entries (FAILED - 1) > first item > name > should == "ITEM:1" > last item > name > should == "ITEM:2" (FAILED - 2) > > Failures: > > 1) Sample when creating 2 named items > Failure/Error: it { should have(2).entries } > expected 2 entries, got 1 > # ./sample_spec.rb:14 > > 2) Sample when creating 2 named items last item name > Failure/Error: its(:name) { should == "ITEM:2" } > expected: "ITEM:2", > got: "ITEM:1" (using ==) > # ./sample_spec.rb:23 > > Finished in 0.00167 seconds > 3 examples, 2 failures > > In the above, failure 2) is a direct result of failure 1) and would be great to avoided if possible. Especially if I want to spec much more stuff there with much more noise being displayed. > > Thank you for your help, > Gennady. I don't consider that noise, I consider it useful clues as to what's wrong. cheers, Matt matt at mattwynne.net 07974 430184 From dchelimsky at gmail.com Sat Dec 11 10:54:42 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 11 Dec 2010 09:54:42 -0600 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> Message-ID: On Fri, Dec 10, 2010 at 6:56 AM, David Chelimsky wrote: > > On Dec 10, 2010, at 1:18 AM, Michelle Pace wrote: > >> Thanks (again) Dave for your reply and the time you've taken. >> >> However I think I must be really bad at explaining myself... so I've >> drawn a picture for you which to show my problem. [One of the >> requirements in the book is that I have to have ZenTest installed.] > > You're explaining yourself just fine. The problem is that you're listening 1/2 to the book and 1/2 to me, but you need to just listen to me right now :) > > The problem is as follows: > > * the book uses ruby-1.8 > * you are using ruby-1.9 > * ruby-1.8 includes "." on the $LOAD_PATH > * ruby-1.9 does _not_ include "." on the $LOAD_PATH > * ZenTest-4.4.1 does _not_ add "." to the $LOAD_PATH > * these last two ^^ mean that if you're using ruby-1.9, rspec-2, and ZenTest-4.4.1, the autotest command that ships with ZenTest will not find './autotest/discover.rb' and will not load the correct class > * per the error message you got when you ran autospec, autospec has been removed from rspec-2, so you have to use the autotest command > > Any of the following combinations _will_ work: > > 1) Run the following commands > $ gem uninstall ZenTest > $ gem uninstall autotest > $ gem install autotest -v 4.4.5 > $ autotest > > Again, use autotest, not autospec. autotest-4.4.5 is a standalone autotest gem that does not require ZenTest. This will work using the autotest/discover.rb file because autotest-4.4.5 adds "." to the $LOAD_PATH. > > 2) > $ gem uninstall autotest > $ gem install ZenTest > > At this point you have the book's recommended setup, but the autotest command will not see autotest/discover.rb. Your options are: > > a) add "." to the $LOAD_PATH yourself > $ ruby -I . -S autotest > > The -I option tells ruby to add its argument ('.') to the command line. The -S option tells ruby what script to run (autotest). > > b) Use autotest's --style option > $ autotest --style rspec2 > > This bypasses the search for autotest/discover.rb (so you can delete it if you're using this) and "just works." > > There are other options, but I don't want to confuse you any further. I really hope this clears things up. > > Also, I've reported this issue to the ZenTest project, so there is some chance that ZenTest-4.4.2 will add "." to the $LOAD_PATH, at which point the material in the book will work as written (except that the file is "autotest/discover.rb", not "autotest/.autotest/discover.rb") with ruby-1.9. > > Good luck! FYI - Ryan Davis, in spite of his clear distaste for the approach [1], just released ZenTest-4.4.2, which fixes this issue. Cheers, David [1] https://github.com/seattlerb/zentest/commit/e9de80cbc5cca1026197dcb0f3612cf330491556 > > Cheers, > David > > > >> >> http://michellepace.com/pics/autospec-problem.jpg >> >> Again, any suggestions on how to get this working would really be >> appreciated. >> >> Michelle >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > > > From luislavena at gmail.com Sat Dec 11 11:38:09 2010 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 11 Dec 2010 13:38:09 -0300 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> Message-ID: On Sat, Dec 11, 2010 at 12:54 PM, David Chelimsky wrote: > > FYI - Ryan Davis, in spite of his clear distaste for the approach [1], > just released ZenTest-4.4.2, which fixes this issue. > Now that .rspec file is the recommended way of providing options for RSpec2, can we use that to detect discovery? Just a suggestion to avoid these type of conversations ;-) Here is Bacon approach, checking for .bacon file https://github.com/chneukirchen/bacon/blob/master/lib/autotest/discover.rb -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From dchelimsky at gmail.com Sat Dec 11 12:33:29 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 11 Dec 2010 11:33:29 -0600 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> Message-ID: <493F76A3-B063-4C11-B798-9647AE1C0199@gmail.com> On Dec 11, 2010, at 10:38 AM, Luis Lavena wrote: > On Sat, Dec 11, 2010 at 12:54 PM, David Chelimsky wrote: >> >> FYI - Ryan Davis, in spite of his clear distaste for the approach [1], >> just released ZenTest-4.4.2, which fixes this issue. >> > > Now that .rspec file is the recommended way of providing options for > RSpec2, can we use that to detect discovery? > > Just a suggestion to avoid these type of conversations ;-) > > Here is Bacon approach, checking for .bacon file > > https://github.com/chneukirchen/bacon/blob/master/lib/autotest/discover.rb One step ahead of you :) https://github.com/rspec/rspec-core/commit/dc1b0d53fde7505bb5769884e5c54b09b6886f89 > -- > Luis Lavena Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From shea at shealevy.com Sat Dec 11 12:47:07 2010 From: shea at shealevy.com (Shea Levy) Date: Sat, 11 Dec 2010 09:47:07 -0800 Subject: [rspec-users] Rescuing a Test-Free Project with RSpec and Cucumber Message-ID: Hi all, I was recently brought onto a Rails 2.2.3 project which was itself an emergency rescue of a spaghetti-coded PHP project (complete with hard-coded SQL statements!). Due to the fact that the code was already in production and has required fairly constant maintenance and feature additions, the dev who switched everything over to Rails hasn't written a single test. The eventual goal, the achievement of which is one of my primary responsibilities on the project, is to have the project be migrated to Rails 3, fully spec'd at all levels and documented at the top level with Cucumber features, matching Rails conventions (e.g. the database table for the Shop model is currently 'shops_master' and will eventually be 'shops') and with all vestiges of the original project completely removed (there's still some PHP code running on the production site). My question is: what's the best approach to get from here to there? Is it possible to do this gradually while development continues on the current project, or is a total refresh going to be necessary? I'd much prefer a gradual approach because the other dev on the project is working full-time on adding features to and maintaining the current site and all of my responsibilities outside of the migration will be focused on adding features to the current site, so if I were to do a complete refresh any work from here on out would be completely duplicated. Additionally, the other dev on the project (who has much more general coding experience than I do) won't be able to spare time to help me out with problems on a refresh the way he would if any gradual changes were implemented on the current project. The only problem with the gradual approach is that I have no idea how to actually do it! Do I start with unit-tests of the already-existing code and work my way out to features, or do I start with features describing things already implemented and work my way in? Do I try to convince the other dev to start outside-in with all new features now, or do I wait until I've done more with what's already there? Are there any good resources out there for tasks like this? Also, if a refresh IS necessary: what's the best way to go about replicating the functionality of an existing project? tl;dr: Is it possible to save a test-free project via gradual steps, or is a complete refresh necessary? If the former, how do I go about doing that? If the latter, how do I do it in a way that keeps overall functionality of the resulting project the same as the original? Cheers, Shea Levy -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Dec 11 13:24:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 11 Dec 2010 12:24:33 -0600 Subject: [rspec-users] Rescuing a Test-Free Project with RSpec and Cucumber In-Reply-To: References: Message-ID: <5E689383-4B46-4813-919E-57E71215DCF6@gmail.com> On Dec 11, 2010, at 11:47 AM, Shea Levy wrote: > Hi all, > > I was recently brought onto a Rails 2.2.3 project which was itself an emergency rescue of a spaghetti-coded PHP project (complete with hard-coded SQL statements!). Due to the fact that the code was already in production and has required fairly constant maintenance and feature additions, the dev who switched everything over to Rails hasn't written a single test. The eventual goal, the achievement of which is one of my primary responsibilities on the project, is to have the project be migrated to Rails 3, fully spec'd at all levels and documented at the top level with Cucumber features, matching Rails conventions (e.g. the database table for the Shop model is currently 'shops_master' and will eventually be 'shops') and with all vestiges of the original project completely removed (there's still some PHP code running on the production site). My question is: what's the best approach to get from here to there? Is it possible to do this gradually while development continues on the current project, or is a total refresh going to be necessary? I'd much prefer a gradual approach because the other dev on the project is working full-time on adding features to and maintaining the current site and all of my responsibilities outside of the migration will be focused on adding features to the current site, so if I were to do a complete refresh any work from here on out would be completely duplicated. Additionally, the other dev on the project (who has much more general coding experience than I do) won't be able to spare time to help me out with problems on a refresh the way he would if any gradual changes were implemented on the current project. The only problem with the gradual approach is that I have no idea how to actually do it! Do I start with unit-tests of the already-existing code and work my way out to features, or do I start with features describing things already implemented and work my way in? Do I try to convince the other dev to start outside-in with all new features now, or do I wait until I've done more with what's already there? Are there any good resources out there for tasks like this? Also, if a refresh IS necessary: what's the best way to go about replicating the functionality of an existing project? > > tl;dr: Is it possible to save a test-free project via gradual steps, or is a complete refresh necessary? If the former, how do I go about doing that? If the latter, how do I do it in a way that keeps overall functionality of the resulting project the same as the original? > > Cheers, > Shea Levy > There's a great book by Michael Feathers called "Working Effectively with Legacy Code," in which he defines legacy code as code without tests. The examples are mostly in C++ and Java, but many of the concepts are technology-independent. The short version is: do it gradually. Start with a "characterization" test (generally end to end tests, probably using Cucumber) that describes an existing feature and covers the parts of the code you're about to change for a new feature. Feathers' book provides strategies for figuring out what to test in characterization tests. Once you've got the coverage you think you need to get you safely through a feature you're about to write, then drive it out using whatever process you would normally use on a well tested app. If you do this consistently as you add new features, you'll build up a meaningful suite pretty quickly. Make sense? Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dk at structuralartistry.com Sat Dec 11 13:27:28 2010 From: dk at structuralartistry.com (David Kahn) Date: Sat, 11 Dec 2010 12:27:28 -0600 Subject: [rspec-users] Rescuing a Test-Free Project with RSpec and Cucumber In-Reply-To: References: Message-ID: On first thought what I would do since you have the project running in production is to write all your Features and get them to pass on the existing production application. That gives you a reality test on each piece you change as you rebuilt. You have an additional challenge being in Rails 2 and wanting to go to Rails 3. I think if you want to do it gradually, start with the Rails 2 project, write all Features and get them passing and then rework the entire project gradually to completion in Rails 2. *Then* once all this is done and everything is passing (Features/Functional/Unit tests), then migrate it to Rails 3. Of course this might be harder and a bit more time consuming than a full rewrite in Rails 3 but you will gain the benefit of shadowing a functional in-production project. On Sat, Dec 11, 2010 at 11:47 AM, Shea Levy wrote: > Hi all, > > I was recently brought onto a Rails 2.2.3 project which was itself an > emergency rescue of a spaghetti-coded PHP project (complete with hard-coded > SQL statements!). Due to the fact that the code was already in production > and has required fairly constant maintenance and feature additions, the dev > who switched everything over to Rails hasn't written a single test. The > eventual goal, the achievement of which is one of my primary > responsibilities on the project, is to have the project be migrated to Rails > 3, fully spec'd at all levels and documented at the top level with Cucumber > features, matching Rails conventions (e.g. the database table for the Shop > model is currently 'shops_master' and will eventually be 'shops') and with > all vestiges of the original project completely removed (there's still some > PHP code running on the production site). My question is: what's the best > approach to get from here to there? Is it possible to do this gradually > while development continues on the current project, or is a total refresh > going to be necessary? I'd much prefer a gradual approach because the other > dev on the project is working full-time on adding features to and > maintaining the current site and all of my responsibilities outside of the > migration will be focused on adding features to the current site, so if I > were to do a complete refresh any work from here on out would be completely > duplicated. Additionally, the other dev on the project (who has much more > general coding experience than I do) won't be able to spare time to help me > out with problems on a refresh the way he would if any gradual changes were > implemented on the current project. The only problem with the gradual > approach is that I have no idea how to actually do it! Do I start with > unit-tests of the already-existing code and work my way out to features, or > do I start with features describing things already implemented and work my > way in? Do I try to convince the other dev to start outside-in with all new > features now, or do I wait until I've done more with what's already there? > Are there any good resources out there for tasks like this? Also, if a > refresh IS necessary: what's the best way to go about replicating the > functionality of an existing project? > > tl;dr: Is it possible to save a test-free project via gradual steps, or is > a complete refresh necessary? If the former, how do I go about doing that? > If the latter, how do I do it in a way that keeps overall functionality of > the resulting project the same as the original? > > Cheers, > Shea Levy > > _______________________________________________ > 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 katrina.owen at gmail.com Sat Dec 11 13:26:14 2010 From: katrina.owen at gmail.com (Katrina Owen) Date: Sat, 11 Dec 2010 19:26:14 +0100 Subject: [rspec-users] Rescuing a Test-Free Project with RSpec and Cucumber In-Reply-To: References: Message-ID: Hi, I would highly recommend reading "Working with Legacy Code" by Michael Feathers. It's full of advice on how to lock down legacy code and save it gradually. The examples are mostly (all?) in Java, so the actual steps would be different, but I think it could give you an idea of how/where to start. Katrina On Sat, Dec 11, 2010 at 6:47 PM, Shea Levy wrote: > Hi all, > > I was recently brought onto a Rails 2.2.3 project which was itself an > emergency rescue of a spaghetti-coded PHP project (complete with hard-coded > SQL statements!). Due to the fact that the code was already in production > and has required fairly constant maintenance and feature additions, the dev > who switched everything over to Rails hasn't written a single test. The > eventual goal, the achievement of which is one of my primary > responsibilities on the project, is to have the project be migrated to Rails > 3, fully spec'd at all levels and documented at the top level with Cucumber > features, matching Rails conventions (e.g. the database table for the Shop > model is currently 'shops_master' and will eventually be 'shops') and with > all vestiges of the original project completely removed (there's still some > PHP code running on the production site). My question is: what's the best > approach to get from here to there? Is it possible to do this gradually > while development continues on the current project, or is a total refresh > going to be necessary? I'd much prefer a gradual approach because the other > dev on the project is working full-time on adding features to and > maintaining the current site and all of my responsibilities outside of the > migration will be focused on adding features to the current site, so if I > were to do a complete refresh any work from here on out would be completely > duplicated. Additionally, the other dev on the project (who has much more > general coding experience than I do) won't be able to spare time to help me > out with problems on a refresh the way he would if any gradual changes were > implemented on the current project. The only problem with the gradual > approach is that I have no idea how to actually do it! Do I start with > unit-tests of the already-existing code and work my way out to features, or > do I start with features describing things already implemented and work my > way in? Do I try to convince the other dev to start outside-in with all new > features now, or do I wait until I've done more with what's already there? > Are there any good resources out there for tasks like this? Also, if a > refresh IS necessary: what's the best way to go about replicating the > functionality of an existing project? > > tl;dr: Is it possible to save a test-free project via gradual steps, or is a > complete refresh necessary? If the former, how do I go about doing that? If > the latter, how do I do it in a way that keeps overall functionality of the > resulting project the same as the original? > > Cheers, > Shea Levy > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From luislavena at gmail.com Sat Dec 11 14:33:17 2010 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 11 Dec 2010 16:33:17 -0300 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: <493F76A3-B063-4C11-B798-9647AE1C0199@gmail.com> References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> <493F76A3-B063-4C11-B798-9647AE1C0199@gmail.com> Message-ID: On Sat, Dec 11, 2010 at 2:33 PM, David Chelimsky wrote: > > > One step ahead of you :) > https://github.com/rspec/rspec-core/commit/dc1b0d53fde7505bb5769884e5c54b09b6886f89 > I'm going to beat your speed record David, some day.. some day :-) PS: Thank you :-D -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From ben at benmabey.com Sun Dec 12 00:51:43 2010 From: ben at benmabey.com (Ben Mabey) Date: Sat, 11 Dec 2010 22:51:43 -0700 Subject: [rspec-users] Comparing files In-Reply-To: References: <095F3898-F645-48EC-B915-E6ECE4EB09CB@mattwynne.net> <4D02539B.4060300@benmabey.com> Message-ID: <4D0462EF.3050508@benmabey.com> On 12/11/10 2:03 AM, Matt Wynne wrote: > On 10 Dec 2010, at 16:21, Ben Mabey wrote: > >> On 12/10/10 8:56 AM, Matt Wynne wrote: >>> Hello folks, >>> >>> I'm writing some tests for file upload code. The files are binary, images mostly. I'm futzing around a bit, trying to figure out how to assert that the uploaded file is the same as some golden master. If I do this: >>> >>> File.read(uploaded_file_path).should == File.read(path_to_expected_file) >>> >>> Then when it fails, I get an ugly diff of the difference between the binary files. So I'm about to invent something of my own. Has anyone got a good pattern for doing this already? >>> >>> cheers, >>> Matt >> I would compare the file's MD5 (or other) hash. It won't tell you what is different.. just that they aren't identical which is what I think you want. So... something like: >> >> Digest::MD5.hexdigest(File.read(uploaded_file_path)).should == Digest::MD5.hexdigest(File.read(path_to_expected_file)) >> >> -Ben > Great minds, Ben :) > > I ended up with this: > > https://gist.github.com/736421 > > cheers, > Matt Yeah, that is a keeper... I don't know why my last email took several hours to reach the mailing list. Very odd... -Ben From dchelimsky at gmail.com Sun Dec 12 18:50:15 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Dec 2010 17:50:15 -0600 Subject: [rspec-users] rspec-2.3.0 is released Message-ID: <220D2740-F817-4554-A225-72E65EB4D6E4@gmail.com> rspec-2.3.0 is released (including rspec, rspec-core, rspec-mocks, rspec-expecations and rspec-rails). ### rspec-core-2.3.0 / 2010-12-12 [full changelog](http://github.com/rspec/rspec-core/compare/v2.2.1...v2.3.0) * Enhancements * tell autotest to use "rspec2" if it sees a .rspec file in the project's root directory * replaces the need for ./autotest/discover.rb, which will not work with all versions of ZenTest and/or autotest * config.expect_with * :rspec # => rspec/expectations * :stdlib # => test/unit/assertions * :rspec, :stdlib # => both * Bug fixes * fix dev Gemfile to work on non-mac-os machines (Lake Denman) * ensure explicit subject is only eval'd once (Laszlo Bacsi) ### rspec-expectations-2.3.0 / 2010-12-12 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.2.1...v2.3.0) * Enhancements * diff strings when include matcher fails (Mike Sassak) ### rspec-mocks-2.3.0 / 2010-12-12 [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.2.1...v2.3.0) * Bug fixes * Fix our Marshal extension so that it does not interfere with objects that have their own @mock_proxy instance variable. (Myron Marston) ### rspec-rails-2.3.0 / 2010-12-12 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.2.1...v2.3.0) * Changes * Generator no longer generates autotest/autodiscover.rb, as it is no longer needed (as of rspec-core-2.3.0) From Gennady.Bystritsky at quest.com Sun Dec 12 21:58:22 2010 From: Gennady.Bystritsky at quest.com (Gennady Bystritsky) Date: Mon, 13 Dec 2010 02:58:22 +0000 Subject: [rspec-users] RSpec2: How to avoid an example run when previous failed In-Reply-To: <325106E3-545E-4F76-B212-8D57E57442D8@mattwynne.net> References: <4E17BA9B-A020-4C52-A089-C4FF4D3786EA@quest.com> <325106E3-545E-4F76-B212-8D57E57442D8@mattwynne.net> Message-ID: <91721C30-2532-47AE-B2FD-F6FE63C31C6F@quest.com> On Dec 11, 2010, at 5:14 AM, Matt Wynne wrote: > > On 10 Dec 2010, at 20:25, Gennady Bystritsky wrote: > >> Is there a way not to execute an example when another one fails? I want to minimize failure noises in cases when, say, one spec checks that an array has an expected number of elements while the others drill down on a specific element. However, when there's a wrong number of elements in the first place, other failures are just noise. >> >> Consider the following spec: >> >> 1 class Sample >> 2 attr_reader :items >> 3 def initialize(number) >> 4 @items = (1 .. number).map { |_item| >> 5 Struct.new(:name).new("ITEM:#{_item}") >> 6 } >> 7 end >> 8 end >> 9 >> 10 describe Sample, "when creating 2 named items" do >> 11 let(:items) { Sample.new(2).items } >> 12 subject { items } >> 13 >> 14 it { should have(2).entries } >> 15 >> 16 context "first item" do >> 17 subject { items.first } >> 18 its(:name) { should == "ITEM:1" } >> 19 end >> 20 >> 21 context "last item" do >> 22 subject { items.last } >> 23 its(:name) { should == "ITEM:2" } >> 24 end >> 25 end >> >> When run, it produces the following: >> >> $ rspec -fd sample_spec.rb >> >> Sample when creating 2 named items >> should have 2 entries >> first item >> name >> should == "ITEM:1" >> last item >> name >> should == "ITEM:2" >> >> Finished in 0.00158 seconds >> 3 examples, 0 failures >> >> Everything is great until I have an "innocent" bug in the range in line 4, like "(1 ... number)" instead of "(1 .. number)". In which case the above command will produce this: >> >> $ rspec -fd sample_spec.rb >> >> Sample when creating 2 named items >> should have 2 entries (FAILED - 1) >> first item >> name >> should == "ITEM:1" >> last item >> name >> should == "ITEM:2" (FAILED - 2) >> >> Failures: >> >> 1) Sample when creating 2 named items >> Failure/Error: it { should have(2).entries } >> expected 2 entries, got 1 >> # ./sample_spec.rb:14 >> >> 2) Sample when creating 2 named items last item name >> Failure/Error: its(:name) { should == "ITEM:2" } >> expected: "ITEM:2", >> got: "ITEM:1" (using ==) >> # ./sample_spec.rb:23 >> >> Finished in 0.00167 seconds >> 3 examples, 2 failures >> >> In the above, failure 2) is a direct result of failure 1) and would be great to avoided if possible. Especially if I want to spec much more stuff there with much more noise being displayed. >> >> Thank you for your help, >> Gennady. > > I don't consider that noise, I consider it useful clues as to what's wrong. > > cheers, > Matt Matt, thanks a lot for your opinion. Yet I feel I haven't properly expressed myself. I agree with you that normally one wants as much independent failure reports as a tool can generate. However, sometimes when you write specs you know for sure that if a test for the number of array elements fails, the subsequent tests of individual elements are destined to fail with "weird" messages, like: NoMethodError: undefined method `do_something' for nil:NilClass And they repeat again and again for all elements you test, scrolling the most relevant first failure off the screen (say, in autotest output). Not cool. Anyways, I discovered recently introduced RSpec ability to fast fail -- controllable by config parameter "fail_fast", or command line option "--fail-fast". Apparently I am not the only one who was bitten by this ;-) It helps with my issues at hand, however I would prefer more granular ability to, say, put a number of specs into fail_fast{} kind of block thus selectively indicating such cases. Gennady. > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From bploetz at gmail.com Mon Dec 13 08:55:25 2010 From: bploetz at gmail.com (Brian Ploetz) Date: Mon, 13 Dec 2010 05:55:25 -0800 (PST) Subject: [rspec-users] RSpec 2, Rails 3, and SSL routes In-Reply-To: References: Message-ID: <9e130395-b3bb-4d38-ae39-70f008175cfd@fj16g2000vbb.googlegroups.com> Anybody? On Dec 9, 3:22?pm, Brian Ploetz wrote: > Hi all, > > This is probably a stupid question, but I can't figure out how to do > this..... > > If I have some routes which require SSL, how do I test that with > RSpec? For example: > > # routes.rb > scope :constraints => { :protocol => "https" } do > ? match '/foos.(:format)' => 'foos#index', :via => :get, :constraints > => { :format => /(json|xml)/ } > end > > In my routing spec, I've tried the following variants with no luck: > > describe "routing to foos" do > ? it "routes /foos.json to foos#index" do > ? ? { :get => "/foos.json", :protocol => "https" }.should route_to( > ? ? ? :controller => "foos", > ? ? ? :action => "index", > ? ? ? :format => "json" > ? ? ) > ? end > > describe "routing to foos" do > ? it "routes /foos.json to foos#index" do > ? ? { :get => "/foos.json" }.should route_to( > ? ? ? :controller => "foos", > ? ? ? :action => "index", > ? ? ? :format => "json", > ? ? ? :protocol => "https" > ? ? ) > ? end > > Thanks in advance for any help. > BP > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Dec 13 09:16:55 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Dec 2010 08:16:55 -0600 Subject: [rspec-users] RSpec 2, Rails 3, and SSL routes In-Reply-To: <9e130395-b3bb-4d38-ae39-70f008175cfd@fj16g2000vbb.googlegroups.com> References: <9e130395-b3bb-4d38-ae39-70f008175cfd@fj16g2000vbb.googlegroups.com> Message-ID: On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote: > Anybody? > > On Dec 9, 3:22 pm, Brian Ploetz wrote: >> Hi all, >> >> This is probably a stupid question, but I can't figure out how to do >> this..... >> >> If I have some routes which require SSL, how do I test that with >> RSpec? For example: >> >> # routes.rb >> scope :constraints => { :protocol => "https" } do >> match '/foos.(:format)' => 'foos#index', :via => :get, :constraints >> => { :format => /(json|xml)/ } >> end >> >> In my routing spec, I've tried the following variants with no luck: >> >> describe "routing to foos" do >> it "routes /foos.json to foos#index" do >> { :get => "/foos.json", :protocol => "https" }.should route_to( >> :controller => "foos", >> :action => "index", >> :format => "json" >> ) >> end >> >> describe "routing to foos" do >> it "routes /foos.json to foos#index" do >> { :get => "/foos.json" }.should route_to( >> :controller => "foos", >> :action => "index", >> :format => "json", >> :protocol => "https" >> ) >> end >> >> Thanks in advance for any help. There is an open issue in the Rails tracker about this [1]. assert_recognizes, to which "should route_to" delegates, does not yet support constraints. Sadly, this means there is no good way to do this at the moment. [1] https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_recognizes-does-not-support-constraints for more info. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bploetz at gmail.com Mon Dec 13 09:43:10 2010 From: bploetz at gmail.com (Brian Ploetz) Date: Mon, 13 Dec 2010 06:43:10 -0800 (PST) Subject: [rspec-users] RSpec 2, Rails 3, and SSL routes In-Reply-To: References: <9e130395-b3bb-4d38-ae39-70f008175cfd@fj16g2000vbb.googlegroups.com> Message-ID: <565f30a4-b8c9-48ca-abb5-82602eb4355a@w29g2000vba.googlegroups.com> OK, cool. I'll avoid banging my head against the wall in the mean time. :-) Thanks alot David. BP On Dec 13, 9:16?am, David Chelimsky wrote: > On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote: > > > > > Anybody? > > > On Dec 9, 3:22 pm, Brian Ploetz wrote: > >> Hi all, > > >> This is probably a stupid question, but I can't figure out how to do > >> this..... > > >> If I have some routes which require SSL, how do I test that with > >> RSpec? For example: > > >> # routes.rb > >> scope :constraints => { :protocol => "https" } do > >> ? match '/foos.(:format)' => 'foos#index', :via => :get, :constraints > >> => { :format => /(json|xml)/ } > >> end > > >> In my routing spec, I've tried the following variants with no luck: > > >> describe "routing to foos" do > >> ? it "routes /foos.json to foos#index" do > >> ? ? { :get => "/foos.json", :protocol => "https" }.should route_to( > >> ? ? ? :controller => "foos", > >> ? ? ? :action => "index", > >> ? ? ? :format => "json" > >> ? ? ) > >> ? end > > >> describe "routing to foos" do > >> ? it "routes /foos.json to foos#index" do > >> ? ? { :get => "/foos.json" }.should route_to( > >> ? ? ? :controller => "foos", > >> ? ? ? :action => "index", > >> ? ? ? :format => "json", > >> ? ? ? :protocol => "https" > >> ? ? ) > >> ? end > > >> Thanks in advance for any help. > > There is an open issue in the Rails tracker about this [1]. assert_recognizes, to which "should route_to" delegates, does not yet support constraints. Sadly, this means there is no good way to do this at the moment. > > [1]https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_rec...for more info. > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From bploetz at gmail.com Mon Dec 13 11:44:48 2010 From: bploetz at gmail.com (Brian Ploetz) Date: Mon, 13 Dec 2010 08:44:48 -0800 (PST) Subject: [rspec-users] RSpec 2, Rails 3, and SSL routes In-Reply-To: <565f30a4-b8c9-48ca-abb5-82602eb4355a@w29g2000vba.googlegroups.com> References: <9e130395-b3bb-4d38-ae39-70f008175cfd@fj16g2000vbb.googlegroups.com> <565f30a4-b8c9-48ca-abb5-82602eb4355a@w29g2000vba.googlegroups.com> Message-ID: Actually, Rails seems to correctly support *some* routing constraints in tests (:format being one), but not others (:protocol being one). I'm coming up with a failing test which I'll attach to that Rails ticket, but just noting it here as an FYI to others... On Dec 13, 9:43?am, Brian Ploetz wrote: > OK, cool. I'll avoid banging my head against the wall in the mean > time. :-) > > Thanks alot David. > BP > > On Dec 13, 9:16?am, David Chelimsky wrote: > > > On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote: > > > > Anybody? > > > > On Dec 9, 3:22 pm, Brian Ploetz wrote: > > >> Hi all, > > > >> This is probably a stupid question, but I can't figure out how to do > > >> this..... > > > >> If I have some routes which require SSL, how do I test that with > > >> RSpec? For example: > > > >> # routes.rb > > >> scope :constraints => { :protocol => "https" } do > > >> ? match '/foos.(:format)' => 'foos#index', :via => :get, :constraints > > >> => { :format => /(json|xml)/ } > > >> end > > > >> In my routing spec, I've tried the following variants with no luck: > > > >> describe "routing to foos" do > > >> ? it "routes /foos.json to foos#index" do > > >> ? ? { :get => "/foos.json", :protocol => "https" }.should route_to( > > >> ? ? ? :controller => "foos", > > >> ? ? ? :action => "index", > > >> ? ? ? :format => "json" > > >> ? ? ) > > >> ? end > > > >> describe "routing to foos" do > > >> ? it "routes /foos.json to foos#index" do > > >> ? ? { :get => "/foos.json" }.should route_to( > > >> ? ? ? :controller => "foos", > > >> ? ? ? :action => "index", > > >> ? ? ? :format => "json", > > >> ? ? ? :protocol => "https" > > >> ? ? ) > > >> ? end > > > >> Thanks in advance for any help. > > > There is an open issue in the Rails tracker about this [1]. assert_recognizes, to which "should route_to" delegates, does not yet support constraints. Sadly, this means there is no good way to do this at the moment. > > > [1]https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_rec...more info. > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From djangst at gmail.com Mon Dec 13 17:31:37 2010 From: djangst at gmail.com (djangst) Date: Mon, 13 Dec 2010 14:31:37 -0800 (PST) Subject: [rspec-users] Count error on lambda should change Message-ID: <1234426c-0d82-4469-97df-7b3ec68823ac@j13g2000vbp.googlegroups.com> Hi, any idea what could cause the following error in a controller test? "count should have been changed by 1, but was changed by 0" I'm posting to a create route using a lambda, similar to Hartl's example in his Rails tutorial: it "should create a user" do lambda do post :create, :user => @attr end.should change(User, :count).by(1) end The only difference is I'm using a factory instead of an attribute hash. I know the action works because I can perform it manually and my model specs pass. More importantly, I can see the inserts (two rows, parent and child) in my Postgres logs. And I see a rollback before the count is selected. Could that be the cause? [I searched for a while and didn't see much discussion about this, so probably not.] From djangst at gmail.com Mon Dec 13 18:08:13 2010 From: djangst at gmail.com (djangst) Date: Mon, 13 Dec 2010 15:08:13 -0800 (PST) Subject: [rspec-users] Count error on lambda should change Message-ID: Hi, any idea what could cause the following error in a controller test? "count should have been changed by 1, but was changed by 0" I'm posting to a create route using a lambda, similar to Hartl's example in his Rails tutorial: it "should create a user" do lambda do post :create, :user => @attr end.should change(User, :count).by(1) end The only difference is I'm using a factory instead of an attribute hash. I know the action works because I can perform it manually and my model specs pass. More importantly, I can see the inserts (two rows, parent and child) in my Postgres logs. And I see a rollback before the count is selected. Could that be the cause? [I searched for a while and didn't see much discussion about this, so probably not.] From dchelimsky at gmail.com Mon Dec 13 21:45:35 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Dec 2010 20:45:35 -0600 Subject: [rspec-users] Count error on lambda should change In-Reply-To: <1234426c-0d82-4469-97df-7b3ec68823ac@j13g2000vbp.googlegroups.com> References: <1234426c-0d82-4469-97df-7b3ec68823ac@j13g2000vbp.googlegroups.com> Message-ID: On Mon, Dec 13, 2010 at 4:31 PM, djangst wrote: > Hi, any idea what could cause the following error in a controller > test? > > ? ? "count should have been changed by 1, but was changed by 0" > > I'm posting to a create route using a lambda, similar to Hartl's > example in his Rails tutorial: > > it "should create a user" do > ?lambda do > ? ?post :create, :user => @attr > ?end.should change(User, :count).by(1) > end > > The only difference is I'm using a factory instead of an attribute > hash. I know the action works because I can perform it manually and my > model specs pass. Please show us your code instead of referencing someone else's and then describing the differences. There are so many things that could be the source of the problem that anything anybody offers here is going to be a guess at best. From jonathan at parkerhill.com Mon Dec 13 23:46:11 2010 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Mon, 13 Dec 2010 23:46:11 -0500 Subject: [rspec-users] nested examples in html formatter Message-ID: <11807759-577D-4118-84FB-A928E25A64BA@parkerhill.com> Is there a way for the html formatter to show nested "describe" blocks, as written in my examples. Or perhaps I should change how I write my examples so nesting can be shown? eg describe MyModel do it "should be valid" describe "something" do it "should do this correctly" it "should fail gracefully" it "should do this without that" end describe "something else" do it "should go on and on" end end From lists at ruby-forum.com Tue Dec 14 08:15:49 2010 From: lists at ruby-forum.com (Michelle Pace) Date: Tue, 14 Dec 2010 14:15:49 +0100 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com>, , , Message-ID: <85ffb5b208f5c0e5bad66fcc9fed9416@ruby-forum.com> David Chelimsky wrote in post #967835: > ZenTest-4.4.2 will add "." to the $LOAD_PATH, at which point the > material in > the book will work as written (except that the file is > "autotest/discover.rb", not > "autotest/.autotest/discover.rb") with ruby-1.9. Ok - I have updated to ZenTest-4.4.2, I've made sure that I have autotest/discover.rb and that I use 'autotest' in place of 'autospec'...I'm sorry to say it, but iis still not 'verking: C:\DEVELOPMENT\twits>autotest loading autotest/rspec2 bundle exec C:\devtools\Ruby192\bin\ruby -S C:/devtools/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2 .3.0/bin/rspec --tty 'C:/DEVELOPMENT/twits/spec/twits_spec.rb' Could not find gem 'rspec (~> 2.1.0, runtime)' in any of the gem sources listed in your Gemfile. Interrupt a second time to quit Terminate batch job (Y/N)? ^C C:\DEVELOPMENT\twits>ls spec/* spec/spec_helper.rb spec/twits_spec.rb :) sorry David... but got any more pointers for me?? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Dec 14 08:25:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 14 Dec 2010 07:25:53 -0600 Subject: [rspec-users] nested examples in html formatter In-Reply-To: <11807759-577D-4118-84FB-A928E25A64BA@parkerhill.com> References: <11807759-577D-4118-84FB-A928E25A64BA@parkerhill.com> Message-ID: <56FA78D4-1A61-4D62-9912-89E136A4FDA4@gmail.com> On Dec 13, 2010, at 10:46 PM, Jonathan Linowes wrote: > Is there a way for the html formatter to show nested "describe" blocks, as written in my examples. Not supported yet. Patches welcome! > Or perhaps I should change how I write my examples so nesting can be shown? > > eg > > describe MyModel do > it "should be valid" > > describe "something" do > it "should do this correctly" > it "should fail gracefully" > it "should do this without that" > end > > describe "something else" do > it "should go on and on" > end > end > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From luislavena at gmail.com Tue Dec 14 09:18:16 2010 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 14 Dec 2010 11:18:16 -0300 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: <85ffb5b208f5c0e5bad66fcc9fed9416@ruby-forum.com> References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> <85ffb5b208f5c0e5bad66fcc9fed9416@ruby-forum.com> Message-ID: On Tue, Dec 14, 2010 at 10:15 AM, Michelle Pace wrote: > > Ok - I have updated to ZenTest-4.4.2, I've made sure that I have > autotest/discover.rb and that I use 'autotest' in place > of 'autospec'...I'm sorry to say it, but iis still not 'verking: > > C:\DEVELOPMENT\twits>autotest > loading autotest/rspec2 > bundle exec C:\devtools\Ruby192\bin\ruby -S > C:/devtools/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2 > .3.0/bin/rspec --tty 'C:/DEVELOPMENT/twits/spec/twits_spec.rb' > Could not find gem 'rspec (~> 2.1.0, runtime)' in any of the gem sources > listed in your Gemfile. The error is there, did you update your Gemfile definitions to the latest version and run bundle update rpsec or bundle update rspec-rails? -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From lists at ruby-forum.com Tue Dec 14 11:38:00 2010 From: lists at ruby-forum.com (Michelle Pace) Date: Tue, 14 Dec 2010 17:38:00 +0100 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com>, , , , <85ffb5b208f5c0e5bad66fcc9fed9416@ruby-forum.com>, Message-ID: Luis Lavena wrote in post #968298: > On Tue, Dec 14, 2010 at 10:15 AM, Michelle Pace > wrote: >> Could not find gem 'rspec (~> 2.1.0, runtime)' in any of the gem sources >> listed in your Gemfile. > > The error is there, did you update your Gemfile definitions to the > latest version and run bundle update rpsec or bundle update > rspec-rails? Thanks Luis, I'm completely new with this... mmm - no? All I ran was "%gem update" and thought that would do it as it now returns with "Nothing to update". How do I go about updating my "gemfile definitions"? -- Posted via http://www.ruby-forum.com/. From djangst at gmail.com Tue Dec 14 13:00:07 2010 From: djangst at gmail.com (djangst) Date: Tue, 14 Dec 2010 10:00:07 -0800 (PST) Subject: [rspec-users] Count error on lambda should change In-Reply-To: <1234426c-0d82-4469-97df-7b3ec68823ac@j13g2000vbp.googlegroups.com> References: <1234426c-0d82-4469-97df-7b3ec68823ac@j13g2000vbp.googlegroups.com> Message-ID: <5a9fc262-dbae-4fa0-b2fc-05743e67543a@35g2000prt.googlegroups.com> The problem was related to the use of the factory-generated instance, in this case a parent with one child instance similar to Hartl's user/ micropost example, but different in that I require at least one child instance to be present (in the has_many relationship). I'm doing this in conjunction with an attachment upload, so getting everything working together and tested properly has been problematic. I may post an example later to hopefully get some feedback. From elliot.winkler at gmail.com Tue Dec 14 13:07:06 2010 From: elliot.winkler at gmail.com (Elliot Winkler) Date: Tue, 14 Dec 2010 11:07:06 -0700 Subject: [rspec-users] @current_user in controller specs In-Reply-To: References: Message-ID: You can't say User.new(:id=>27) as ActiveRecord prevents :id from being mass-assigned like that (in the case of an action that does User.new(params[:user]) in the controller, people would be able to set the id through the POST data). Try User.new.tap {|u| u.id = 27 } instead. -- Elliot On Fri, Dec 10, 2010 at 3:15 PM, John Gadbois wrote: > Hi, > > I'm an absolute beginner with RSpec, so I apologize if this question > doesn't make sense. > > I'm using RSpec 2, Rails 3. I have a @current_user instance variable that > I can access in my controller. I have a controller called > PlanOrderController. In the create action of this model, I would like to > assign the user_id of the PlanOrder object to be the user_id of the > @current_user before saving. > > I have the generated rails controller specs so I'm starting with those. > Basically I want my controller spec for the create action to test to make > sure that the newly created PlanOrder has it's user_id property set to @ > current_user.id > > The code I have so far is below but it's not working > > it "sets the user id to the logged on user" do > @current_user = User.new(:id=>27) > controller.stub!(:current_user).and_return(@current_user) > > PlanOrder.stub(:new).with({"days_per_week" => 3, > "description"=>"Test", "purpose_id"=>1 }) { mock_plan_order(:save => true) } > post :create, :plan_order =>{"days_per_week" => 3, > "description"=>"Test", "purpose_id"=>1 } > plan_order = assigns(:plan_order) > plan_order.user_id.should be(@current_user.id) > end > > Any help would be appreciated. > > Thanks, > John > > _______________________________________________ > 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 luislavena at gmail.com Tue Dec 14 14:36:13 2010 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 14 Dec 2010 16:36:13 -0300 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> <85ffb5b208f5c0e5bad66fcc9fed9416@ruby-forum.com> Message-ID: On Tue, Dec 14, 2010 at 1:38 PM, Michelle Pace wrote: > > Thanks Luis, I'm completely new with this... mmm - no? Are you following a Rails guide? didn't the guide mention something about a Gemfile? > All I ran was "%gem update" and thought that would do it as it now > returns with "Nothing to update". How do I go about updating my "gemfile > definitions"? > You're using Bundler, bundler needs a "manifest" of gems and versions that your application use. Look for "Gemfile" in the root of your application. More information in Bundler website: http://gembundler.com/ -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From lists at ruby-forum.com Tue Dec 14 19:53:43 2010 From: lists at ruby-forum.com (Daniel C.) Date: Wed, 15 Dec 2010 01:53:43 +0100 Subject: [rspec-users] Rspec & Rails Nested Resources Message-ID: <7aa0aa0396b0a525d8bcad98b58612e0@ruby-forum.com> Hey all, I'm new to Rspec and I was just wondering what the standard way of testing nested resources is? I currently have a Job model which has many Correspondences. The new action of my CorrespondencesController looks like: def new @job = Job.find params[:job_id] @correspondence = @job.correspondences.build end And my current spec looks like: it "GET new" do @job = stub_model(Job, :to_param => "1") Job.should_receive(:find).and_return(@job) get :new, :job_id => @job.id assigns[:correspondence].should_not be_nil end The test is currently failing with correspondence is nil, but it works fine in the browser. Any help here would be great, thanks. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Dec 14 20:59:02 2010 From: lists at ruby-forum.com (Michelle Pace) Date: Wed, 15 Dec 2010 02:59:02 +0100 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com> <85ffb5b208f5c0e5bad66fcc9fed9416@ruby-forum.com> Message-ID: <91f1c848dcc2b8fde0df33c4d4d83547@ruby-forum.com> Luis Lavena wrote in post #968399: > You're using Bundler, bundler needs a "manifest" of gems and versions > that your application use. Look for "Gemfile" in the root of your > application. *yay*! Thanks Luis (and David) for all your patience. I've finally got it working and can now go onto Page 19 of this book. I looked for the automatically generated gemfile and found that it was completely out of date with version numbers so I updated it to the versions I have. Thanks again for all the help and putting up with my new-be-ness. Cheers, Michelle THE OLD (ORIGINAL): ----------------------------------- group :development do gem "rspec", "~> 2.1.0" gem "bundler", "~> 1.0.0" gem "jeweler", "~> 1.5.1" gem "rcov", ">= 0" end I CHANGED IT TO THIS AND IT WORKS: ----------------------------------- group :development do gem "rspec", "~> 2.3.0" gem "bundler", "~> 1.0.7" gem "jeweler", "~> 1.5.1" gem "rcov", ">= 0" end -- Posted via http://www.ruby-forum.com/. From jarmo.p at gmail.com Wed Dec 15 10:47:43 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 15 Dec 2010 07:47:43 -0800 (PST) Subject: [rspec-users] nested examples in html formatter In-Reply-To: <56FA78D4-1A61-4D62-9912-89E136A4FDA4@gmail.com> References: <11807759-577D-4118-84FB-A928E25A64BA@parkerhill.com> <56FA78D4-1A61-4D62-9912-89E136A4FDA4@gmail.com> Message-ID: <69f17b71-7e7b-45b8-9ce7-fa34338f8871@l17g2000yqe.googlegroups.com> Just FYI, it is now: https://github.com/rspec/rspec-core/commit/edb7f851a85ffe318a5d9d161c896bde448b61e1 Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net On Dec 14, 3:25?pm, David Chelimsky wrote: > On Dec 13, 2010, at 10:46 PM, Jonathan Linowes wrote: > > > Is there a way for the html formatter to show nested "describe" blocks, as written in my examples. > > Not supported yet. Patches welcome! > > > > > > > > > > > Or perhaps I should change how I write my examples so nesting can be shown? > > > eg > > > describe MyModel do > > ? ?it "should be valid" > > > ? ?describe "something" do > > ? ? ? ? ? ?it "should do this correctly" > > ? ? ? ? ? ?it "should fail gracefully" > > ? ? ? ? ? ?it "should do this without that" > > ? ?end > > > ? ?describe "something else" do > > ? ? ? ? ? ?it "should go on and on" > > ? ?end > > end > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Wed Dec 15 20:26:24 2010 From: lists at ruby-forum.com (Adam Wilson) Date: Thu, 16 Dec 2010 02:26:24 +0100 Subject: [rspec-users] Nested model and Factory.build Message-ID: <7e5dce384023735a5894974a0663eeb6@ruby-forum.com> I am new to RSpec and BDD, learning it while starting a new project. I am writing model tests for a user model with a has_one association: class User < ActiveRecord::Base has_one :core_profile validates_associated :core_profile, :as => :core_profileable accepts_nested_attributes_for : core_profile after_initialize :build_associations def build_associations build_core_profile unless core_profile || !core_profile.valid? end end class CoreProfile < ActiveRecord::Base attr_accessor :password, :password_confirmation attr_accessible :user_name attr_protected :hashed_password validates :user_name, :presence => true validates :first_name, :presence => true validates :last_name, :presence => true belongs_to :core_profileable, :polymorphic => true acts_as_authentic end I am using Factory Girl to test model data. I have been trying to test creation of a Parent. Testing for a valid Parent and valid CoreProfile work fine, also invalid Parent and valid CoreProfile... however when I test for valid Parent and invalid CoreProfile I get an failure do to "Validation failed" - it seems to not return invalid for the Parent... here is the test in question: it "should be invalid :invalid_core_profile_user" do user = Factory.build(:invalid_core_profile_user) user.core_profile.should_be invalid? end and the Factory definitions: Factory.define :invalid_core_profile_parent, :class => User do |p| p.email 'barry.white at test.com' p.phone_number '(925) 555-1212' p.association :invalid_core_profile end Factory.define :invalid_core_profile, :class => CoreProfile do |cp| cp.first_name 'Barry' cp.last_name 'White' cp.user_name '' cp.password 'password' cp.password_confirmation '' end I am assuming that Factory.build(:invalid_core_profile_user) creates the associated objects first but does not bubble up the validity, just breaks out with the "Validation failed" message. Maybe I am doing this wrong - should User only handle its own validation and not its associated models? Thing is - the CoreProfile should only be saved as part of a User, so its important to test them together. I have googled high and low and can't seem to find an answer. Thanks for reading! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Dec 16 01:17:44 2010 From: lists at ruby-forum.com (Neha J.) Date: Thu, 16 Dec 2010 07:17:44 +0100 Subject: [rspec-users] making sure a model acts_as_authentic In-Reply-To: <09B92C01-D37D-4C2E-98DB-29B05462ADB9@gmail.com> References: <09B92C01-D37D-4C2E-98DB-29B05462ADB9@gmail.com> Message-ID: Hello Stephen, I came across same problem few days back. Its very simple. You need not spec a model to check if the model acts_as_authentic. I am using RSpec with Factory_girl. So when I create factory for my respective model, Factory does the checking for the model. Try creating a Factory for respective model in before (:each) block. And for cross-checking, just comment out the acts_as_authentic line from your model file. You should be able to see the error message onscreen when spec runs. And when you uncomment the line, spec runs with 0 errors. Hope this helps. --Neha Jain Stephen Smithstone wrote in post #966709: > Is there any way to spec that a model should acts_as_authentic which is > from the authlogic plugin > im using rspec-1 > > Stephen Smithstone -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Dec 16 01:22:54 2010 From: lists at ruby-forum.com (Neha J.) Date: Thu, 16 Dec 2010 07:22:54 +0100 Subject: [rspec-users] specing a model to make sure it implements act_as_authentic In-Reply-To: References: Message-ID: Hello Stephen, I came across same problem few days back. Its very simple. You need not spec a model to check if the model acts_as_authentic. I am using RSpec with Factory_girl. So when I create factory for my respective model, Factory does the checking for the model. Try creating a Factory for respective model in before (:each) block. And for cross-checking, just comment out the acts_as_authentic line from your model file. You should be able to see the error message onscreen when spec runs. And when you uncomment the line, spec runs with 0 errors. Hope this helps. --Neha Jain -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Dec 16 23:20:01 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Dec 2010 22:20:01 -0600 Subject: [rspec-users] rspec-rails-2.3.1 is released! Message-ID: <7AFCEC2B-8BD2-4BBA-BD97-B8BABC15FF4E@gmail.com> ### rspec-rails-2.3.1 / 2010-12-16 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.3.0...v2.3.1) * Bug fixes * respond_to? correctly handles 2 args * scaffold generator no longer fails on autotest directory From dchelimsky at gmail.com Thu Dec 16 23:20:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Dec 2010 22:20:03 -0600 Subject: [rspec-users] rspec-core-2.3.1 is released Message-ID: <2C7A0774-2524-454E-8BF3-EB47C9CD11CA@gmail.com> ### rspec-core-2.3.1 / 2010-12-16 full changelog: http://github.com/rspec/rspec-core/compare/v2.3.0...v2.3.1 * Bug fixes * send debugger warning message to $stdout if RSpec.configuration.error_stream has not been defined yet. * HTML Formatter _finally_ properly displays nested groups (Jarmo Pertman) * eliminate some warnings when running RSpec's own suite (Jarmo Pertman) From niku at niku.name Fri Dec 17 09:12:59 2010 From: niku at niku.name (niku -E:)) Date: Fri, 17 Dec 2010 23:12:59 +0900 Subject: [rspec-users] [Mock]How do I check order of method argument ? Message-ID: Hello. My name is niku. I'm using rspec 2.2.1 /tmp% rspec --version 2.2.1 I tested http://gist.github.com/744935 and passed. /tmp% rspec stdout_spec.rb .. Finished in 0.00105 seconds 2 examples, 0 failures But I expected test fail. Because It's wrong order that argument of 'write' method. How do I check order of argument ? regards. From dchelimsky at gmail.com Fri Dec 17 10:44:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Dec 2010 09:44:03 -0600 Subject: [rspec-users] [Mock]How do I check order of method argument ? In-Reply-To: References: Message-ID: <627ADB78-88D4-4F17-8B54-FFAB95D3876A@gmail.com> On Dec 17, 2010, at 8:12 AM, niku -E:) wrote: > Hello. > My name is niku. > > I'm using rspec 2.2.1 > > /tmp% rspec --version > 2.2.1 > > I tested http://gist.github.com/744935 and passed. > > /tmp% rspec stdout_spec.rb > .. > > Finished in 0.00105 seconds > 2 examples, 0 failures > > But I expected test fail. > Because It's wrong order that argument of 'write' method. Message expectations are not constrained by order unless you explicitly tell them to be. This is documented for rspec-1 here: http://rspec.info/documentation/mocks/message_expectations.html. The docs for rspec-mocks-2 don't have this yet, but will soon. Basically, do this instead. it "puts 'foo' and 'bar'" do mock = double("stdout") mock.should_receive(:write).with("\n").ordered mock.should_receive(:write).with("\n").ordered mock.should_receive(:write).with("foo").ordered mock.should_receive(:write).with("bar").ordered $stdout = mock puts "foo" puts "bar" end HTH, David > > How do I check order of argument ? > > regards. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Fri Dec 17 20:48:46 2010 From: lists at ruby-forum.com (Matt S.) Date: Sat, 18 Dec 2010 02:48:46 +0100 Subject: [rspec-users] Failing View Spec, rspec-rails 2.2.1 In-Reply-To: References: Message-ID: <2e2123b87149628f90bd152373041204@ruby-forum.com> Hey David, You rock. Thanks a million. Got it working right away! Thanks, Matt -- Posted via http://www.ruby-forum.com/. From niku at niku.name Fri Dec 17 22:19:35 2010 From: niku at niku.name (niku -E:)) Date: Sat, 18 Dec 2010 12:19:35 +0900 Subject: [rspec-users] [Mock]How do I check order of method argument ? In-Reply-To: <627ADB78-88D4-4F17-8B54-FFAB95D3876A@gmail.com> References: <627ADB78-88D4-4F17-8B54-FFAB95D3876A@gmail.com> Message-ID: Hello. My question was solved by David's answer. Thank you David! On Sat, Dec 18, 2010 at 12:44 AM, David Chelimsky wrote: > > On Dec 17, 2010, at 8:12 AM, niku -E:) wrote: > >> Hello. >> My name is niku. >> >> I'm using rspec 2.2.1 >> >> /tmp% rspec --version >> 2.2.1 >> >> I tested http://gist.github.com/744935 and passed. >> >> /tmp% rspec stdout_spec.rb >> .. >> >> Finished in 0.00105 seconds >> 2 examples, 0 failures >> >> But I expected test fail. >> Because It's wrong order that argument of 'write' method. > > > Message expectations are not constrained by order unless you explicitly tell them to be. This is documented for rspec-1 here: http://rspec.info/documentation/mocks/message_expectations.html. The docs for rspec-mocks-2 don't have this yet, but will soon. > > Basically, do this instead. > > ?it "puts 'foo' and 'bar'" do > ? ?mock = double("stdout") > ? ?mock.should_receive(:write).with("\n").ordered > ? ?mock.should_receive(:write).with("\n").ordered > ? ?mock.should_receive(:write).with("foo").ordered > ? ?mock.should_receive(:write).with("bar").ordered > ? ?$stdout = mock > > ? ?puts "foo" > ? ?puts "bar" > ?end > > HTH, > David > > > >> >> How do I check order of argument ? >> >> regards. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From patmaddox at me.com Sat Dec 18 05:59:44 2010 From: patmaddox at me.com (Pat Maddox) Date: Sat, 18 Dec 2010 02:59:44 -0800 Subject: [rspec-users] "unit" vs. "functional" specs In-Reply-To: References: Message-ID: Why don't functional specs count towards your coverage metric? It sounds like you're shooting for 100% unit test coverage -- why? If you write code in order to make your functional specs pass, then that code was TDD'd...right? Pat On Dec 10, 2010, at 2:29 PM, Andrew Wagner wrote: > I went back and forth on whether to send this to this list or the ruby-talk list, so feel free to tell me to take a hike... > > I'm working on a personal project where I'm trying to keep a really high bar on quality. One of the ways I'm doing that is to stick very close to the BDD/TDD cycle as suggested in the RSpec book. However, I'm actually using rspec for both the feature-level (BDD) tests and the unit-level (TDD) tests. I'm also striving for 100% test coverage using Simplecov. > > That said, I just realized that, to enforce that cycle, it's also important that I ask "do my unit tests by themselves provide 100% test coverage?". Because, otherwise, it's easy to get excited and write code to make the feature past, that isn't TDD'd. > > Anyway, all that to ask: is there some way to configure Simplecov to emit code coverage stats for just a subset of all the tests that are running? That is, I want to set up my rakefile such that it runs all my tests, but only reports on code coverage for the unit tests. > > Am I going about this with the right mindset? Any suggestions? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patmaddox at me.com Sat Dec 18 06:21:17 2010 From: patmaddox at me.com (Pat Maddox) Date: Sat, 18 Dec 2010 03:21:17 -0800 Subject: [rspec-users] Count error on lambda should change In-Reply-To: References: Message-ID: <19FE7E1C-9C0C-4521-8FCA-0CCF42934166@me.com> Sounds like a validation failure. My guess is that you're re-using the factory-created record's attributes, and your example fails because of a uniqueness validation. This would explain the rollback if you're using the create! or save! method. Pat On Dec 13, 2010, at 3:08 PM, djangst wrote: > Hi, any idea what could cause the following error in a controller > test? > > "count should have been changed by 1, but was changed by 0" > > I'm posting to a create route using a lambda, similar to Hartl's > example in his Rails tutorial: > > it "should create a user" do > lambda do > post :create, :user => @attr > end.should change(User, :count).by(1) > end > > The only difference is I'm using a factory instead of an attribute > hash. I know the action works because I can perform it manually and my > model specs pass. > > More importantly, I can see the inserts (two rows, parent and child) > in my Postgres logs. And I see a rollback before the count is > selected. Could that be the cause? [I searched for a while and didn't > see much discussion about this, so probably not.] > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patmaddox at me.com Sat Dec 18 06:31:23 2010 From: patmaddox at me.com (Pat Maddox) Date: Sat, 18 Dec 2010 03:31:23 -0800 Subject: [rspec-users] Rspec & Rails Nested Resources In-Reply-To: <7aa0aa0396b0a525d8bcad98b58612e0@ruby-forum.com> References: <7aa0aa0396b0a525d8bcad98b58612e0@ruby-forum.com> Message-ID: <8863125F-AC6C-47EF-B537-ADA48C90DAED@me.com> Try assigns(:correspondence) instead. If that doesn't work, I would inspect the value of @job.correspondences.build (when run in the test). It's possible that stub_model is causing #build to return nil -- I don't remember the behavior off the top of my head and don't have a Ruby available to check. Anyway if it is nil then you'll need to do some more stubbing setup. stub_chain may be useful. Pat On Dec 14, 2010, at 4:53 PM, "Daniel C." wrote: > Hey all, > > I'm new to Rspec and I was just wondering what the standard way of > testing nested resources is? > > I currently have a Job model which has many Correspondences. > > The new action of my CorrespondencesController looks like: > > def new > @job = Job.find params[:job_id] > @correspondence = @job.correspondences.build > end > > And my current spec looks like: > > it "GET new" do > @job = stub_model(Job, :to_param => "1") > Job.should_receive(:find).and_return(@job) > get :new, :job_id => @job.id > assigns[:correspondence].should_not be_nil > end > > The test is currently failing with correspondence is nil, but it works > fine in the browser. > > Any help here would be great, thanks. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patmaddox at me.com Sat Dec 18 07:01:26 2010 From: patmaddox at me.com (Pat Maddox) Date: Sat, 18 Dec 2010 04:01:26 -0800 Subject: [rspec-users] [Mock]How do I check order of method argument ? In-Reply-To: References: Message-ID: <78126F36-6C5B-4248-9D85-0CA81BF876A3@me.com> mock.should_receive(:write).with("\n").ordered Append .ordered as above On Dec 17, 2010, at 6:12 AM, "niku -E:)" wrote: > Hello. > My name is niku. > > I'm using rspec 2.2.1 > > /tmp% rspec --version > 2.2.1 > > I tested http://gist.github.com/744935 and passed. > > /tmp% rspec stdout_spec.rb > .. > > Finished in 0.00105 seconds > 2 examples, 0 failures > > But I expected test fail. > Because It's wrong order that argument of 'write' method. > > How do I check order of argument ? > > regards. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Dec 18 15:11:50 2010 From: lists at ruby-forum.com (Sarah Allen) Date: Sat, 18 Dec 2010 21:11:50 +0100 Subject: [rspec-users] Configuring RSpec for Integration Test Message-ID: In using RSpec for integration testing with Capybara, I was surprised thave I needed to do extra configuration. I started with the config from this blog post: http://codingfrontier.com/integration-testing-setup-with-rspec-2-and-ca and I pared it down to only what I needed to write an integration test, and ended up with require 'action_dispatch' require 'capybara/rails' require 'capybara/dsl' module RSpec::Rails module IntegrationExampleGroup include ActionDispatch::Integration::Runner include Capybara def app ::Rails.application end RSpec.configure do |c| c.include self, :example_group => { :file_path => /\bspec\/integration\// } end end end I understand why I would need special config to include Capybara, but I don't understand why I need to define app and include the ActionDisplatch stuff -- I thought that would come automagically with rspec-rails by just including spec_helper. My whole little test project is here: https://github.com/blazingcloud/rspec-capybara Before I give this to other folks as example code, I would really like to understand it and know if there is an easier/better/more recommended way to do this. Thanks, Sarah work http://blazingcloud.net/ personal blog http://www.ultrasaurus.com p.s. I know cucumber is an alternate way. I'm doing a compare/contrast. The cucumber version is here: https://github.com/blazingcloud/cucumber_lesson -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Dec 18 15:47:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Dec 2010 14:47:36 -0600 Subject: [rspec-users] Configuring RSpec for Integration Test In-Reply-To: References: Message-ID: <80F2BC20-1356-462C-8348-AED473C716C6@gmail.com> On Dec 18, 2010, at 2:11 PM, Sarah Allen wrote: > In using RSpec for integration testing with Capybara, I was surprised > thave I needed to do extra configuration. I started with the config > from this blog post: > http://codingfrontier.com/integration-testing-setup-with-rspec-2-and-ca That blog post was based on a beta version of rspec-rails 2 before we got the integration worked out :) Per "Webrat and Capybara" on http://relishapp.com/rspec/rspec-rails, all you should need now is this in your Gemfile: gem "capybara" Cheers, David > > > and I pared it down to only what I needed to write an integration test, > and ended up with > > require 'action_dispatch' > require 'capybara/rails' > require 'capybara/dsl' > > module RSpec::Rails > module IntegrationExampleGroup > include ActionDispatch::Integration::Runner > include Capybara > > def app > ::Rails.application > end > > RSpec.configure do |c| > c.include self, :example_group => { :file_path => > /\bspec\/integration\// } > end > > end > end > > I understand why I would need special config to include Capybara, but I > don't understand why I need to define app and include the > ActionDisplatch stuff -- I thought that would come automagically with > rspec-rails by just including spec_helper. > > My whole little test project is here: > https://github.com/blazingcloud/rspec-capybara > > Before I give this to other folks as example code, I would really like > to understand it and know if there is an easier/better/more recommended > way to do this. > > Thanks, > Sarah > work http://blazingcloud.net/ > personal blog http://www.ultrasaurus.com > > p.s. I know cucumber is an alternate way. I'm doing a compare/contrast. > The cucumber version is here: > https://github.com/blazingcloud/cucumber_lesson From dk at structuralartistry.com Sat Dec 18 16:07:30 2010 From: dk at structuralartistry.com (David Kahn) Date: Sat, 18 Dec 2010 15:07:30 -0600 Subject: [rspec-users] Configuring RSpec for Integration Test In-Reply-To: <80F2BC20-1356-462C-8348-AED473C716C6@gmail.com> References: <80F2BC20-1356-462C-8348-AED473C716C6@gmail.com> Message-ID: On Sat, Dec 18, 2010 at 2:47 PM, David Chelimsky wrote: > On Dec 18, 2010, at 2:11 PM, Sarah Allen wrote: > > > In using RSpec for integration testing with Capybara, I was surprised > > thave I needed to do extra configuration. I started with the config > > from this blog post: > > http://codingfrontier.com/integration-testing-setup-with-rspec-2-and-ca > Also, you might want to check out Steak... it runs inside Rspec, I have been using in lieu of Cucumber starting this week and I am very happy and enjoying the process: https://github.com/cavalle/steak > > That blog post was based on a beta version of rspec-rails 2 before we got > the integration worked out :) > > Per "Webrat and Capybara" on http://relishapp.com/rspec/rspec-rails, all > you should need now is this in your Gemfile: > > gem "capybara" > > Cheers, > David > > > > > > > and I pared it down to only what I needed to write an integration test, > > and ended up with > > > > require 'action_dispatch' > > require 'capybara/rails' > > require 'capybara/dsl' > > > > module RSpec::Rails > > module IntegrationExampleGroup > > include ActionDispatch::Integration::Runner > > include Capybara > > > > def app > > ::Rails.application > > end > > > > RSpec.configure do |c| > > c.include self, :example_group => { :file_path => > > /\bspec\/integration\// } > > end > > > > end > > end > > > > I understand why I would need special config to include Capybara, but I > > don't understand why I need to define app and include the > > ActionDisplatch stuff -- I thought that would come automagically with > > rspec-rails by just including spec_helper. > > > > My whole little test project is here: > > https://github.com/blazingcloud/rspec-capybara > > > > Before I give this to other folks as example code, I would really like > > to understand it and know if there is an easier/better/more recommended > > way to do this. > > > > > Thanks, > > Sarah > > work http://blazingcloud.net/ > > personal blog http://www.ultrasaurus.com > > > > p.s. I know cucumber is an alternate way. I'm doing a compare/contrast. > > The cucumber version is here: > > https://github.com/blazingcloud/cucumber_lesson > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Dec 18 18:32:38 2010 From: lists at ruby-forum.com (Sarah Allen) Date: Sun, 19 Dec 2010 00:32:38 +0100 Subject: [rspec-users] Configuring RSpec for Integration Test In-Reply-To: <80F2BC20-1356-462C-8348-AED473C716C6@gmail.com> References: <80F2BC20-1356-462C-8348-AED473C716C6@gmail.com> Message-ID: <7a66bb5738cf176fa0c670b0964e9645@ruby-forum.com> David Chelimsky wrote in post #969325: > Per "Webrat and Capybara" on http://relishapp.com/rspec/rspec-rails, all > you should need now is this in your Gemfile: > > gem "capybara" > > Cheers, > David I did that, but then it didn't recognize my named route "root_path" or the capybara method "visit" I wondered whether it was because I was creating a new "integration" directory that needed it's own special config somehow... but I'm just guessing. Thanks, Sarah -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Dec 18 18:54:08 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Dec 2010 17:54:08 -0600 Subject: [rspec-users] Configuring RSpec for Integration Test In-Reply-To: <7a66bb5738cf176fa0c670b0964e9645@ruby-forum.com> References: <80F2BC20-1356-462C-8348-AED473C716C6@gmail.com> <7a66bb5738cf176fa0c670b0964e9645@ruby-forum.com> Message-ID: On Dec 18, 2010, at 5:32 PM, Sarah Allen wrote: > David Chelimsky wrote in post #969325: >> Per "Webrat and Capybara" on http://relishapp.com/rspec/rspec-rails, all >> you should need now is this in your Gemfile: >> >> gem "capybara" >> >> Cheers, >> David > > I did that, but then it didn't recognize my named route "root_path" or > the capybara method "visit" > > I wondered whether it was because I was creating a new "integration" > directory that needed it's own special config somehow... but I'm just > guessing. Yes - that's the problem. For rspec to do what it does implicitly you need to put things in a standard set of directories. What you're thinking of as integration specs go in spec/requests. If you need to use spec/integration instead, then you'll need to tell RSpec to include RSpec::Rails::RequestExampleGroup in those examples. You can do that on a per group basis, like this: describe "something" do include RSpec::Rails::RequestExampleGroup ... end Or globally like this: RSpec.configure do |config| config.include RSpec::Rails::RequestExampleGroup, :example_group => { :file_path => /spec\/integration/ } end Or via a combination of config and per-group metadata, like this: RSpec.configure do |config| config.include RSpec::Rails::RequestExampleGroup, :type => :integration end describe "something", :type => :integration do .. end HTH, David From apremdas at gmail.com Sun Dec 19 08:20:58 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Sun, 19 Dec 2010 13:20:58 +0000 Subject: [rspec-users] "unit" vs. "functional" specs In-Reply-To: References: Message-ID: When doing BDD, especially at the start, I found it really easy to write more code than you need to, when implementing a particular functional spec. I also found it really easy to miss the point where you should move into the inner cycle (unit cycle). Using the unit test coverage metric to make sure you only write what you need and that all your public method interfaces are specified at the unit level seems laudable. Of course 100% test coverage by itself doesn't mean that much, but examining the code you have missed and the reasons why your application of BDD failed to cover the code is instructive. On 18 December 2010 10:59, Pat Maddox wrote: > Why don't functional specs count towards your coverage metric? It sounds > like you're shooting for 100% unit test coverage -- why? If you write code > in order to make your functional specs pass, then that code was > TDD'd...right? > > Pat > > > On Dec 10, 2010, at 2:29 PM, Andrew Wagner > wrote: > > > I went back and forth on whether to send this to this list or the > ruby-talk list, so feel free to tell me to take a hike... > > > > I'm working on a personal project where I'm trying to keep a really high > bar on quality. One of the ways I'm doing that is to stick very close to the > BDD/TDD cycle as suggested in the RSpec book. However, I'm actually using > rspec for both the feature-level (BDD) tests and the unit-level (TDD) tests. > I'm also striving for 100% test coverage using Simplecov. > > > > That said, I just realized that, to enforce that cycle, it's also > important that I ask "do my unit tests by themselves provide 100% test > coverage?". Because, otherwise, it's easy to get excited and write code to > make the feature past, that isn't TDD'd. > > > > Anyway, all that to ask: is there some way to configure Simplecov to emit > code coverage stats for just a subset of all the tests that are running? > That is, I want to set up my rakefile such that it runs all my tests, but > only reports on code coverage for the unit tests. > > > > Am I going about this with the right mindset? Any suggestions? > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sun Dec 19 17:36:57 2010 From: lists at ruby-forum.com (Daniel C.) Date: Sun, 19 Dec 2010 23:36:57 +0100 Subject: [rspec-users] Rspec & Rails Nested Resources In-Reply-To: <7aa0aa0396b0a525d8bcad98b58612e0@ruby-forum.com> References: <7aa0aa0396b0a525d8bcad98b58612e0@ruby-forum.com> Message-ID: Thanks for your response Pat - I ended up taking the stub_chain method which got it working. For anyone interested this is my new test: it "GET new" do @correspondence = mock_model(Correspondence) @job.stub_chain(:correspondences, :build).and_return(@correspondence) get :new, :job_id => @job assigns[:correspondence].should be_an_instance_of Correspondence end -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Dec 20 11:54:37 2010 From: lists at ruby-forum.com (Thomas Andrews) Date: Mon, 20 Dec 2010 17:54:37 +0100 Subject: [rspec-users] Rspec-rails with gems 1.3.4 Message-ID: <46387e75c8421569f8f79299043a6c3a@ruby-forum.com> When I try to install rspec-rails it tells me: ERROR: Error installing rspec-rails: i18n requires RubyGems version >= 1.3.5 I am using RubyGems 1.3.4, and I am locked down to that version at the client site. Is there a version of rspec-rails that I can install without i18n? =thomas -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Dec 20 11:56:23 2010 From: lists at ruby-forum.com (Roger Pack) Date: Mon, 20 Dec 2010 17:56:23 +0100 Subject: [rspec-users] feature suggestion: straight strings Message-ID: <5cee906f8d3fd9d7d61fa6b5390f2cc9@ruby-forum.com> Sorry if I mentioned this one before, but has anyone proposed being able to do something like "it should be able".to { } ? (or something like that)... Might be preferable where a test description doesn't start with "it" Thoughts? Thanks. -r -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Dec 20 13:02:16 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Dec 2010 12:02:16 -0600 Subject: [rspec-users] feature suggestion: straight strings In-Reply-To: <5cee906f8d3fd9d7d61fa6b5390f2cc9@ruby-forum.com> References: <5cee906f8d3fd9d7d61fa6b5390f2cc9@ruby-forum.com> Message-ID: On Dec 20, 2010, at 10:56 AM, Roger Pack wrote: > Sorry if I mentioned this one before, but has anyone proposed being able > to do something like > > > "it should be able".to { > > } > > ? (or something like that)... > > Might be preferable where a test description doesn't start with "it" I think ending in "to" is just as constraining as starting with "it", no? > Thoughts? "it" and "specify" are both aliases for "example", so you can say: describe "foo" do example "doing something or other" do ... end end HTH, David > > Thanks. > -r > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Dec 20 13:04:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Dec 2010 12:04:58 -0600 Subject: [rspec-users] Rspec-rails with gems 1.3.4 In-Reply-To: <46387e75c8421569f8f79299043a6c3a@ruby-forum.com> References: <46387e75c8421569f8f79299043a6c3a@ruby-forum.com> Message-ID: <0AC68EBD-D15B-436C-8FF3-1EC6637EF60C@gmail.com> On Dec 20, 2010, at 10:54 AM, Thomas Andrews wrote: > When I try to install rspec-rails it tells me: > > ERROR: Error installing rspec-rails: > i18n requires RubyGems version >= 1.3.5 > > > I am using RubyGems 1.3.4, and I am locked down to that version at the > client site. Is there a version of rspec-rails that I can install > without i18n? What version of rails are you using? I'm guessing if you're locked at 1.3.4, you're also locked at rails < 3.0, in which case you'd want rspec-rails-1.3.3. HTH, David > > =thomas > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Dec 20 13:33:14 2010 From: lists at ruby-forum.com (Thomas Andrews) Date: Mon, 20 Dec 2010 19:33:14 +0100 Subject: [rspec-users] Rspec-rails with gems 1.3.4 In-Reply-To: <0AC68EBD-D15B-436C-8FF3-1EC6637EF60C@gmail.com> References: <46387e75c8421569f8f79299043a6c3a@ruby-forum.com> <0AC68EBD-D15B-436C-8FF3-1EC6637EF60C@gmail.com> Message-ID: <8838a1d37f12ad8aac0c51de457f1783@ruby-forum.com> David Chelimsky wrote in post #969618: > On Dec 20, 2010, at 10:54 AM, Thomas Andrews wrote: > >> When I try to install rspec-rails it tells me: >> >> ERROR: Error installing rspec-rails: >> i18n requires RubyGems version >= 1.3.5 >> >> >> I am using RubyGems 1.3.4, and I am locked down to that version at the >> client site. Is there a version of rspec-rails that I can install >> without i18n? > > What version of rails are you using? I'm guessing if you're locked at > 1.3.4, you're also locked at rails < 3.0, in which case you'd want > rspec-rails-1.3.3. > > > HTH, > David Thanks, that worked. Yeah, sorry, I should have given my rails version, which, for the record, is 2.3.5. =thomas -- Posted via http://www.ruby-forum.com/. From apremdas at gmail.com Mon Dec 20 18:47:24 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Mon, 20 Dec 2010 23:47:24 +0000 Subject: [rspec-users] Testing html email content with have_selector rspec2 rails3 fails In-Reply-To: References: Message-ID: Rob, This doesn't make sense 1. None of your examples here are using have_selector ! 2. Why is OrderMailer no longer creating a receipt 3. Why is @mailer being encoded Is mailer.body the same in both versions, can you show this. Have you tried using a debugger before the first have_tag line. All best Andrew :) On 30 November 2010 12:10, Rob Aldred wrote: > Previously on rails 2.x > I have been able to test the content of my html actionmailer emails. > > In rspec 1.x: > > @mailer = OrderMailer.create_receipt(@order) > @mailer.body.should have_tag('.order_number') > @mailer.body.should have_tag('.billing_address') > @mailer.body.should have_tag('.delivery_address') > > I have changed to rspec 2.x style > > @mailer = OrderMailer.receipt(@order) > @body = @mailer.encoded > @body.should have_tag('.order_number') > @body.should have_tag('.billing_address') > @body.should have_tag('.delivery_address') > > It fails. > I suspect theres something else that have_tag was doing that > have_selector is not? > Am I doing something wrong? Is there a better way to tests the content > of my emails? > > Maybe I should never have tested email content this way, is it more a > job for cucumber? > Look forward to your responses. > > Thanks > Rob > _______________________________________________ > 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 robert.dober at gmail.com Tue Dec 21 06:48:07 2010 From: robert.dober at gmail.com (Robert Dober) Date: Tue, 21 Dec 2010 12:48:07 +0100 Subject: [rspec-users] feature suggestion: straight strings In-Reply-To: References: <5cee906f8d3fd9d7d61fa6b5390f2cc9@ruby-forum.com> Message-ID: On Mon, Dec 20, 2010 at 7:02 PM, David Chelimsky wrote: Probably one could argue that in a spec environment what I am about to say does not apply as much as in production code. Yet I feel that it is not the responsibility of a String to describe an example. This theoretical observation apart, I find the idea rather appealing. Anyway I am not qualified to vote or judge, just wanted to share these thoughts. Cheers Robert -- The 1,000,000th fibonacci number contains '42' 2039 times; that is almost 30 occurrences more than expected (208988 digits). N.B. The 42nd fibonacci number does not contain '1000000' that is almost the expected 3.0e-06 times. From johan.rejeep at gmail.com Tue Dec 21 15:11:01 2010 From: johan.rejeep at gmail.com (rejeep) Date: Tue, 21 Dec 2010 12:11:01 -0800 (PST) Subject: [rspec-users] Make macros DRY Message-ID: <1c2c9f84-c840-431c-94c7-ce7ad778e7c4@t35g2000yqj.googlegroups.com> Hey, I have lots of problems to refactor RSpec macros and make them DRY. Right now I'm stuck in such a situation for some role macros. In my controller tests, I want to write: 1) it_should_grant_access(:super_admin, :to => :countries) 2) it_should_grant_access(:admin, :to => :countries, :only => [:index, :show]) 3) it_should_not_grant_access(:user, :to => :countries) These three rules should make sure that: 1) Super admin should be granted access to all default actions in the countries controller 2) Admin should be granted access to index and show, but not to new, create, edit, update or destroy 3) User should not be granted access to any of the default actions Since I want to be using this from many places, I used a module: module RoleMacros DEFAULT_ACTIONS = [:index, :show, :new, :create, :edit, :update, :destroy] def it_should_grant_access(role, options) # ... if except.present? actions = DEFAULT_ACTIONS - Array(except) elsif only.present? actions = Array(only) else actions = DEFAULT_ACTIONS end # ... end def it_not_should_grant_access(role, options) # ... end end As you see from the example code there are some stuff I need to do before I can do the actual testing. My question is how to solve this in a DRY way so that I can use the set up code in the "not" case as well? Another problem is that when I specify that some role should have access to some actions, it also means that the role should not have access to all but those actions. This means that I must have each request test in separate so that I can call them. But I'm not sure how to do this. Thanks! From dchelimsky at gmail.com Tue Dec 21 21:03:16 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Dec 2010 20:03:16 -0600 Subject: [rspec-users] Make macros DRY In-Reply-To: <1c2c9f84-c840-431c-94c7-ce7ad778e7c4@t35g2000yqj.googlegroups.com> References: <1c2c9f84-c840-431c-94c7-ce7ad778e7c4@t35g2000yqj.googlegroups.com> Message-ID: <5CA3FA0C-EAFD-4500-8C3B-AA2253DEF10E@gmail.com> On Dec 21, 2010, at 2:11 PM, rejeep wrote: > Hey, > > I have lots of problems to refactor RSpec macros and make them DRY. > Right now I'm stuck in such a situation for some role macros. > > In my controller tests, I want to write: > > 1) it_should_grant_access(:super_admin, :to => :countries) > 2) it_should_grant_access(:admin, :to => :countries, :only => > [:index, :show]) > 3) it_should_not_grant_access(:user, :to => :countries) > > These three rules should make sure that: > > 1) Super admin should be granted access to all default actions in > the countries controller > 2) Admin should be granted access to index and show, but not to new, > create, edit, update or destroy > 3) User should not be granted access to any of the default actions > > Since I want to be using this from many places, I used a module: > > module RoleMacros > DEFAULT_ACTIONS = > [:index, :show, :new, :create, :edit, :update, :destroy] > > def it_should_grant_access(role, options) > > # ... > > if except.present? > actions = DEFAULT_ACTIONS - Array(except) > elsif only.present? > actions = Array(only) > else > actions = DEFAULT_ACTIONS > end > > # ... > > end > > def it_not_should_grant_access(role, options) > # ... > end > end > > As you see from the example code there are some stuff I need to do > before I can do the actual testing. > > My question is how to solve this in a DRY way so that I can use the > set up code in the "not" case as well? Just use the Extract Method refactoring: def it_should_grant_access(role, options) actions_from(options).each do |action| # ... end end def it_not_should_grant_access(role, options) actions_from(options).each do |action| # ... end end def actions_from(options) if options[:except] DEFAULT_ACTIONS - options[:except] elsif options[:only] options[:only] else DEFAULT_ACTIONS end end > Another problem is that when I specify that some role should have > access to some actions, it also means that the role should not have > access to all but those actions. This means that I must have each > request test in separate so that I can call them. But I'm not sure how > to do this. Just use one macro: def it_should_grant_access(role, options) actions_from(options).each do |action| # ... specify grant access end (DEFAULT_ACTIONS - actions_from(options)).each do |action| # ... specify deny access end end HTH, David > Thanks! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From wolfmanjm at gmail.com Wed Dec 22 03:51:53 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Wed, 22 Dec 2010 00:51:53 -0800 (PST) Subject: [rspec-users] running rspec in spec/requests directory with cells fails Message-ID: Hi, not exactly sure if this is a cells bug or an rspec (or both), but when running a simple request spec from the spec/requests directory gets an error whereas running it from the RAILS ROOT directory it works.. Seems it cannot find the view in the cells directory. The full project is in https://github.com/wolfmanjm/wolfmanblog_rails. Using rails 3.0.3 and rspec-rails 2.2.1 > cd spec/request > rspec basics_spec.rb [sequel] Setting up the "test" environment: F Failures: 1) Basic tests works! (now write some real specs) Failure/Error: visit "/" Missing template cell/rails/google_search with {:locale=>[:en, :en], :handlers=>[:haml, :rjs, :rhtml, :rxml, :erb, :builder], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json]} in view paths "/home/morris/work/ruby/rails3/wolfmanblog/spec/requests/ app/cells", "/home/morris/work/ruby/rails3/wolfmanblog/spec/requests/ app/cells/layouts" and possible paths sidebar/google_searchcell/rails/ google_search # /home/morris/work/ruby/rails3/wolfmanblog/app/cells/ sidebar_cell.rb:8:in `google_search' # /home/morris/work/ruby/rails3/wolfmanblog/app/helpers/ application_helper.rb:3:in `sidebar' # /home/morris/work/ruby/rails3/wolfmanblog/app/views/layouts/ application.html.haml:34:in `_app_views_layouts_application_html_haml__882586219_84745880_0' # ./basics_spec.rb:5 Finished in 0.14442 seconds 1 example, 1 failure From johan.rejeep at gmail.com Wed Dec 22 05:11:21 2010 From: johan.rejeep at gmail.com (rejeep) Date: Wed, 22 Dec 2010 02:11:21 -0800 (PST) Subject: [rspec-users] Make macros DRY In-Reply-To: <5CA3FA0C-EAFD-4500-8C3B-AA2253DEF10E@gmail.com> References: <1c2c9f84-c840-431c-94c7-ce7ad778e7c4@t35g2000yqj.googlegroups.com> <5CA3FA0C-EAFD-4500-8C3B-AA2253DEF10E@gmail.com> Message-ID: Thanks for your reply David! My solution ended up something like this: def it_should_grant_access(role, options) request_index = proc do get :index response.success? end # ... actions_from(options).each do |action| request = instance_eval(&eval("request_#{action}")) request.should be_true, "#{role} should have been granted access to #{action}, but was not" end # ... end Not perfect, but it works. Btw, I solved the "not-case" by flipping only and except and then just call it_should_grant_access. Thanks! On Dec 22, 3:03?am, David Chelimsky wrote: > On Dec 21, 2010, at 2:11 PM, rejeep wrote: > > > > > > > > > > > Hey, > > > I have lots of problems to refactor RSpec macros and make them DRY. > > Right now I'm stuck in such a situation for some role macros. > > > In my controller tests, I want to write: > > > ?1) it_should_grant_access(:super_admin, :to => :countries) > > ?2) it_should_grant_access(:admin, :to => :countries, :only => > > [:index, :show]) > > ?3) it_should_not_grant_access(:user, :to => :countries) > > > These three rules should make sure that: > > > ?1) Super admin should be granted access to all default actions in > > the countries controller > > ?2) Admin should be granted access to index and show, but not to new, > > create, edit, update or destroy > > ?3) User should not be granted access to any of the default actions > > > Since I want to be using this from many places, I used a module: > > > ?module RoleMacros > > ? ?DEFAULT_ACTIONS = > > [:index, :show, :new, :create, :edit, :update, :destroy] > > > ? ?def it_should_grant_access(role, options) > > > ? ? ?# ... > > > ? ? ?if except.present? > > ? ? ? ?actions = DEFAULT_ACTIONS - Array(except) > > ? ? ?elsif only.present? > > ? ? ? ?actions = Array(only) > > ? ? ?else > > ? ? ? ?actions = DEFAULT_ACTIONS > > ? ? ?end > > > ? ? ?# ... > > > ? ?end > > > ? ?def it_not_should_grant_access(role, options) > > ? ? ?# ... > > ? ?end > > ?end > > > As you see from the example code there are some stuff I need to do > > before I can do the actual testing. > > > My question is how to solve this in a DRY way so that I can use the > > set up code in the "not" case as well? > > Just use the Extract Method refactoring: > > def it_should_grant_access(role, options) > ? actions_from(options).each do |action| > ? ? # ... > ? end > end > > def it_not_should_grant_access(role, options) > ? actions_from(options).each do |action| > ? ? # ... > ? end > end > > def actions_from(options) > ? if options[:except] > ? ? DEFAULT_ACTIONS - options[:except] > ? elsif options[:only] > ? ? options[:only] > ? else > ? ? DEFAULT_ACTIONS > ? end > end > > > Another problem is that when I specify that some role should have > > access to some actions, it also means that the role should not have > > access to all but those actions. This means that I must have each > > request test in separate so that I can call them. But I'm not sure how > > to do this. > > Just use one macro: > > def it_should_grant_access(role, options) > ? actions_from(options).each do |action| > ? ? # ... specify grant access > ? end > ? (DEFAULT_ACTIONS - actions_from(options)).each do |action| > ? ? # ... specify deny access > ? end > end > > HTH, > David > > > Thanks! > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Dec 22 08:52:24 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Dec 2010 07:52:24 -0600 Subject: [rspec-users] running rspec in spec/requests directory with cells fails In-Reply-To: References: Message-ID: On Dec 22, 2010, at 2:51 AM, Jim Morris wrote: > Hi, not exactly sure if this is a cells bug or an rspec (or both), but > when running a simple request spec > from the spec/requests directory gets an error whereas running it from > the RAILS ROOT directory it works.. > Seems it cannot find the view in the cells directory. > > The full project is in https://github.com/wolfmanjm/wolfmanblog_rails. > Using rails 3.0.3 and rspec-rails 2.2.1 > >> cd spec/request Try running from the project root instead: $ rspec spec/requests/basics_spec.rb or $ rspec spec/requests or $ rake spec:requests HTH, David >> rspec basics_spec.rb > > [sequel] Setting up the "test" environment: > F > > Failures: > > 1) Basic tests works! (now write some real specs) > Failure/Error: visit "/" > Missing template cell/rails/google_search with > {:locale=>[:en, :en], :handlers=>[:haml, :rjs, :rhtml, :rxml, :erb, :builder], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json]} > in view paths "/home/morris/work/ruby/rails3/wolfmanblog/spec/requests/ > app/cells", "/home/morris/work/ruby/rails3/wolfmanblog/spec/requests/ > app/cells/layouts" and possible paths sidebar/google_searchcell/rails/ > google_search > # /home/morris/work/ruby/rails3/wolfmanblog/app/cells/ > sidebar_cell.rb:8:in `google_search' > # /home/morris/work/ruby/rails3/wolfmanblog/app/helpers/ > application_helper.rb:3:in `sidebar' > # /home/morris/work/ruby/rails3/wolfmanblog/app/views/layouts/ > application.html.haml:34:in > `_app_views_layouts_application_html_haml__882586219_84745880_0' > # ./basics_spec.rb:5 > > Finished in 0.14442 seconds > 1 example, 1 failure > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From wolfmanjm at gmail.com Wed Dec 22 14:44:51 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Wed, 22 Dec 2010 11:44:51 -0800 (PST) Subject: [rspec-users] running rspec in spec/requests directory with cells fails In-Reply-To: References: Message-ID: <7c2fbd90-41b5-4704-9de8-9310f9d0f305@i32g2000pri.googlegroups.com> Yes it works from ROOT as I said in original post :) However I can run normal request specs from the request directory itself, if they don't use cells. Is rspec meant to only run from ROOT? Also this part of the error message seems suspicious... and possible paths sidebar/google_searchcell/rails/google_search Seems to have concatenated two paths into one. The reason I am asking is because the rspec-mode for emacs runs its specs from the directory the spec you are testing resides. I'll need to fix that if rspec is not meant to be run from there. Thanks On Dec 22, 5:52?am, David Chelimsky wrote: > On Dec 22, 2010, at 2:51 AM, Jim Morris wrote: > > > Hi, not exactly sure if this is a cells bug or an rspec (or both), but > > when running a simple request spec > > from the spec/requests directory gets an error whereas running it from > > the RAILS ROOT directory it works.. > > Seems it cannot find the view in the cells directory. > > > The full project is inhttps://github.com/wolfmanjm/wolfmanblog_rails. > > Using rails 3.0.3 and rspec-rails 2.2.1 > > >> cd spec/request > > Try running from the project root instead: > > $ rspec spec/requests/basics_spec.rb > > or > > $ rspec spec/requests > > or > > $ rake spec:requests > > HTH, > David > > > > >> rspec basics_spec.rb > > > [sequel] Setting up the "test" environment: > > F > > > Failures: > > > ?1) Basic tests works! (now write some real specs) > > ? ? Failure/Error: visit "/" > > ? ? Missing template cell/rails/google_search with > > {:locale=>[:en, :en], :handlers=>[:haml, :rjs, :rhtml, :rxml, :erb, :builder], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json]} > > in view paths "/home/morris/work/ruby/rails3/wolfmanblog/spec/requests/ > > app/cells", "/home/morris/work/ruby/rails3/wolfmanblog/spec/requests/ > > app/cells/layouts" and possible paths sidebar/google_searchcell/rails/ > > google_search > > ? ? # /home/morris/work/ruby/rails3/wolfmanblog/app/cells/ > > sidebar_cell.rb:8:in `google_search' > > ? ? # /home/morris/work/ruby/rails3/wolfmanblog/app/helpers/ > > application_helper.rb:3:in `sidebar' > > ? ? # /home/morris/work/ruby/rails3/wolfmanblog/app/views/layouts/ > > application.html.haml:34:in > > `_app_views_layouts_application_html_haml__882586219_84745880_0' > > ? ? # ./basics_spec.rb:5 > > > Finished in 0.14442 seconds > > 1 example, 1 failure > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Dec 22 15:09:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Dec 2010 14:09:33 -0600 Subject: [rspec-users] running rspec in spec/requests directory with cells fails In-Reply-To: <7c2fbd90-41b5-4704-9de8-9310f9d0f305@i32g2000pri.googlegroups.com> References: <7c2fbd90-41b5-4704-9de8-9310f9d0f305@i32g2000pri.googlegroups.com> Message-ID: <2CE2F2EA-E23F-439F-A9A0-7DF6D45C88F7@gmail.com> On Dec 22, 2010, at 1:44 PM, Jim Morris wrote: > Yes it works from ROOT as I said in original post :) Oops. Missed that. > However I can run normal request specs from the request directory > itself, if they don't use cells. > > Is rspec meant to only run from ROOT? Yes. You _can_ get it to work elsewhere, but you have to do some fun things w/ the LOAD_PATH to do it. > Also this part of the error message seems suspicious... > > and possible paths sidebar/google_searchcell/rails/google_search > > Seems to have concatenated two paths into one. > > The reason I am asking is because the rspec-mode for emacs runs its > specs from the directory the spec you are testing resides. > I'll need to fix that if rspec is not meant to be run from there. Yeah, that's the case. Cheers, David > > Thanks > > > On Dec 22, 5:52 am, David Chelimsky wrote: >> On Dec 22, 2010, at 2:51 AM, Jim Morris wrote: >> >>> Hi, not exactly sure if this is a cells bug or an rspec (or both), but >>> when running a simple request spec >>> from the spec/requests directory gets an error whereas running it from >>> the RAILS ROOT directory it works.. >>> Seems it cannot find the view in the cells directory. >> >>> The full project is inhttps://github.com/wolfmanjm/wolfmanblog_rails. >>> Using rails 3.0.3 and rspec-rails 2.2.1 >> >>>> cd spec/request >> >> Try running from the project root instead: >> >> $ rspec spec/requests/basics_spec.rb >> >> or >> >> $ rspec spec/requests >> >> or >> >> $ rake spec:requests >> >> HTH, >> David >> >> >> >>>> rspec basics_spec.rb >> >>> [sequel] Setting up the "test" environment: >>> F >> >>> Failures: >> >>> 1) Basic tests works! (now write some real specs) >>> Failure/Error: visit "/" >>> Missing template cell/rails/google_search with >>> {:locale=>[:en, :en], :handlers=>[:haml, :rjs, :rhtml, :rxml, :erb, :builder], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json]} >>> in view paths "/home/morris/work/ruby/rails3/wolfmanblog/spec/requests/ >>> app/cells", "/home/morris/work/ruby/rails3/wolfmanblog/spec/requests/ >>> app/cells/layouts" and possible paths sidebar/google_searchcell/rails/ >>> google_search >>> # /home/morris/work/ruby/rails3/wolfmanblog/app/cells/ >>> sidebar_cell.rb:8:in `google_search' >>> # /home/morris/work/ruby/rails3/wolfmanblog/app/helpers/ >>> application_helper.rb:3:in `sidebar' >>> # /home/morris/work/ruby/rails3/wolfmanblog/app/views/layouts/ >>> application.html.haml:34:in >>> `_app_views_layouts_application_html_haml__882586219_84745880_0' >>> # ./basics_spec.rb:5 >> >>> Finished in 0.14442 seconds >>> 1 example, 1 failure >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> Cheers, >> David >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jeroentjevandijk at gmail.com Thu Dec 23 05:57:36 2010 From: jeroentjevandijk at gmail.com (Jeroen van Dijk) Date: Thu, 23 Dec 2010 11:57:36 +0100 Subject: [rspec-users] Use filters to wrap examples into a pending block? Message-ID: Hi all, I was wonder whether something like the following is possible in RSpec? RSpec.configure do |c| c.filter_examples : pending_for_some_reason => lambda {|example| pending "This example is failing due to upgrade of x" do example.call end } end it "should succeed, but probably doesn't yet", :pending_for_some_reason => true do raise "fail" end I'm currently working on a library that has many failing specs due to an upgrade of a dependency. It would be nice if a could just flag examples that are failing due to that change without having to copy paste the pending block. Cheers, Jeroen -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeroentjevandijk at gmail.com Thu Dec 23 06:40:40 2010 From: jeroentjevandijk at gmail.com (Jeroen van Dijk) Date: Thu, 23 Dec 2010 12:40:40 +0100 Subject: [rspec-users] Use filters to wrap examples into a pending block? In-Reply-To: References: Message-ID: Found the answer by looking at the features: RSpec.configure do |c| c.around do |example| if example.metadata.has_key?(:broken) pending "is broken since change from 3.0.0.beta4 to 3.0.3" do example.call end end end end Nice :-) On Thu, Dec 23, 2010 at 11:57 AM, Jeroen van Dijk < jeroentjevandijk at gmail.com> wrote: > Hi all, > > I was wonder whether something like the following is possible in RSpec? > > RSpec.configure do |c| > c.filter_examples : pending_for_some_reason => lambda {|example| > pending "This example is failing due to upgrade of x" do > example.call > end > } > end > > it "should succeed, but probably doesn't yet", :pending_for_some_reason => > true do > raise "fail" > end > > I'm currently working on a library that has many failing specs due to an > upgrade of a dependency. It would be nice if a could just flag examples that > are failing due to that change without having to copy paste the pending > block. > > Cheers, > Jeroen > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeroentjevandijk at gmail.com Thu Dec 23 07:02:15 2010 From: jeroentjevandijk at gmail.com (Jeroen van Dijk) Date: Thu, 23 Dec 2010 13:02:15 +0100 Subject: [rspec-users] Use filters to wrap examples into a pending block? In-Reply-To: References: Message-ID: Oh and don't forget the 'else' part: RSpec.configure do |c| c.around do |example| if example.metadata.has_key?(:broken) pending "is broken since change from 3.0.0.beta4 to 3.0.3" do example.call end else example.call end end end Suddenly my test suite was mega fast and I had no failing specs... oops :-) Cheers On Thu, Dec 23, 2010 at 12:40 PM, Jeroen van Dijk < jeroentjevandijk at gmail.com> wrote: > Found the answer by looking at the features: > > RSpec.configure do |c| > c.around do |example| > if example.metadata.has_key?(:broken) > pending "is broken since change from 3.0.0.beta4 to 3.0.3" do > example.call > end > end > end > end > > Nice :-) > > On Thu, Dec 23, 2010 at 11:57 AM, Jeroen van Dijk < > jeroentjevandijk at gmail.com> wrote: > >> Hi all, >> >> I was wonder whether something like the following is possible in RSpec? >> >> RSpec.configure do |c| >> c.filter_examples : pending_for_some_reason => lambda {|example| >> pending "This example is failing due to upgrade of x" do >> example.call >> end >> } >> end >> >> it "should succeed, but probably doesn't yet", :pending_for_some_reason => >> true do >> raise "fail" >> end >> >> I'm currently working on a library that has many failing specs due to an >> upgrade of a dependency. It would be nice if a could just flag examples that >> are failing due to that change without having to copy paste the pending >> block. >> >> Cheers, >> Jeroen >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumangurung at gmail.com Wed Dec 22 14:28:08 2010 From: sumangurung at gmail.com (Suman Gurung) Date: Wed, 22 Dec 2010 11:28:08 -0800 (PST) Subject: [rspec-users] Stubbing out common setup Message-ID: <4f321664-d341-4f62-a116-53d17a3287f7@e20g2000vbn.googlegroups.com> I want to stub an after save method(which generates files and so, is time consuming), for most of my spec files apart from a few where that method is actually tested. I was trying to do this with using shared examples but with rspec 2, i believe before(:each) defined in the shared examples are automatically wrapped inside a 'context' in the host class. What would be a good way to include a setup like this in more than one spec files? before(:each) do stub some methods end What I am trying to achieve is not to have the above code in all my spec files. From darynholmes at gmail.com Wed Dec 22 12:58:30 2010 From: darynholmes at gmail.com (Daryn) Date: Wed, 22 Dec 2010 09:58:30 -0800 (PST) Subject: [rspec-users] View Specs Message-ID: Hi, I was using WebRat and I had view specs that looked like this: describe "expenses/new.html.erb" do it "displays 'New Expense'" do render rendered.should include("New Expense") end end I am now using Capybara and you cannot use those matchers in View Specs. What should my view specs look like? If I try using: get "expenses/edit" I end up with: undefined method `get' for # Am I meant to keep using render, rendered? How should the spec above be re-written? And the nested one below? it "renders a form to create an expense" do render rendered.should have_selector("form", :method => "post", :action => expenses_path ) do |form| form.should have_selector("input", :type => "text", :name => "expense[name]") form.should have_selector("input", :type => "text", :name => "expense[limit]") form.should have_selector("input", :type => "submit", :value => "Add") form.should have_selector("a", :content => "Cancel", :href => expenses_path) end end Thanks, Daryn From jeffdeville at gmail.com Tue Dec 21 21:26:36 2010 From: jeffdeville at gmail.com (JDeville) Date: Tue, 21 Dec 2010 18:26:36 -0800 (PST) Subject: [rspec-users] Inconsistent Test results w/ Autotest vs just rspec ./spec Message-ID: Problem ------------------------------------------------------- When I run autotest against my rails 3 app, I get some errors that seem to imply that my @ variables are not be cleared for each context. It happens only in my controller tests, but that may simply be a coincidence. When autotest tests either of these controllers in isolation, the tests pass. The first one is not messing up the second (I tried commenting out the first breaking test) When I run the entire spec w/ just rspec ./spec, everything passes. I tried to emulate what autotest calls with: bundle exec /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/ bin/ruby -S /Volumes/files/jeffdeville/.rvm/gems/ree-1.8.7-2010.02/ gems/rspec-core-2.3.1/bin/rspec --tty ./spec (I just replaced the individual file names with ./spec). That worked fine too. Environment ------------------------------------------------------- Gemfile bits ----------- group :test, :stress do gem 'mongoid-rspec' gem 'mocha' gem "rspec" gem "rspec-rails" gem "bourne" gem 'factory_girl_rails' gem "ZenTest" gem "autotest" gem "autotest-rails" gem "cucumber" gem "launchy" gem "gherkin" gem "cucumber-rails" gem "webrat" gem "capybara" gem "capybara-envjs" gem 'selenium-client' gem 'fakeweb' gem 'vcr' gem "httparty" gem 'rpm_contrib' gem 'newrelic_rpm' gem 'fuubar' gem 'ruby-debug' end Here are the gem versions being used. I've tried to filter it to just the ones I could see being relevant. Using ZenTest (4.4.2) Using autotest (4.4.6) Using autotest-rails (4.1.0) Using mocha (0.9.8) Using bourne (1.0) Using bundler (1.0.7) Using term-ansicolor (1.0.5) Using factory_girl (1.3.2) Using rails (3.0.3) Using factory_girl_rails (1.0) Using rspec-core (2.3.1) Using rspec-expectations (2.3.0) Using rspec-mocks (2.3.0) Using rspec (2.3.0) Using rspec-instafail (0.1.5) Using ruby-progressbar (0.0.9) Using mongoid-rspec (1.3.2) Using rspec-rails (2.3.1) I'm using ruby 1.8.7 REE I'm afraid I don't really know how autotest works I didn't seem to have this problem until recently, so I'm wondering if a recent release requires me to change something that I missed. Thanks From dchelimsky at gmail.com Fri Dec 24 06:03:34 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Dec 2010 06:03:34 -0500 Subject: [rspec-users] View Specs In-Reply-To: References: Message-ID: On Wed, Dec 22, 2010 at 12:58 PM, Daryn wrote: > Hi, > > I was using WebRat and I had view specs that looked like this: > > describe "expenses/new.html.erb" do > ?it "displays 'New Expense'" do > ? ?render > ? ?rendered.should include("New Expense") > ?end > end > > I am now using Capybara and you cannot use those matchers in View > Specs. > What should my view specs look like? > > If I try using: get "expenses/edit" > I end up with: undefined method `get' for > # > > > Am I meant to keep using render, rendered? > How should the spec above be re-written? > And the nested one below? > > it "renders a form to create an expense" do > ? ? ?render > ? ?rendered.should have_selector("form", > ? ? ?:method => "post", > ? ? ?:action => expenses_path > ? ? ?) do |form| > > ? ? ? ?form.should have_selector("input", > ? ? ? ? ?:type => "text", > ? ? ? ? ?:name => "expense[name]") > > ? ? ? ?form.should have_selector("input", > ? ? ? ? ?:type => "text", > ? ? ? ? ?:name => "expense[limit]") > > ? ? ? ?form.should have_selector("input", > ? ? ? ? ?:type => "submit", > ? ? ? ? ?:value => "Add") > > ? ? ? ?form.should have_selector("a", > ? ? ? ? ? ?:content => "Cancel", > ? ? ? ? ? ?:href => expenses_path) > ? ? ?end > ? ?end render(), rendered(), and the include() matcher all come from rspec or rails, not Webrat or Capybara. get() is from rails, but only used in controller and request specs (which are thin wrappers for rails' functional and integration tests). The only thing you've lost for now is Webrat's have_selector() matcher. For right now your best bet is rails' assert_select: http://api.rubyonrails.org/classes/ActionDispatch/Assertions/SelectorAssertions.html#method-i-assert_select Sometime soon, Capybara's counterparts, have_selector() and have_xpath() will also be available in view specs. How soon, I'm not sure, but Jonas and I worked on this a bit together last month at RubyConf. HTH, David From dchelimsky at gmail.com Fri Dec 24 06:11:28 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Dec 2010 06:11:28 -0500 Subject: [rspec-users] Stubbing out common setup In-Reply-To: <4f321664-d341-4f62-a116-53d17a3287f7@e20g2000vbn.googlegroups.com> References: <4f321664-d341-4f62-a116-53d17a3287f7@e20g2000vbn.googlegroups.com> Message-ID: On Wed, Dec 22, 2010 at 2:28 PM, Suman Gurung wrote: > I want to stub an after save method(which generates files and so, is > time consuming), for most of my spec files apart from a few where that > method is actually tested. > I was trying to do this with using shared examples but with rspec 2, i > believe before(:each) defined in the shared examples are automatically > wrapped inside a 'context' in the host class. > > What would be a good way to include a setup like this in more than one > spec files? > > before(:each) do > ?stub some methods > end > > What I am trying to achieve is not to have the above code in all my > spec files. RSpec.configure do |config| config.before(:each, :type => :controller) do # stub some methods end end HTH, David From zhiqiang.lei at gmail.com Sun Dec 26 00:05:26 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Sun, 26 Dec 2010 13:05:26 +0800 Subject: [rspec-users] Mock in lambda? Message-ID: Hi, I have a lambda. Test = lambda { kill(333) } How should I spec if I want to make sure this Test will send kill message with 333? Thanks. Best regards, Zhi-Qiang Lei zhiqiang.lei at gmail.com From dchelimsky at gmail.com Sun Dec 26 00:25:15 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 26 Dec 2010 00:25:15 -0500 Subject: [rspec-users] Mock in lambda? In-Reply-To: References: Message-ID: On Sun, Dec 26, 2010 at 12:05 AM, Zhi-Qiang Lei wrote: > Hi, > > I have a lambda. > > Test = lambda { kill(333) } > > How should I spec if I want to make sure this Test will send kill message with 333? Thanks. Depends on the scope in which the block will be evaluated. Since kill is being called with no receiver, its implicit receiver will be the object in which it is evaluated, so you can mock it on that object, e.g: class Foo def bar yield end end foo = Foo.new foo.should_receive(:kill) foo.bar { kill(333) } Not sure if that aligns with your situation, but that should give you an idea. HTH, David > Best regards, > Zhi-Qiang Lei > zhiqiang.lei at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zhiqiang.lei at gmail.com Sun Dec 26 02:51:34 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Sun, 26 Dec 2010 15:51:34 +0800 Subject: [rspec-users] Mock in lambda? In-Reply-To: <20EF46F5-4B19-4096-81E7-48BD33A842E4@gmail.com> References: <20EF46F5-4B19-4096-81E7-48BD33A842E4@gmail.com> Message-ID: Sorry, it is my codes' fault. It works now. On Dec 26, 2010, at 3:47 PM, Zhi-Qiang Lei wrote: > Hi, > > I'm trying to mock the scope. > > Test = lambda { kill(333) } > app = double("test") > app.should_receive(:kill).with(333).once > app.instance_eval Test > > It will say that kill method miss in app. And to stub a kill method will not help. Can I only define a new class to test it? Thanks. > > On Dec 26, 2010, at 1:25 PM, David Chelimsky wrote: > >> On Sun, Dec 26, 2010 at 12:05 AM, Zhi-Qiang Lei wrote: >>> Hi, >>> >>> I have a lambda. >>> >>> Test = lambda { kill(333) } >>> >>> How should I spec if I want to make sure this Test will send kill message with 333? Thanks. >> >> Depends on the scope in which the block will be evaluated. Since kill >> is being called with no receiver, its implicit receiver will be the >> object in which it is evaluated, so you can mock it on that object, >> e.g: >> >> class Foo >> def bar >> yield >> end >> end >> >> foo = Foo.new >> foo.should_receive(:kill) >> foo.bar { kill(333) } >> >> Not sure if that aligns with your situation, but that should give you an idea. >> >> HTH, >> David >> >>> Best regards, >>> Zhi-Qiang Lei >>> zhiqiang.lei at gmail.com >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > Best regards, > Zhi-Qiang Lei > zhiqiang.lei at gmail.com > Best regards, Zhi-Qiang Lei zhiqiang.lei at gmail.com From zhiqiang.lei at gmail.com Sun Dec 26 02:47:10 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Sun, 26 Dec 2010 15:47:10 +0800 Subject: [rspec-users] Mock in lambda? In-Reply-To: References: Message-ID: <20EF46F5-4B19-4096-81E7-48BD33A842E4@gmail.com> Hi, I'm trying to mock the scope. Test = lambda { kill(333) } app = double("test") app.should_receive(:kill).with(333).once app.instance_eval Test It will say that kill method miss in app. And to stub a kill method will not help. Can I only define a new class to test it? Thanks. On Dec 26, 2010, at 1:25 PM, David Chelimsky wrote: > On Sun, Dec 26, 2010 at 12:05 AM, Zhi-Qiang Lei wrote: >> Hi, >> >> I have a lambda. >> >> Test = lambda { kill(333) } >> >> How should I spec if I want to make sure this Test will send kill message with 333? Thanks. > > Depends on the scope in which the block will be evaluated. Since kill > is being called with no receiver, its implicit receiver will be the > object in which it is evaluated, so you can mock it on that object, > e.g: > > class Foo > def bar > yield > end > end > > foo = Foo.new > foo.should_receive(:kill) > foo.bar { kill(333) } > > Not sure if that aligns with your situation, but that should give you an idea. > > HTH, > David > >> Best regards, >> Zhi-Qiang Lei >> zhiqiang.lei at gmail.com >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Best regards, Zhi-Qiang Lei zhiqiang.lei at gmail.com From dchelimsky at gmail.com Sun Dec 26 06:31:42 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 26 Dec 2010 06:31:42 -0500 Subject: [rspec-users] Inconsistent Test results w/ Autotest vs just rspec ./spec In-Reply-To: References: Message-ID: On Tue, Dec 21, 2010 at 9:26 PM, JDeville wrote: > Problem ------------------------------------------------------- > > > When I run autotest against my rails 3 app, I get some errors that > seem to imply that my @ variables are not be cleared for each > context. ?It happens only in my controller tests, but that may simply > be a coincidence. ?When autotest tests either of these controllers in > isolation, the tests pass. ?The first one is not messing up the second > (I tried commenting out the first breaking test) > > When I run the entire spec w/ just rspec ./spec, everything passes. ?I > tried to emulate what autotest calls with: > bundle exec /Volumes/files/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/ > bin/ruby -S /Volumes/files/jeffdeville/.rvm/gems/ree-1.8.7-2010.02/ > gems/rspec-core-2.3.1/bin/rspec --tty ./spec > (I just replaced the individual file names with ./spec). ?That worked > fine too. Replacing the filenames with ./spec won't necessarily get you the same result as having all the filenames spelled out. Autotest has a bunch of strategies for ordering files. The default is "random". In my experience, what you're seeing happens because there is a leaky example (one that leaves some global state modified) that only causes problems when run before other examples that rely on that bit of state. Try running the examples using different autotest ordering strategies and see what happens. Just put this in a .autotest file in the root of the project: Autotest.add_hook :initialize do |autotest| autotest.order = :alpha end Valid values are :alpha, :reverse, :random, :natural. HTH, David > Environment ?------------------------------------------------------- > > > Gemfile bits ----------- > group :test, :stress do > ? ? ? ?gem 'mongoid-rspec' > ? ? ? ?gem 'mocha' > ? ? ? ?gem "rspec" > ? ? ? ?gem "rspec-rails" > ? ? ? ?gem "bourne" > ? ? ? ?gem 'factory_girl_rails' > ? ? ? ?gem "ZenTest" > ? ? ? ?gem "autotest" > ? ? ? ?gem "autotest-rails" > ? ? ? ?gem "cucumber" > ? ? ? ?gem "launchy" > ? ? ? ?gem "gherkin" > ? ? ? ?gem "cucumber-rails" > ? ? ? ?gem "webrat" > ? ? ? ?gem "capybara" > ? ? ? ?gem "capybara-envjs" > ? ? ? ?gem 'selenium-client' > ? ? ? ?gem 'fakeweb' > ? ? ? ?gem 'vcr' > ? ? ? ?gem "httparty" > ? ? ? ?gem 'rpm_contrib' > ? ? ? ?gem 'newrelic_rpm' > ? ? ? ?gem 'fuubar' > ? ? ? ?gem 'ruby-debug' > end > > Here are the gem versions being used. ?I've tried to filter it to just > the ones I could see being relevant. > Using ZenTest (4.4.2) > Using autotest (4.4.6) > Using autotest-rails (4.1.0) > Using mocha (0.9.8) > Using bourne (1.0) > Using bundler (1.0.7) > Using term-ansicolor (1.0.5) > Using factory_girl (1.3.2) > Using rails (3.0.3) > Using factory_girl_rails (1.0) > Using rspec-core (2.3.1) > Using rspec-expectations (2.3.0) > Using rspec-mocks (2.3.0) > Using rspec (2.3.0) > Using rspec-instafail (0.1.5) > Using ruby-progressbar (0.0.9) > Using mongoid-rspec (1.3.2) > Using rspec-rails (2.3.1) > > I'm using ruby 1.8.7 REE > > I'm afraid I don't really know how autotest works > > I didn't seem to have this problem until recently, so I'm wondering if > a recent release requires me to change something that I missed. > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From wolfmanjm at gmail.com Mon Dec 27 23:39:40 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Mon, 27 Dec 2010 20:39:40 -0800 (PST) Subject: [rspec-users] rspec 2 helper spec problems Message-ID: <5843fbf7-28bb-4d9b-a63d-99cefeddca88@c13g2000prc.googlegroups.com> Hi, I have a working application_helper_spec.rb, and now I created a posts_helper_spec.rb in the spec/helpers directory. But it looks like rspec is not treating it as a helper spec, the helper returns null and mocks and stubs are not recognized, and the before is not being executed, and even my spec_helper.rb is not seeing it as a :type => :helper (full source in https://github.com/wolfmanjm/wolfmanblog_rails) Using rspec-rails 2.3.1 the spec is... require 'spec_helper' describe PostsHelper do before do @post= mock_model(Post) end describe '#num_comments with comments' do @post.stub("comments_size").and_return(10) helper.num_comments(@post).should == '10 comments' end describe '#num_comments with no comments' do @post.stub("comments_size").and_return(0) helper.num_comments(@post).should == 'no comments' end end > rspec spec/helpers/posts_helper_spec.rb /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `stub' for nil:NilClass (NoMethodError) from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/ posts_helper_spec.rb:10 from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in `module_eval' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in `subclass' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:118:in `describe' from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/ posts_helper_spec.rb:9 from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in `module_eval' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in `subclass' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:118:in `describe' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/extensions/object.rb:6:in `describe' from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/ posts_helper_spec.rb:3 from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in `load' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in `load_spec_files' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in `map' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in `load_spec_files' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/command_line.rb:18:in `run' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/runner.rb:55:in `run_in_process' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/runner.rb:46:in `run' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/runner.rb:10:in `autorun' from /opt/ruby-enterprise-1.8.7-2010.02/bin/rspec:19 From wolfmanjm at gmail.com Tue Dec 28 18:11:23 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Tue, 28 Dec 2010 15:11:23 -0800 (PST) Subject: [rspec-users] rspec 2 helper spec problems In-Reply-To: <5843fbf7-28bb-4d9b-a63d-99cefeddca88@c13g2000prc.googlegroups.com> References: <5843fbf7-28bb-4d9b-a63d-99cefeddca88@c13g2000prc.googlegroups.com> Message-ID: <54758248-f307-4b2d-8104-27a4b903fa77@29g2000prb.googlegroups.com> Never mind sorry for the noise :) Guess I shouldn't have been working so late at night ;) I left out the it block! On Dec 27, 8:39?pm, Jim Morris wrote: > Hi, I have a working application_helper_spec.rb, and now I created a > posts_helper_spec.rb in the spec/helpers directory. > > But it looks like rspec is not treating it as a helper spec, the > helper returns null and mocks and stubs are not recognized, and the > before is not being executed, and even my spec_helper.rb is not seeing > it as a :type => :helper > > (full source inhttps://github.com/wolfmanjm/wolfmanblog_rails) > Using rspec-rails 2.3.1 > > the spec is... > > require 'spec_helper' > > describe PostsHelper do > > ? before do > ? ? @post= mock_model(Post) > ? end > > ? describe '#num_comments with comments' do > ? ? @post.stub("comments_size").and_return(10) > ? ? helper.num_comments(@post).should == '10 comments' > ? end > > ? describe '#num_comments with no comments' do > ? ? @post.stub("comments_size").and_return(0) > ? ? helper.num_comments(@post).should == 'no comments' > ? end > end > > > rspec spec/helpers/posts_helper_spec.rb > > /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in > `method_missing': undefined method `stub' for nil:NilClass > (NoMethodError) > ? ? ? ? from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/ > posts_helper_spec.rb:10 > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in `module_eval' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in `subclass' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/example_group.rb:118:in `describe' > ? ? ? ? from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/ > posts_helper_spec.rb:9 > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in `module_eval' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in `subclass' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/example_group.rb:118:in `describe' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/extensions/object.rb:6:in `describe' > ? ? ? ? from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/ > posts_helper_spec.rb:3 > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in `load' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in > `load_spec_files' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in `map' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in > `load_spec_files' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/command_line.rb:18:in `run' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/runner.rb:55:in `run_in_process' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/runner.rb:46:in `run' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > rspec-core-2.3.1/lib/rspec/core/runner.rb:10:in `autorun' > ? ? ? ? from /opt/ruby-enterprise-1.8.7-2010.02/bin/rspec:19 > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From tiago.fernandez at gmail.com Tue Dec 28 16:01:04 2010 From: tiago.fernandez at gmail.com (Tiago Fernandez) Date: Tue, 28 Dec 2010 22:01:04 +0100 Subject: [rspec-users] RSpec2 issue with RCov Message-ID: Hello, I am experiencing an issue with RSpec2, while running RCov. In my Rakefile, I have a task defined like this: namespace :test do desc "Run all specs." RSpec::Core::RakeTask.new(:spec) do |t| t.pattern = 'spec/**/*_spec.rb' t.verbose = false end RSpec::Core::RakeTask.new(:coverage) do |t| t.rcov = true t.rcov_opts = %q[--exclude "spec"] t.verbose = true end end When running test:coverage, I get this: ./spec/foo_spec.rb:3: undefined method `describe' for main:Object (NoMethodError) from /Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516:in `load' from /Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516 from /usr/bin/rcov:19:in `load' from /usr/bin/rcov:19 rake aborted! ruby -S rcov -Ispec:lib --exclude "spec" "./spec/foo_spec.rb" failed Below my gem list: diff-lcs (1.1.2) rake (0.8.7) rcov (0.9.9) rspec (2.3.0) rspec-core (2.3.1) rspec-expectations (2.3.0) rspec-mocks (2.3.0) And here's the code: https://github.com/tiagofernandez/codekatas/tree/master/matchmaker Any idea? Thanks in advance. Tiago Fernandez -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Dec 28 20:34:18 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 28 Dec 2010 19:34:18 -0600 Subject: [rspec-users] RSpec2 issue with RCov In-Reply-To: References: Message-ID: On Tue, Dec 28, 2010 at 3:01 PM, Tiago Fernandez wrote: > Hello, > I am experiencing an issue with RSpec2, while running RCov.?In my Rakefile, > I have a task defined like this: > ?? ?namespace :test do > ?? ? ?desc "Run all specs." > ?? ? ?RSpec::Core::RakeTask.new(:spec) do |t| > ?? ? ? ?t.pattern = 'spec/**/*_spec.rb' > ?? ? ? ?t.verbose = false > ?? ? ?end > > ?? ? ?RSpec::Core::RakeTask.new(:coverage) do |t| > ?? ? ? ?t.rcov = true > ?? ? ? ?t.rcov_opts = ?%q[--exclude "spec"] > ?? ? ? ?t.verbose = true > ?? ? ?end > ?? ?end > When running test:coverage, I get this: > ?? ?./spec/foo_spec.rb:3: undefined method `describe' for main:Object > (NoMethodError) > ?? ? from /Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516:in `load' > ?? ? from /Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516 > ?? ? from /usr/bin/rcov:19:in `load' > ?? ? from /usr/bin/rcov:19 > ?? ?rake aborted! > ?? ?ruby -S rcov -Ispec:lib --exclude "spec" "./spec/foo_spec.rb" failed > Below my gem list: > ?? ?diff-lcs (1.1.2) > ?? ?rake (0.8.7) > ?? ?rcov (0.9.9) > ?? ?rspec (2.3.0) > ?? ?rspec-core (2.3.1) > ?? ?rspec-expectations (2.3.0) > ?? ?rspec-mocks (2.3.0) > And here's the code: > https://github.com/tiagofernandez/codekatas/tree/master/matchmaker > Any idea? require "rspec" :) > Thanks in advance. > Tiago Fernandez > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From shea at shealevy.com Wed Dec 29 00:49:49 2010 From: shea at shealevy.com (Shea Levy) Date: Tue, 28 Dec 2010 21:49:49 -0800 Subject: [rspec-users] BDD and Performance Message-ID: <463330ec358c4f5929156f933c8d07c9@shealevy.com> Hi all, What's the best way to implement performance enhancements from the outside-in? For example, if I'm working test-free and I know I'm going to be looking up my Shops by phone number often, I'll write a migration to make phone_number an index of the shops table. What feature(s) and spec(s) would I write to drive me to that migration? Cheers, Shea Levy -------------- next part -------------- An HTML attachment was scrubbed... URL: From shea at shealevy.com Wed Dec 29 01:01:12 2010 From: shea at shealevy.com (Shea Levy) Date: Tue, 28 Dec 2010 22:01:12 -0800 Subject: [rspec-users] BDD and Interacting With External Resources Message-ID: <6f3eb1edebc8d25421d7890e17a4819d@shealevy.com> Hi all, What's the best way to handle features which rely on an external API in a behaviour-driven way? Suppose I have an app which manages online ordering from several independent stores, with a cut taken from each purchase, and I want to add a feature whereby orders made by phone that were facilitated by the website can be tracked so that the cut can be taken. I discover that I can use Twilio to generate a phone number for each store and set up a controller to generate Twiml that results in callers to that phone number hearing a recording warning them that their call will be recorded then redirecting them to the store's real number, with a URL of the recording being sent back to the controller after hangup. How would I drive out the desired behaviour (which can be seen as either "the app generates the proper twiml and stores the relevant call data" or "the app routes and records calls" depending on your perspective) from the outside-in? I don't know how to write a Cucumber step definition that ensures that a phone rings! Cheers, Shea -------------- next part -------------- An HTML attachment was scrubbed... URL: From shea at shealevy.com Wed Dec 29 01:14:44 2010 From: shea at shealevy.com (Shea Levy) Date: Tue, 28 Dec 2010 22:14:44 -0800 Subject: [rspec-users] Webrat or RSpec and Table Headers Message-ID: <516836757b4ab018a3695dc7a6d2a5ba@shealevy.com> Hi all, Suppose I have a table that lists all of my products, that includes a a somewhere in the first , and each product has its data held within a . After updating a product's description, I want to write something like: within "tr#category#{category.id}" do under_header "Description" do |scope| scope.contains "New Description" end end in a Cucumber/webrat feature definition or response.should have_tag("tr#category1") do under_header "Description" do text => "Howdy end end in an RSpec spec. Is there anything like this available, any way to search within a specific table column by specifying the header? Cheers, Shea -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonathan at parkerhill.com Wed Dec 29 01:29:05 2010 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 29 Dec 2010 01:29:05 -0500 Subject: [rspec-users] Webrat or RSpec and Table Headers In-Reply-To: <516836757b4ab018a3695dc7a6d2a5ba@shealevy.com> References: <516836757b4ab018a3695dc7a6d2a5ba@shealevy.com> Message-ID: <9250A942-1C83-428E-9347-1FD7737A24B7@parkerhill.com> On Dec 29, 2010, at 1:14 AM, Shea Levy wrote: > Hi all, > > Suppose I have a table that lists all of my products, that includes a a Description somewhere in the first , and each product has its data held within a . After updating a product's description, I want to write something like: > > within "tr#category#{category.id}" do > under_header "Description" do |scope| > scope.contains "New Description" > end > end > > in a Cucumber/webrat feature definition or > > not exactly what you're asking but I do this: Then I should see "New description" on the row containing "Widget Xyz" Then /^(?:|I )should see "([^"]*)" on the row containing "([^"]*)"(?: within "([^"]*)")?$/ do |text1, text, scope| selector = ".//td[contains(.,'#{text}')]//.." with_scope(scope) do within(:xpath, selector) do Then %{I should see "#{text1}"} end end end > response.should have_tag("tr#category1") do > under_header "Description" do > text => "Howdy > end > end > > in an RSpec spec. Is there anything like this available, any way to search within a specific table column by specifying the header? > > Cheers, > Shea > > _______________________________________________ > 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 matt at mattwynne.net Wed Dec 29 05:18:21 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 29 Dec 2010 10:18:21 +0000 Subject: [rspec-users] BDD and Performance In-Reply-To: <463330ec358c4f5929156f933c8d07c9@shealevy.com> References: <463330ec358c4f5929156f933c8d07c9@shealevy.com> Message-ID: <161D2A1A-C96E-4F9D-8C03-00BA80DD2BE4@mattwynne.net> On 29 Dec 2010, at 05:49, Shea Levy wrote: > Hi all, > > What's the best way to implement performance enhancements from the outside-in? For example, if I'm working test-free and I know I'm going to be looking up my Shops by phone number often, I'll write a migration to make phone_number an index of the shops table. What feature(s) and spec(s) would I write to drive me to that migration? > > Cheers, > Shea Levy > I try to think of an example, from the user's perspective, that describes a goal I'm trying to meet. So in the case of the shop, I might say: Given there are 10,000 Shops in the system When I look up a Shop by it's phone number Then I should see the result within 0.2 seconds Just as with business rules, forcing yourself to describe the goal in such concrete terms can trigger some very interesting and useful conversations. Obviously you will find that these kinds of tests behave much less deterministically than business rule tests, so it's useful if you can make your development and test environments as homogenous as possible. You can also help smooth this out by making the scenario work with averages instead: Given there are 10,000 Shops in the system When I perform 100 searches for a Shop by phone number Then on average, I should see the result within 0.2 seconds These sorts of tests are also much slower than business rule tests, because they tend to need lots of data and to take several samples to get their average. It's worth tagging them to exclude them from your check-in build run and running them in a nightly build instead. Hope that helps. cheers, Matt matt at mattwynne.net 07974 430184 -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Dec 29 05:21:50 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 29 Dec 2010 10:21:50 +0000 Subject: [rspec-users] Webrat or RSpec and Table Headers In-Reply-To: <516836757b4ab018a3695dc7a6d2a5ba@shealevy.com> References: <516836757b4ab018a3695dc7a6d2a5ba@shealevy.com> Message-ID: On 29 Dec 2010, at 06:14, Shea Levy wrote: > Hi all, > > Suppose I have a table that lists all of my products, that includes a a Description somewhere in the first , and each product has its data held within a . After updating a product's description, I want to write something like: > > within "tr#category#{category.id}" do > under_header "Description" do |scope| > scope.contains "New Description" > end > end > > in a Cucumber/webrat feature definition or > > response.should have_tag("tr#category1") do > under_header "Description" do > text => "Howdy > end > end > > in an RSpec spec. Is there anything like this available, any way to search within a specific table column by specifying the header? > > Cheers, > Shea > > It's worth looking at the tableish method that cucumber-rails provides. You can use it to turn a HTML table element into an array. You can even diff it against a Cucumber::Ast::Table object. cheers, Matt matt at mattwynne.net 07974 430184 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Dec 29 10:01:52 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Dec 2010 09:01:52 -0600 Subject: [rspec-users] BDD and Interacting With External Resources In-Reply-To: <6f3eb1edebc8d25421d7890e17a4819d@shealevy.com> References: <6f3eb1edebc8d25421d7890e17a4819d@shealevy.com> Message-ID: <0491144F-06F3-42C0-A6EB-DD3166AF4C36@gmail.com> On Dec 29, 2010, at 12:01 AM, Shea Levy wrote: > Hi all, > > What's the best way to handle features which rely on an external API in a behaviour-driven way? Suppose I have an app which manages online ordering from several independent stores, with a cut taken from each purchase, and I want to add a feature whereby orders made by phone that were facilitated by the website can be tracked so that the cut can be taken. I discover that I can use Twilio to generate a phone number for each store and set up a controller to generate Twiml that results in callers to that phone number hearing a recording warning them that their call will be recorded then redirecting them to the store's real number, with a URL of the recording being sent back to the controller after hangup. How would I drive out the desired behaviour (which can be seen as either "the app generates the proper twiml and stores the relevant call data" or "the app routes and records calls" depending on your perspective) from the outside-in? I don't know how to write a Cucumber step definition that ensures that a phone rings! > The behavior of the app is to set up the Twimi correctly, so I'd specify that with an automation tool like RSpec or Cucumber. You can do a manual system test to prove the phone rings. I'm sure there are other opinions. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Dec 29 10:14:47 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 29 Dec 2010 15:14:47 +0000 Subject: [rspec-users] Webrat or RSpec and Table Headers In-Reply-To: References: <516836757b4ab018a3695dc7a6d2a5ba@shealevy.com> Message-ID: On 29 Dec 2010, at 10:21, Matt Wynne wrote: > > On 29 Dec 2010, at 06:14, Shea Levy wrote: > >> Hi all, >> >> Suppose I have a table that lists all of my products, that includes a a Description somewhere in the first , and each product has its data held within a . After updating a product's description, I want to write something like: >> >> within "tr#category#{category.id}" do >> under_header "Description" do |scope| >> scope.contains "New Description" >> end >> end >> >> in a Cucumber/webrat feature definition or >> >> response.should have_tag("tr#category1") do >> under_header "Description" do >> text => "Howdy >> end >> end >> >> in an RSpec spec. Is there anything like this available, any way to search within a specific table column by specifying the header? >> >> Cheers, >> Shea >> >> > > It's worth looking at the tableish method that cucumber-rails provides. You can use it to turn a HTML table element into an array. You can even diff it against a Cucumber::Ast::Table object. Oops, just realised you're posting to the RSpec, not the Cucumber list. My mistake. cheers, Matt matt at mattwynne.net 07974 430184 -------------- next part -------------- An HTML attachment was scrubbed... URL: From shea at shealevy.com Wed Dec 29 22:43:18 2010 From: shea at shealevy.com (Shea Levy) Date: Wed, 29 Dec 2010 19:43:18 -0800 Subject: [rspec-users] Specing Ajaxy Views Message-ID: <755efa7e2154182fcf22bc569c73b840@shealevy.com> Hi all, I am working on a feature to allow administrators of an online store to rearrange the order in which their product categories show up on the site. I want to use a simple implementation of sortable_lists (madrobby.github.com/scriptaculous/sortable-lists-demo/) to allow the administrators to just drag and drop the categories into the desired order. I have already written a cucumber feature that I hope expresses the desired function (does anyone know if Capybara+Selenium's drag_to method will work with sortable_lists?), and have gotten to red on the Cucumber level, but I'm at a loss as to how to continue. The Cucumber scenario goes to the page, drags each category to the desired spot, then reloads the page to check that the categories are in the right order. The When (dragging each category) passes (though the dragging doesn't actually do anything, since the sortable_list is not set up yet), but the Then (checking the categories) fails because nothing was actually changed. I think my next step should be a view spec, but I'm not sure exactly how to proceed. I think what I want to check on the view level is a) that clicking and dragging updates the document and b) that the proper AJAX request is sent to the controller, but I don't know how to do either. Once I got those working, the next step (specing the controller which responds to the request) seems easier, but I don't know how to get past this part. Also, it occurs to me that, since I didn't write the sortable_list code myself, maybe I should view it as an external API and my view spec should just check that the view is set up properly to interact with the API. Does that make more sense? How would I do that? In general, if I want to add Javascript functionality to a view, should I treat the scripting itself as a separate component to be "speced" with something like JsUnit as part of the inner circle of the BDD cycle, along with specing views, controllers, and models, or is there ever a time when Javascript specs should be considered the responsibility of the view spec? Cheers, Shea -------------- next part -------------- An HTML attachment was scrubbed... URL: From bnferguson at gmail.com Wed Dec 29 15:07:05 2010 From: bnferguson at gmail.com (Brandon Ferguson) Date: Wed, 29 Dec 2010 12:07:05 -0800 (PST) Subject: [rspec-users] Problems with rspec 1.3.1 and Ruby 1.9.2 Message-ID: Hello, Recently was driving a spike on moving our app to Ruby 1.9 and ran into some problems with out test suite. I could be totally off here as I couldn't find much reference to rspec 1.3's ruby 1.9 compatibility. The error I'm getting is: NoMethodError in 'BusinessesController POST clear as a superuser in non-production environments removes notifications if found in params' undefined method `carrier_accounts' for # /Users/bnferguson/.rvm/gems/ruby-1.9.2-p0 at mobi/gems/activerecord-2.3.9/ lib/active_record/attribute_methods.rb:260:in `method_missing' spec/controllers/businesses_controller_spec.rb:110:in `block (5 levels) in ' and the related code for that would be: https://gist.github.com/5f1f968b93e028aaf210 (line 20 corresponding to 110) The gem list, versions, full error output, etc are here: https://gist.github.com/758982 I'm getting something like ~1700 specs failing mostly from this and "can't modify frozen object". Seems like this error is happening on a lot of stub_model calls and mock_model calls. It's baffling. The can't modify frozen object doesn't even give a stack trace. Any clues? Such strange breaks. From lists at ruby-forum.com Fri Dec 31 14:48:51 2010 From: lists at ruby-forum.com (Kevin Lochner) Date: Fri, 31 Dec 2010 20:48:51 +0100 Subject: [rspec-users] my helper stubs aren't working (rspec2, rails3) Message-ID: My helper tests broke when I upgraded to rails3/rspec2. I don't seem to be able to stub out methods in my helper tests. Anyone know what's going on here? #users_helper_spec.rb describe UsersHelper do describe "the helper" do it "should stub" do helper.stub(:foobar_method).and_return(666) helper.foobar_method.should == 666 end end end gives me: 1) UsersHelper the helper should stub Failure/Error: helper.foobar_method.should == 666 undefined method `foobar_method' for # # ./spec/helpers/users_helper_spec.rb:5 -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Dec 31 19:36:30 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 31 Dec 2010 18:36:30 -0600 Subject: [rspec-users] my helper stubs aren't working (rspec2, rails3) In-Reply-To: References: Message-ID: On Dec 31, 2010, at 1:48 PM, Kevin Lochner wrote: > My helper tests broke when I upgraded to rails3/rspec2. I don't seem to > be able to stub out methods in my helper tests. > > Anyone know what's going on here? > > #users_helper_spec.rb > describe UsersHelper do > describe "the helper" do > it "should stub" do > helper.stub(:foobar_method).and_return(666) > helper.foobar_method.should == 666 > end > end > end > > gives me: > > 1) UsersHelper the helper should stub > Failure/Error: helper.foobar_method.should == 666 > undefined method `foobar_method' for # > # ./spec/helpers/users_helper_spec.rb:5 I copied that code into a new Rails 3/RSpec 2 app and the example passes without error. Can you post your Gemfile and spec/spec_helper.rb files? I'm guessing there's a configuration problem of some sort. Cheers, David From klochner at gmail.com Thu Dec 30 16:02:52 2010 From: klochner at gmail.com (klochner) Date: Thu, 30 Dec 2010 13:02:52 -0800 (PST) Subject: [rspec-users] helper spec problems Message-ID: <8cb168ff-24df-4d24-9bfd-ccf6a3560af3@z19g2000yqb.googlegroups.com> Using: rspec 2.3 with rails3 I'm unable to stub out the current_user method in my helper, not sure what I'm doing wrong: describe "link_to_current_user, When logged in" do it "should link to the given user" do helper.stub!(:current_user).and_return(@user) helper.should_receive(:user_profile_path).at_least(:once).and_return('/ user/profiles/1') helper.link_to_current_user.should have_selector("a[href='/user/ profiles/1']") end end 7) UsersHelper link_to_current_user, When logged in should link to the given user Failure/Error: helper.link_to_current_user.should have_selector("a[href='/user/profiles/1']") undefined local variable or method `current_user' for # # ./app/helpers/users_helper.rb:84:in `link_to_current_user' # ./spec/helpers/users_helper_spec.rb:89 and lines 83/84 from users_helper.rb: def link_to_current_user(options={}) if current_user From ks at cissor.com Thu Dec 30 17:37:42 2010 From: ks at cissor.com (Kurt) Date: Thu, 30 Dec 2010 14:37:42 -0800 (PST) Subject: [rspec-users] can't get RSpec 2.3.1 to work in Rails 3.0.3 - uninitialized constant Rails (NameError) Message-ID: <444335fc-0e31-47e6-93f2-35684f3cc34c@r16g2000prh.googlegroups.com> I just installed rspec-rails 2.3.1 gem into a new Rails 3.0.3 app, ran the rspec:install generator, but the system doesn't see any other RSpec generators (like rspec_controller), and the server will no longer start. Both report this error: /.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-rails-2.3.1/lib/rspec- rails.rb:3:in `': uninitialized constant Rails (NameError) Here's a clip of the file referenced by the error: module RSpec module Rails class Railtie < ::Rails::Railtie I've used RSpec 2.0 and 2.1 with Rails 3 before without problems. Any suggestions greatly appreciated..