From zhiqiang.lei at gmail.com Fri Oct 1 07:11:27 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Fri, 1 Oct 2010 19:11:27 +0800 Subject: [rspec-users] Strange return value Message-ID: <306913FD-051F-4FDB-9164-8C7498CB315C@gmail.com> Dear All, I meet a strange issue when I test my Rack Middleware. Could anyone help me to point the error out? Thanks. This is the code. class EIOUAuthorization def initialize(app) @app = app end def call(env) request = Rack::Request.new(env) path_strings = request.path_info.split('/', 4) if path_strings[1] == 'people' user = User.get(path_strings[2]) return not_found if user.nil? digest_authentication(user).call(env) else @app.call(env) end end #private def not_found [404, {'Content-Type' => 'text/plain', 'Content-Length' => '0'}, []] end def digest_authentication(user) auth = Rack::Auth::Digest::MD5.new(@app, user.realm) do |email| {user.person.email => user.ha1}[email] end auth.passwords_hashed = true auth.opaque = 'opaque-for-' + user.realm auth end end And this is my test case. describe '#call' do it 'should call digest_authentication method with id when get /people/{person-id}' do app.should_receive(:digest_authentication).with(@user).once get "/people/#{@person.id}" end end describe '#digest_authentication' do it 'should respond to call' do app.digest_authentication(@user).should respond_to(:call) end end From the result we can see the #digest_authentication is called, and the result should respond to call. But the fact is that it return a nil object in the code. F. 1) NoMethodError in 'EIOUAuthorization#call should call digest_authentication method with id when get /people/{person-id}' undefined method `call' for nil:NilClass ./spec/../main.rb:21:in `call' /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/mock_session.rb:30:in `request' /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/test.rb:207:in `process_request' /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/test.rb:57:in `get' ./spec/eiou_authorization.rb:34: Finished in 0.024267 seconds 2 examples, 1 failure Best regards, Lei, Zhi-Qiang From dchelimsky at gmail.com Fri Oct 1 08:48:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 1 Oct 2010 07:48:36 -0500 Subject: [rspec-users] Strange return value In-Reply-To: <306913FD-051F-4FDB-9164-8C7498CB315C@gmail.com> References: <306913FD-051F-4FDB-9164-8C7498CB315C@gmail.com> Message-ID: <6D978D02-04E8-4F09-8608-791D8AB20955@gmail.com> On Oct 1, 2010, at 6:11 AM, Zhi-Qiang Lei wrote: > Dear All, > > I meet a strange issue when I test my Rack Middleware. Could anyone help me to point the error out? Thanks. > > This is the code. > > class EIOUAuthorization > def initialize(app) > @app = app > end > def call(env) > request = Rack::Request.new(env) > path_strings = request.path_info.split('/', 4) > if path_strings[1] == 'people' > user = User.get(path_strings[2]) > return not_found if user.nil? > digest_authentication(user).call(env) > else > @app.call(env) > end > end > #private > def not_found > [404, {'Content-Type' => 'text/plain', 'Content-Length' => '0'}, []] > end > def digest_authentication(user) > auth = Rack::Auth::Digest::MD5.new(@app, user.realm) do |email| > {user.person.email => user.ha1}[email] > end > auth.passwords_hashed = true > auth.opaque = 'opaque-for-' + user.realm > auth > end > end > > And this is my test case. > > describe '#call' do > it 'should call digest_authentication method with id when get /people/{person-id}' do > app.should_receive(:digest_authentication).with(@user).once > get "/people/#{@person.id}" > end > end > > describe '#digest_authentication' do > it 'should respond to call' do > app.digest_authentication(@user).should respond_to(:call) > end > end > >> From the result we can see the #digest_authentication is called, and the result should respond to call. But the fact is that it return a nil object in the code. > > F. > > 1) > NoMethodError in 'EIOUAuthorization#call should call digest_authentication method with id when get /people/{person-id}' > undefined method `call' for nil:NilClass > ./spec/../main.rb:21:in `call' > /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/mock_session.rb:30:in `request' > /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/test.rb:207:in `process_request' > /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/test.rb:57:in `get' > ./spec/eiou_authorization.rb:34: > > Finished in 0.024267 seconds > > 2 examples, 1 failure How are you initializing the app object? From zhiqiang.lei at gmail.com Sat Oct 2 00:50:33 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Sat, 2 Oct 2010 12:50:33 +0800 Subject: [rspec-users] Strange return value In-Reply-To: <6D978D02-04E8-4F09-8608-791D8AB20955@gmail.com> References: <306913FD-051F-4FDB-9164-8C7498CB315C@gmail.com> <6D978D02-04E8-4F09-8608-791D8AB20955@gmail.com> Message-ID: On Oct 1, 2010, at 8:48 PM, David Chelimsky wrote: > On Oct 1, 2010, at 6:11 AM, Zhi-Qiang Lei wrote: > >> Dear All, >> >> I meet a strange issue when I test my Rack Middleware. Could anyone help me to point the error out? Thanks. >> >> This is the code. >> >> class EIOUAuthorization >> def initialize(app) >> @app = app >> end >> def call(env) >> request = Rack::Request.new(env) >> path_strings = request.path_info.split('/', 4) >> if path_strings[1] == 'people' >> user = User.get(path_strings[2]) >> return not_found if user.nil? >> digest_authentication(user).call(env) >> else >> @app.call(env) >> end >> end >> #private >> def not_found >> [404, {'Content-Type' => 'text/plain', 'Content-Length' => '0'}, []] >> end >> def digest_authentication(user) >> auth = Rack::Auth::Digest::MD5.new(@app, user.realm) do |email| >> {user.person.email => user.ha1}[email] >> end >> auth.passwords_hashed = true >> auth.opaque = 'opaque-for-' + user.realm >> auth >> end >> end >> >> And this is my test case. >> >> describe '#call' do >> it 'should call digest_authentication method with id when get /people/{person-id}' do >> app.should_receive(:digest_authentication).with(@user).once >> get "/people/#{@person.id}" >> end >> end >> >> describe '#digest_authentication' do >> it 'should respond to call' do >> app.digest_authentication(@user).should respond_to(:call) >> end >> end >> >>> From the result we can see the #digest_authentication is called, and the result should respond to call. But the fact is that it return a nil object in the code. >> >> F. >> >> 1) >> NoMethodError in 'EIOUAuthorization#call should call digest_authentication method with id when get /people/{person-id}' >> undefined method `call' for nil:NilClass >> ./spec/../main.rb:21:in `call' >> /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/mock_session.rb:30:in `request' >> /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/test.rb:207:in `process_request' >> /Library/Ruby/Gems/1.8/gems/rack-test-0.5.4/lib/rack/test.rb:57:in `get' >> ./spec/eiou_authorization.rb:34: >> >> Finished in 0.024267 seconds >> >> 2 examples, 1 failure > > > How are you initializing the app object? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users As follow. $:.unshift File.join(File.dirname(__FILE__), '..') require 'main' require 'rack/test' describe EIOUAuthorization do include Rack::Test::Methods before :all do @person = Person.create(:email => 'zhiqiang.lei at gmail.com') @user = User.new @user.name = 'levin' @user.person = @person @user.password = 'password' @user.save end def unprotected_app lambda do |env| [200, {'Content-Type' => 'text/plain'}, ['Hello World!']] end end def protected_app @protected_app ||= EIOUAuthorization.new(unprotected_app) end alias :app :protected_app describe '#call' do it 'should call digest_authentication method with id when get /people/{person-id}' do app.should_receive(:digest_authentication).with(@user).once get "/people/#{@person.id}" end end describe '#digest_authentication' do it 'should respond to call' do app.digest_authentication(@user).should respond_to(:call) end end after :all do Person.all.destroy User.all.destroy end end From schlamp at gmx.de Sat Oct 2 15:27:22 2010 From: schlamp at gmx.de (Kai Schlamp) Date: Sat, 02 Oct 2010 21:27:22 +0200 Subject: [rspec-users] response.should have_text leads to undefined method `has_text?' Message-ID: <20101002192722.25040@gmx.net> A big hello. I would like to test a controller that directly renders some JSON output (by using "render :json => @entity_names"). For that task I tried in my spec file "response.should have_text('["enim", "enita"]')". Unfortunately I always get that error: Failure/Error: response.should have_text('["enim", "enita"]') undefined method `has_text?' for " ":String (Also a "response.body.should have_text('["enim", "enita"]')as someone suggested on Stackoverflow did not solve the problem.) Do I miss some gem that provides that method? Here my Gemfile: source 'http://rubygems.org' gem 'rails', '>= 3.0.0' gem 'mysql2' gem 'mongrel' gem 'devise' gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => 'rails3' gem 'thinking-sphinx', :git => 'git://github.com/freelancing-god/thinking-sphinx.git', :branch => 'rails3', :require => 'thinking_sphinx' group :test, :development do gem 'rspec-rails', '>= 2.0.0.beta.19' gem 'steak', :git => 'git://github.com/cavalle/steak.git' gem 'webrat' gem 'capybara' gem 'capybara-envjs' gem 'shoulda' gem 'launchy' gem 'autotest' gem 'autotest-rails' gem 'test_notifier' gem 'rails3-generators' gem 'factory_girl_rails' gem 'populator' gem 'faker' gem 'random_data' gem 'database_cleaner', :git => 'git://github.com/bmabey/database_cleaner.git' gem 'delorean' end Best regards, Kai -- GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl From dchelimsky at gmail.com Sat Oct 2 16:04:04 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 2 Oct 2010 15:04:04 -0500 Subject: [rspec-users] response.should have_text leads to undefined method `has_text?' In-Reply-To: <20101002192722.25040@gmx.net> References: <20101002192722.25040@gmx.net> Message-ID: On Oct 2, 2010, at 2:27 PM, Kai Schlamp wrote: > A big hello. > > I would like to test a controller that directly renders some JSON output (by using "render :json => @entity_names"). For that task I tried in my spec file "response.should have_text('["enim", "enita"]')". Unfortunately I always get that error: > Failure/Error: response.should have_text('["enim", "enita"]') > undefined method `has_text?' for " ":String have_text is not supported in rspec-2. For JSON, I like to deserialize the output and match against the decoded JSON: json = ActiveSupport::JSON::decode(response.body) json.should eq(%w[enim enita]) Then you could wrap that in a matcher: RSpec::Matchers.define :be_json do |expected_json| match do |response| json = ActiveSupport::JSON::decode(response.body) json.should == expected_json end end response.should be_json(%w[enim enita]) HTH, David > > (Also a "response.body.should have_text('["enim", "enita"]')as someone suggested on Stackoverflow did not solve the problem.) > > Do I miss some gem that provides that method? Here my Gemfile: > > source 'http://rubygems.org' > > gem 'rails', '>= 3.0.0' > gem 'mysql2' > gem 'mongrel' > gem 'devise' > gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => 'rails3' > gem 'thinking-sphinx', :git => 'git://github.com/freelancing-god/thinking-sphinx.git', :branch => 'rails3', :require => 'thinking_sphinx' > > group :test, :development do > gem 'rspec-rails', '>= 2.0.0.beta.19' > gem 'steak', :git => 'git://github.com/cavalle/steak.git' > gem 'webrat' > gem 'capybara' > gem 'capybara-envjs' > gem 'shoulda' > gem 'launchy' > gem 'autotest' > gem 'autotest-rails' > gem 'test_notifier' > gem 'rails3-generators' > gem 'factory_girl_rails' > gem 'populator' > gem 'faker' > gem 'random_data' > gem 'database_cleaner', :git => 'git://github.com/bmabey/database_cleaner.git' > gem 'delorean' > end > > Best regards, > Kai > -- > GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit > gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Oct 3 18:41:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 3 Oct 2010 17:41:53 -0500 Subject: [rspec-users] rspec-1.3.1.rc and rspec-rails-1.3.3.rc are released! Message-ID: <30B11EBC-6901-4CB3-8F4C-CAEAF032B8F1@gmail.com> rspec-1.3.1.rc and rspec-rails-1.3.3.rc are released! These are release candidate gems for updates 1.x series, including some bug fixes and deprecation warnings for functionality that will be removed in rspec-2. Barring unexpected complications, I'll release final versions of these gems within the next week. Cheers, David =================================================================== rspec-1.3.1 (rc) * enhancements * Array =~ matcher works with subclasses of Array (Matthew Peychich & Pat Maddox) * config.suppress_deprecation_warnings! * bug fixes * QuitBacktraceTweaker no longer eats all paths with 'lib' (Tim Harper - #912) * Fix delegation of stubbed values on superclass class-level methods. (Scott Taylor - #496 - #957) * Fix pending to work with ruby-1.9 * deprecations * share_as (will be removed from rspec-core-2.0) * simple_matcher (will be removed from rspec-core-2.0) =================================================================== rspec-rails-1.3.3 (rc) * enhancements * replace use of 'returning' with 'tap' (to quite rails-2.3.9 deprecation warnings) * bug fixes * support message expectation on template.render with locals (Sergey Nebolsin). Closes #941. * helper instance variable no longer persists across examples (alex rothenberg). Closes #627. * mock_model stubs marked_for_destruction? (returns false). =================================================================== From lists at ruby-forum.com Sun Oct 3 21:24:43 2010 From: lists at ruby-forum.com (Will Marshall) Date: Mon, 4 Oct 2010 03:24:43 +0200 Subject: [rspec-users] using rcov with rspec2 In-Reply-To: References: Message-ID: <4fc7756d6370ef74abcba875525a2315@ruby-forum.com> > The error i get is this: > > `require': no such file to load -- spec_helper (LoadError) The only solution I have found for this is to revert from rspec-rails beta.22 to rspec-rails beta.20 -- Posted via http://www.ruby-forum.com/. From jan at limpens.com Sun Oct 3 23:32:51 2010 From: jan at limpens.com (Jan Limpens) Date: Mon, 4 Oct 2010 00:32:51 -0300 Subject: [rspec-users] undefined method `mock' for # Hekko, what does the following mean? 1) PortfolioItemsController should render index Failure/Error: @portfolio = mock_model(Portfolio) undefined method `mock' for # # /Users/jan/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/actionpack-3.0.0/lib/action_dispatch/testing/assertions/routing.rb:177:in `method_missing' # /Users/jan/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-rails-2.0.0.beta.22/lib/rspec/rails/mocks.rb:71:in `mock_model' # ./spec/controllers/portfolio_items_controller_spec.rb:7:in `block (2 levels) in ' This is using mongoid, with rails 3 require 'spec_helper' describe PortfolioItemsController do render_views before(:all) do @portfolio = mock_model(Portfolio) #dies here @item = mock_model(PortfolioItem) @items = [@item, mock_model(PortfolioItem)] PortfolioItem.stub!(:find).and_return(@item) PortfolioItem.stub!(:all).and_return(@items) @portfolio.stub!(:items).and_return(@items) end it "should render index" do response.should be_success end end #routes.rb resources :portfolios do resources :portfolio_items do resources :images end end class Portfolio include Mongoid::Document validates_presence_of :title field :title, :type => String embed_many :items, :class_name => PortfolioItem.name end class PortfolioItem include Mongoid::Document embedded_in :portfolio, :inverse_of => :items field(:title) field(:description) field(:date) embed_many(:images) validates_presence_of :title, :date end Any idea, what I am doing wrong here? On another note, I think be_success does not exist anymore, right? -- Jan -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Oct 5 00:47:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Oct 2010 23:47:22 -0500 Subject: [rspec-users] rspec-2.0.0.rc is released Message-ID: <4DD28857-3452-4CB7-BC1F-444A68C1E32D@gmail.com> rspec-2.0.0.rc is released! See http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/ for links to all sorts of documentation on rspec-2. Plan is to release rspec-2.0.0 (final) within the next week, so please install, upgrade, etc, and report issues to: http://github.com/rspec/rspec-core/issues http://github.com/rspec/rspec-expectations/issues http://github.com/rspec/rspec-mocks/issues http://github.com/rspec/rspec-rails/issues Many thinks to all of the contributors who got us here! ================================================================== ### rspec-core-2.0.0.rc / 2010-10-05 [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0.beta.22...v2.0.0.rc) * Enhancements * implicitly require unknown formatters so you don't have to require the file explicitly on the commmand line (Michael Grosser) * add --out/-o option to assign output target * added fail_fast configuration option to abort on first failure * support a Hash subject (its([:key]) { should == value }) (Josep M. Bach) * Bug fixes * Explicitly require rspec version to fix broken rdoc task (Hans de Graaff) * Ignore backtrace lines that come from other languages, like Java or Javascript (Charles Lowell) * Rake task now does what is expected when setting (or not setting) fail_on_error and verbose * Fix bug in which before/after(:all) hooks were running on excluded nested groups (Myron Marston) * Fix before(:all) error handling so that it fails examples in nested groups, too (Myron Marston) ================================================================== ### rspec-expectations-2.0.0.rc / 2010-10-05 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.22...v2.0.0.rc) * Enhancements * require 'rspec/expectations' in a T::U or MiniUnit suite (Josep M. Bach) * Bug fixes * change by 0 passes/fails correctly (Len Smith) * Add description to satisfy matcher ================================================================== ### rspec-mocks-2.0.0.rc / 2010-10-05 [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0.rc) * Enhancements * support passing a block to an expecttation block (Nicolas Braem) * obj.should_receive(:msg) {|&block| ... } * Bug fixes * Fix YAML serialization of stub (Myron Marston) * Fix rdoc rake task (Hans de Graaff) ================================================================== ### rspec-rails-2.0.0.rc / 2010-10-05 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.0.0.beta.22...v2.0.0.rc) * Enhancements * add --webrat-matchers flag to scaffold generator (for view specs) * separate ActiveModel and ActiveRecord APIs in mock_model and stub_model * ControllerExampleGroup uses controller as the implicit subject by default (Paul Rosania) -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom at experthuman.com Tue Oct 5 03:32:13 2010 From: tom at experthuman.com (Tom Stuart) Date: Tue, 5 Oct 2010 08:32:13 +0100 Subject: [rspec-users] rspec-1.3.1.rc and rspec-rails-1.3.3.rc are released! In-Reply-To: <30B11EBC-6901-4CB3-8F4C-CAEAF032B8F1@gmail.com> References: <30B11EBC-6901-4CB3-8F4C-CAEAF032B8F1@gmail.com> Message-ID: Hi David, On 3 Oct 2010, at 23:41, David Chelimsky wrote: > These are release candidate gems for updates 1.x series, including some bug fixes and deprecation warnings for functionality that will be removed in rspec-2. I'm having to maintain a fork of RSpec just so that I can revert the commit which caused the breakage in https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/1009. What are the chances of getting the failing example from that ticket into 1.3.1, along with either a reversion of the offending commit or (much better) an actual fix? To me this is a significant compatibility issue since it used to work in RSpec 1.2.9 and still does work in RSpec 2. I just don't understand enough about how this part of RSpec works to do a proper fix myself, but from a selfish perspective a revert of the bad commit is better than no fix at all. Cheers, -Tom From nathanvda at gmail.com Tue Oct 5 07:20:41 2010 From: nathanvda at gmail.com (nathanvda) Date: Tue, 5 Oct 2010 04:20:41 -0700 (PDT) Subject: [rspec-users] using rcov with rspec2 In-Reply-To: <4fc7756d6370ef74abcba875525a2315@ruby-forum.com> References: <4fc7756d6370ef74abcba875525a2315@ruby-forum.com> Message-ID: <28b369ea-226b-4abf-94ca-78ee3a43709a@k10g2000yqa.googlegroups.com> I hoped the new rspec2.0.0.rc would fix it, but it doesn't. I hope anybody can shed any light on this? On Oct 4, 3:24?am, Will Marshall wrote: > > The error i get is this: > > > `require': no such file to load -- spec_helper (LoadError) > > The only solution I have found for this is to revert from rspec-rails > beta.22 to rspec-rails beta.20 > -- > Posted viahttp://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Oct 5 08:28:32 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Oct 2010 07:28:32 -0500 Subject: [rspec-users] using rcov with rspec2 In-Reply-To: <28b369ea-226b-4abf-94ca-78ee3a43709a@k10g2000yqa.googlegroups.com> References: <4fc7756d6370ef74abcba875525a2315@ruby-forum.com> <28b369ea-226b-4abf-94ca-78ee3a43709a@k10g2000yqa.googlegroups.com> Message-ID: On Tue, Oct 5, 2010 at 6:20 AM, nathanvda wrote: > On Oct 4, 3:24?am, Will Marshall wrote: >> > The error i get is this: >> >> > `require': no such file to load -- spec_helper (LoadError) >> >> The only solution I have found for this is to revert from rspec-rails >> beta.22 to rspec-rails beta.20 Please post replies inline or at the bottom (I moved yours from the top). > I hoped the new rspec2.0.0.rc would fix it, but it doesn't. > > I hope anybody can shed any light on this? I'll need more information as rcov + rspec-2.0.0.rc is working just fine for me. Please report this to http://github.com/rspec/rspec-core/issues and include OS, ruby version, and the full backtrace you are seeing. From paulyoder at gmail.com Sat Oct 2 15:51:11 2010 From: paulyoder at gmail.com (Paul Yoder) Date: Sat, 2 Oct 2010 14:51:11 -0500 Subject: [rspec-users] Routes are not available in RSpec integration test Message-ID: My RSpec integration tests do not seem to have access to the rails routes methods. Here's a link to my more descriptive question on stack overflow: http://stackoverflow.com/questions/3847102/routes-are-not-available-in-rspec-integration-test Does anyone know how to fix this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Oct 5 08:47:00 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Oct 2010 07:47:00 -0500 Subject: [rspec-users] response.should have_text leads to undefined method `has_text?' In-Reply-To: References: Message-ID: <667433A2-782E-4A64-B805-41B17CC00566@gmail.com> On Sep 30, 2010, at 3:50 PM, turkan wrote: > One of my controllers directly renders some JSON output that I would > like to test with RSpec. For that I use 'response.should > have_text("foobar")' in my spec file, but that leads to a > > Failure/Error: response.should have_text("enim") > undefined method `has_text?' for # 0xb6736944> > > I read here somewhere that webrat should be in the Gemfile, but that > also did not solve the problem. The webrat matcher is contain: response.should contain("enim") HTH, David From dchelimsky at gmail.com Tue Oct 5 09:17:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Oct 2010 08:17:26 -0500 Subject: [rspec-users] using rcov with rspec2 In-Reply-To: References: <4fc7756d6370ef74abcba875525a2315@ruby-forum.com> <28b369ea-226b-4abf-94ca-78ee3a43709a@k10g2000yqa.googlegroups.com> Message-ID: On Tue, Oct 5, 2010 at 7:28 AM, David Chelimsky wrote: > On Tue, Oct 5, 2010 at 6:20 AM, nathanvda wrote: >> On Oct 4, 3:24?am, Will Marshall wrote: >>> > The error i get is this: >>> >>> > `require': no such file to load -- spec_helper (LoadError) >>> >>> The only solution I have found for this is to revert from rspec-rails >>> beta.22 to rspec-rails beta.20 > > Please post replies inline or at the bottom (I moved yours from the top). > >> I hoped the new rspec2.0.0.rc would fix it, but it doesn't. >> >> I hope anybody can shed any light on this? > > I'll need more information as rcov + rspec-2.0.0.rc is working just > fine for me. Please report this to > http://github.com/rspec/rspec-core/issues and include OS, ruby > version, and the full backtrace you are seeing. Actually somebody just reported this to http://github.com/rspec/rspec-rails/issues and I figured out the problem and fixed it in rspec-rails. I've also added http://github.com/rspec/rspec-core/issues/issue/172 to address this now that I understand the problem. Feel free to comment on that issue rather than adding a new one. Cheers, David From cremes.devlist at mac.com Tue Oct 5 10:34:22 2010 From: cremes.devlist at mac.com (Chuck Remes) Date: Tue, 05 Oct 2010 09:34:22 -0500 Subject: [rspec-users] rspec-2.0.0.rc is released In-Reply-To: <4DD28857-3452-4CB7-BC1F-444A68C1E32D@gmail.com> References: <4DD28857-3452-4CB7-BC1F-444A68C1E32D@gmail.com> Message-ID: On Oct 4, 2010, at 11:47 PM, David Chelimsky wrote: > rspec-2.0.0.rc is released! > > See http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/ for links to all sorts of documentation on rspec-2. > > Plan is to release rspec-2.0.0 (final) within the next week, so please install, upgrade, etc, and report issues to: > > http://github.com/rspec/rspec-core/issues > http://github.com/rspec/rspec-expectations/issues > http://github.com/rspec/rspec-mocks/issues > http://github.com/rspec/rspec-rails/issues Is there any coordination with the authors of jeweler, bones, etc. so that the Rake files those tools generate can be updated to rspec2 compatibility? Speaking of which, the Upgrade.markdown didn't include enough information to get my existing Rakefile (created by bones) working. I'm including the changes I had to make in this email so other folks searching the ML will find it. Original: require 'spec/rake/spectask' Spec::Rake::SpecTask.new do |t| t.spec_opts = ['--options', "\"spec/spec.opts\""] t.spec_files = FileList['spec/**/*.rb'] end For rspec2 compatibility: require 'rspec/core/rake_task' RSpec::Core::RakeTask.new do |t| t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"] t.pattern = 'spec/**/*_spec.rb' end Also, as mentioned in the Upgrade.markdown file, I had to modify my spec_helper.rb to use Rspec.configure instead of the original Spec::Runner.configure syntax. cr -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Oct 5 11:59:31 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Oct 2010 10:59:31 -0500 Subject: [rspec-users] rspec-2.0.0.rc is released In-Reply-To: References: <4DD28857-3452-4CB7-BC1F-444A68C1E32D@gmail.com> Message-ID: <9E1482A8-93EC-433F-889C-25543ABA2113@gmail.com> On Oct 5, 2010, at 9:34 AM, Chuck Remes wrote: > > On Oct 4, 2010, at 11:47 PM, David Chelimsky wrote: > >> rspec-2.0.0.rc is released! >> >> See http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/ for links to all sorts of documentation on rspec-2. >> >> Plan is to release rspec-2.0.0 (final) within the next week, so please install, upgrade, etc, and report issues to: >> >> http://github.com/rspec/rspec-core/issues >> http://github.com/rspec/rspec-expectations/issues >> http://github.com/rspec/rspec-mocks/issues >> http://github.com/rspec/rspec-rails/issues > > > Is there any coordination with the authors of jeweler, bones, etc. so that the Rake files those tools generate can be updated to rspec2 compatibility? Not yet. If any of them reach out to me I'll be glad to do what I can. > Speaking of which, the Upgrade.markdown didn't include enough information to get my existing Rakefile (created by bones) working. I'm including the changes I had to make in this email so other folks searching the ML will find it. > > Original: > > require 'spec/rake/spectask' > > Spec::Rake::SpecTask.new do |t| > t.spec_opts = ['--options', "\"spec/spec.opts\""] > t.spec_files = FileList['spec/**/*.rb'] > end > > > For rspec2 compatibility: > > require 'rspec/core/rake_task' > > RSpec::Core::RakeTask.new do |t| > t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"] > t.pattern = 'spec/**/*_spec.rb' > end I'll update the upgrade file. Thx. > > > Also, as mentioned in the Upgrade.markdown file, I had to modify my spec_helper.rb to use Rspec.configure instead of the original Spec::Runner.configure syntax. > > cr > > _______________________________________________ > 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 dchelimsky at gmail.com Tue Oct 5 12:00:42 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Oct 2010 11:00:42 -0500 Subject: [rspec-users] rspec-2.0.0.rc is released In-Reply-To: <9E1482A8-93EC-433F-889C-25543ABA2113@gmail.com> References: <4DD28857-3452-4CB7-BC1F-444A68C1E32D@gmail.com> <9E1482A8-93EC-433F-889C-25543ABA2113@gmail.com> Message-ID: <4C266F6C-C408-4F65-A511-1A8C1490CAB0@gmail.com> On Oct 5, 2010, at 10:59 AM, David Chelimsky wrote: > > On Oct 5, 2010, at 9:34 AM, Chuck Remes wrote: > >> >> On Oct 4, 2010, at 11:47 PM, David Chelimsky wrote: >> >>> rspec-2.0.0.rc is released! >>> >>> See http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/ for links to all sorts of documentation on rspec-2. >>> >>> Plan is to release rspec-2.0.0 (final) within the next week, so please install, upgrade, etc, and report issues to: >>> >>> http://github.com/rspec/rspec-core/issues >>> http://github.com/rspec/rspec-expectations/issues >>> http://github.com/rspec/rspec-mocks/issues >>> http://github.com/rspec/rspec-rails/issues >> >> >> Is there any coordination with the authors of jeweler, bones, etc. so that the Rake files those tools generate can be updated to rspec2 compatibility? > > Not yet. If any of them reach out to me I'll be glad to do what I can. > >> Speaking of which, the Upgrade.markdown didn't include enough information to get my existing Rakefile (created by bones) working. I'm including the changes I had to make in this email so other folks searching the ML will find it. >> >> Original: >> >> require 'spec/rake/spectask' >> >> Spec::Rake::SpecTask.new do |t| >> t.spec_opts = ['--options', "\"spec/spec.opts\""] >> t.spec_files = FileList['spec/**/*.rb'] >> end >> >> >> For rspec2 compatibility: >> >> require 'rspec/core/rake_task' >> >> RSpec::Core::RakeTask.new do |t| >> t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"] >> t.pattern = 'spec/**/*_spec.rb' >> end > > I'll update the upgrade file. Thx. I added an issue to track this: http://github.com/rspec/rspec-core/issues/issue/173. Please feel free to submit a patch :) > >> >> >> Also, as mentioned in the Upgrade.markdown file, I had to modify my spec_helper.rb to use Rspec.configure instead of the original Spec::Runner.configure syntax. >> >> cr >> >> _______________________________________________ >> 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 Tue Oct 5 19:19:54 2010 From: katrina.owen at gmail.com (Katrina Owen) Date: Wed, 6 Oct 2010 01:19:54 +0200 Subject: [rspec-users] Unable to get rid of backtrace when running specs (rspec2, rails3) Message-ID: Hi, I can't seem to silence the stack trace when running specs. Pending specs get this output: ChannelsController GET new responds to xml # why would we want to render xml for Channel.new? # ./spec/controllers/channel_controller_spec.rb:89 Failing specs get this: Failures: 1) ChannelsController POST create failing example Failure/Error: post :create, {:channel => channel} undefined method `save' for nil:NilClass # /gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing' . . ( 30 or so more lines ) . # /gems/spork-0.8.4/lib/spork/server.rb:47:in `run' Here's what I have so far: I've grepped through my project to check whether something is setting the --backtrace option, but as far as I can tell, it's not set. I also did > cd myproject; grep -lre '-b' which matched a bunch of temporary files and binary files, but nothing that seemed remotely relevant. The command I am using to kick off the tests is > rspec --drb spec I've tried running the tests in several ways: with and without spork/DRb, and by calling each of these: > rspec spec > rake spec > bundle exec rspec spec All of these give me a noisy backtrace. Interestingly, when I use rake, the full rails environment gets loaded twice. I haven't figured that one out yet, either. Here are as many of the environment variables as I can think might be relevant: > cat .rspec --colour --format progress > ruby -v ruby 1.9.2p14 (2010-10-02 revision 29393) [x86_64-darwin10.4.0] > rvm -v rvm 1.0.12 > gem list *** LOCAL GEMS *** abstract (1.0.0) actionmailer (3.0.0) actionpack (3.0.0) activemodel (3.0.0) activerecord (3.0.0) activeresource (3.0.0) activesupport (3.0.0) acts_as_state_machine (2.2.0) arel (1.0.1) autotest (4.4.1) aws-s3 (0.6.2) builder (2.1.2) bundler (1.0.1) commonwatir (1.6.5) compass (0.10.5) cucumber (0.9.2) cucumber-rails (0.3.2) diff-lcs (1.1.2) erubis (2.6.6) firewatir (1.6.5) gherkin (2.2.8) haml (3.0.21) hoe (2.6.2) httpclient (2.1.5.2) i18n (0.4.1) jquery-rails (0.2.1) json (1.4.6) json_pure (1.4.6) mail (2.2.6.1) mime-types (1.16) nokogiri (1.4.3.1) paperclip (2.3.3) pg (0.9.0) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.13) rack-test (0.5.6) rails (3.0.0) railties (3.0.0) rake (0.8.7) rspec (2.0.0.rc) rspec-core (2.0.0.rc) rspec-expectations (2.0.0.rc) rspec-mocks (2.0.0.rc) rspec-rails (2.0.0.rc) rubyforge (2.0.4) s4t-utils (1.0.4) spork (0.8.4) term-ansicolor (1.0.5) thor (0.14.2) treetop (1.4.8) tzinfo (0.3.23) user-choices (1.1.6.1) watchr (0.7) webrat (0.7.1) will_paginate (2.3.15) xml-simple (1.0.12) > gem environment RubyGems Environment: - RUBYGEMS VERSION: 1.3.7 - RUBY VERSION: 1.9.2 (2010-10-02 patchlevel 14) [x86_64-darwin10.4.0] - INSTALLATION DIRECTORY: /.rvm/gems/ruby-1.9.2-head at prq - RUBY EXECUTABLE: /.rvm/rubies/ruby-1.9.2-head/bin/ruby - EXECUTABLE DIRECTORY: /.rvm/gems/ruby-1.9.2-head at prq/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-10 - GEM PATHS: - /.rvm/gems/ruby-1.9.2-head at prq - /.rvm/gems/ruby-1.9.2-head at global - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - "install" => "--no-rdoc --no-ri" - "update" => "--no-rdoc --no-ri" - REMOTE SOURCES: - http://rubygems.org/ Any idea whether there are gems that set some configuration options that would turn the --backtrace option on for rspec? I'm not sure where to look next, and would be grateful for any suggestions/pointers! Cheers, Katrina From dchelimsky at gmail.com Tue Oct 5 19:44:19 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Oct 2010 18:44:19 -0500 Subject: [rspec-users] Unable to get rid of backtrace when running specs (rspec2, rails3) In-Reply-To: References: Message-ID: <657483E3-ACD4-4784-B647-80C92BC6C1E7@gmail.com> On Oct 5, 2010, at 6:19 PM, Katrina Owen wrote: > Hi, > > I can't seem to silence the stack trace when running specs. > > Pending specs get this output: > > ChannelsController GET new responds to xml > # why would we want to render xml for Channel.new? > # ./spec/controllers/channel_controller_spec.rb:89 > > Failing specs get this: > > Failures: > 1) ChannelsController POST create failing example > Failure/Error: post :create, {:channel => channel} > undefined method `save' for nil:NilClass > # /gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in > `method_missing' > . > . ( 30 or so more lines ) > . > # /gems/spork-0.8.4/lib/spork/server.rb:47:in `run' > > > Here's what I have so far: > > I've grepped through my project to check whether something is setting > the --backtrace option, but as far as I can tell, it's not set. > I also did >> cd myproject; grep -lre '-b' > which matched a bunch of temporary files and binary files, but nothing > that seemed remotely relevant. > > The command I am using to kick off the tests is > >> rspec --drb spec > > I've tried running the tests in several ways: with and without > spork/DRb, and by calling each of these: >> rspec spec >> rake spec >> bundle exec rspec spec > All of these give me a noisy backtrace. > > Interestingly, when I use rake, the full rails environment gets loaded > twice. I haven't figured that one out yet, either. > > Here are as many of the environment variables as I can think might be relevant: > >> cat .rspec > --colour > --format progress > >> ruby -v > ruby 1.9.2p14 (2010-10-02 revision 29393) [x86_64-darwin10.4.0] > >> rvm -v > rvm 1.0.12 > >> gem list > *** LOCAL GEMS *** > abstract (1.0.0) > actionmailer (3.0.0) > actionpack (3.0.0) > activemodel (3.0.0) > activerecord (3.0.0) > activeresource (3.0.0) > activesupport (3.0.0) > acts_as_state_machine (2.2.0) > arel (1.0.1) > autotest (4.4.1) > aws-s3 (0.6.2) > builder (2.1.2) > bundler (1.0.1) > commonwatir (1.6.5) > compass (0.10.5) > cucumber (0.9.2) > cucumber-rails (0.3.2) > diff-lcs (1.1.2) > erubis (2.6.6) > firewatir (1.6.5) > gherkin (2.2.8) > haml (3.0.21) > hoe (2.6.2) > httpclient (2.1.5.2) > i18n (0.4.1) > jquery-rails (0.2.1) > json (1.4.6) > json_pure (1.4.6) > mail (2.2.6.1) > mime-types (1.16) > nokogiri (1.4.3.1) > paperclip (2.3.3) > pg (0.9.0) > polyglot (0.3.1) > rack (1.2.1) > rack-mount (0.6.13) > rack-test (0.5.6) > rails (3.0.0) > railties (3.0.0) > rake (0.8.7) > rspec (2.0.0.rc) > rspec-core (2.0.0.rc) > rspec-expectations (2.0.0.rc) > rspec-mocks (2.0.0.rc) > rspec-rails (2.0.0.rc) > rubyforge (2.0.4) > s4t-utils (1.0.4) > spork (0.8.4) > term-ansicolor (1.0.5) > thor (0.14.2) > treetop (1.4.8) > tzinfo (0.3.23) > user-choices (1.1.6.1) > watchr (0.7) > webrat (0.7.1) > will_paginate (2.3.15) > xml-simple (1.0.12) > >> gem environment > RubyGems Environment: > - RUBYGEMS VERSION: 1.3.7 > - RUBY VERSION: 1.9.2 (2010-10-02 patchlevel 14) [x86_64-darwin10.4.0] > - INSTALLATION DIRECTORY: /.rvm/gems/ruby-1.9.2-head at prq > - RUBY EXECUTABLE: /.rvm/rubies/ruby-1.9.2-head/bin/ruby > - EXECUTABLE DIRECTORY: /.rvm/gems/ruby-1.9.2-head at prq/bin > - RUBYGEMS PLATFORMS: > - ruby > - x86_64-darwin-10 > - GEM PATHS: > - /.rvm/gems/ruby-1.9.2-head at prq > - /.rvm/gems/ruby-1.9.2-head at global > - GEM CONFIGURATION: > - :update_sources => true > - :verbose => true > - :benchmark => false > - :backtrace => false > - :bulk_threshold => 1000 > - "install" => "--no-rdoc --no-ri" > - "update" => "--no-rdoc --no-ri" > - REMOTE SOURCES: > - http://rubygems.org/ > > Any idea whether there are gems that set some configuration options > that would turn the --backtrace option on for rspec? > > I'm not sure where to look next, and would be grateful for any > suggestions/pointers! This needs some docs, but there is a configuration option called backtrace_clean_patterns that you can append to: RSpec::configure do |c| backtrace_clean_patterns << /gems\// end Maybe we should make that part of the default list? HTH, David From katrina.owen at gmail.com Wed Oct 6 03:33:02 2010 From: katrina.owen at gmail.com (Katrina Owen) Date: Wed, 6 Oct 2010 09:33:02 +0200 Subject: [rspec-users] Unable to get rid of backtrace when running specs (rspec2, rails3) In-Reply-To: <657483E3-ACD4-4784-B647-80C92BC6C1E7@gmail.com> References: <657483E3-ACD4-4784-B647-80C92BC6C1E7@gmail.com> Message-ID: On Wed, Oct 6, 2010 at 1:44 AM, David Chelimsky wrote: > > On Oct 5, 2010, at 6:19 PM, Katrina Owen wrote: >> I can't seem to silence the stack trace when running specs. > > This needs some docs, but there is a configuration option called backtrace_clean_patterns that you can append to: > > RSpec::configure do |c| > ?backtrace_clean_patterns << /gems\// > end > > Maybe we should make that part of the default list? > Thank you, David -- this worked beautifully. It would be great to have that available in the default list. Cheers, Katrina From nathanvda at gmail.com Wed Oct 6 04:25:22 2010 From: nathanvda at gmail.com (nathanvda) Date: Wed, 6 Oct 2010 01:25:22 -0700 (PDT) Subject: [rspec-users] using rcov with rspec2 In-Reply-To: References: <4fc7756d6370ef74abcba875525a2315@ruby-forum.com> <28b369ea-226b-4abf-94ca-78ee3a43709a@k10g2000yqa.googlegroups.com> Message-ID: <795615bc-d264-4bfd-b8d1-faec264c0b3d@x7g2000yqg.googlegroups.com> On 5 okt, 15:17, David Chelimsky wrote: > On Tue, Oct 5, 2010 at 7:28 AM, David Chelimsky wrote: > > On Tue, Oct 5, 2010 at 6:20 AM, nathanvda wrote: > >> On Oct 4, 3:24?am, Will Marshall wrote: > >>> > The error i get is this: > > >>> > `require': no such file to load -- spec_helper (LoadError) > > >>> The only solution I have found for this is to revert from rspec-rails > >>> beta.22 to rspec-rails beta.20 > > > Please post replies inline or at the bottom (I moved yours from the top). > > >> I hoped the new rspec2.0.0.rc would fix it, but it doesn't. > > >> I hope anybody can shed any light on this? > > > I'll need more information as rcov + rspec-2.0.0.rc is working just > > fine for me. Please report this to > >http://github.com/rspec/rspec-core/issuesand include OS, ruby > > version, and the full backtrace you are seeing. > > Actually somebody just reported this tohttp://github.com/rspec/rspec-rails/issuesand I figured out the > problem and fixed it in rspec-rails. > > I've also addedhttp://github.com/rspec/rspec-core/issues/issue/172to > address this now that I understand the problem. Feel free to comment > on that issue rather than adding a new one. > > Cheers, > David Thanks David, that helped me out! From cremes.devlist at mac.com Wed Oct 6 10:09:55 2010 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 06 Oct 2010 09:09:55 -0500 Subject: [rspec-users] rspec2 observations Message-ID: Just a few observations now that I have completed the upgrade from RSpec-1 to RSpec-2. 1. In my project (2800 examples across about 40 files), MRI 1.9.2-p0 takes roughly 3 times longer to complete the spec run. Runtimes grew from 2.2s (rspec 1.3.0) to 6.1s (2.0.0.rc). 2. Rubinius 1.1.0 runs RSpec-2 without error. 3. JRuby 1.5.1 runs RSpec-2 without error. 4. Both Rubinius and JRuby print a deprecation warning while running the exact same code as MRI 1.9.2-p0 (which doesn't print this warning). ***************************************************************** DEPRECATION WARNING: you are using a deprecated constant that will be removed from a future version of RSpec. * Spec is deprecated. * RSpec is the new top-level module in RSpec-2 /Users/cremes/.rvm/gems/rbx-head/gems/rspec-expectations-2.0.0.rc/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing' ***************************************************************** I don't know if this is an issue with RSpec-2 or if Rubinius & JRuby require an update. Or, perhaps the problem is elsewhere and this warning is a red herring. Guidance on this would be welcome; I am happy to open an issue with these other projects if the fault lays there. All in all, it's looking good! cr From dchelimsky at gmail.com Wed Oct 6 10:30:23 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 6 Oct 2010 09:30:23 -0500 Subject: [rspec-users] rspec2 observations In-Reply-To: References: Message-ID: <557AC306-EA90-406C-9155-27E3E29FE07A@gmail.com> On Oct 6, 2010, at 9:09 AM, Chuck Remes wrote: > Just a few observations now that I have completed the upgrade from RSpec-1 to RSpec-2. > > 1. In my project (2800 examples across about 40 files), MRI 1.9.2-p0 takes roughly 3 times longer to complete the spec run. Runtimes grew from 2.2s (rspec 1.3.0) to 6.1s (2.0.0.rc). Is this a Rails-3 project? Are you using the time that rspec displays, or measuring that yourself (including load times before the spec run starts)? > 2. Rubinius 1.1.0 runs RSpec-2 without error. > > 3. JRuby 1.5.1 runs RSpec-2 without error. > > 4. Both Rubinius and JRuby print a deprecation warning while running the exact same code as MRI 1.9.2-p0 (which doesn't print this warning). > > ***************************************************************** > DEPRECATION WARNING: you are using a deprecated constant that will > be removed from a future version of RSpec. > > * Spec is deprecated. > * RSpec is the new top-level module in RSpec-2 > > /Users/cremes/.rvm/gems/rbx-head/gems/rspec-expectations-2.0.0.rc/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing' > ***************************************************************** > > > I don't know if this is an issue with RSpec-2 or if Rubinius & JRuby require an update. Or, perhaps the problem is elsewhere and this warning is a red herring. Guidance on this would be welcome; I am happy to open an issue with these other projects if the fault lays there. That warning would only happen if something was trying to reference the Spec module instead of RSpec. Feel free to open an issue for this so we can track it, but I'm pretty sure it's not anything RSpec can fix. Thanks for the feedback! Cheers, David > All in all, it's looking good! > > cr From cremes.devlist at mac.com Wed Oct 6 12:19:41 2010 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 06 Oct 2010 11:19:41 -0500 Subject: [rspec-users] rspec2 observations In-Reply-To: <557AC306-EA90-406C-9155-27E3E29FE07A@gmail.com> References: <557AC306-EA90-406C-9155-27E3E29FE07A@gmail.com> Message-ID: <682DAC63-1FF1-4355-968D-7608D969A500@mac.com> On Oct 6, 2010, at 9:30 AM, David Chelimsky wrote: > On Oct 6, 2010, at 9:09 AM, Chuck Remes wrote: > >> Just a few observations now that I have completed the upgrade from RSpec-1 to RSpec-2. >> >> 1. In my project (2800 examples across about 40 files), MRI 1.9.2-p0 takes roughly 3 times longer to complete the spec run. Runtimes grew from 2.2s (rspec 1.3.0) to 6.1s (2.0.0.rc). > > Is this a Rails-3 project? Are you using the time that rspec displays, or measuring that yourself (including load times before the spec run starts)? Nope, no Rails. This is a work project which uses a few gems like ffi-rzmq, zmqmachine, sequel, mongo/bson, etc. It's a set of distributed applications for a trading system; no web stuff at all. >> I don't know if this is an issue with RSpec-2 or if Rubinius & JRuby require an update. Or, perhaps the problem is elsewhere and this warning is a red herring. Guidance on this would be welcome; I am happy to open an issue with these other projects if the fault lays there. > > That warning would only happen if something was trying to reference the Spec module instead of RSpec. Feel free to open an issue for this so we can track it, but I'm pretty sure it's not anything RSpec can fix. > > Thanks for the feedback! I'll try to pinpoint the error a bit better before opening an issue. Thanks for a great tool like rspec! It gives me confidence in my code. cr From timgremore at gmail.com Thu Oct 7 17:36:03 2010 From: timgremore at gmail.com (Tim Gremore) Date: Thu, 7 Oct 2010 16:36:03 -0500 Subject: [rspec-users] Could not find shared example group named "an admin is logged in" Message-ID: I'm stuck! Not sure what I'm missing but I'm struggling to get a shared example group working with my controller specs. Here is a piece of the backtrace: /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:68:in `it_should_behave_like': Could not find shared example group named "an admin is logged in" (RuntimeError) from /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:5:in `block in ' from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in `module_eval' from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in `subclass' from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:119:in `describe' from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/extensions/object.rb:7:in `describe' from /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:3:in `' I'm using the following: rails 3.0 rspec-rails 2.0.0.rc (and friends) cucumber-rails 0.3.2 factory_girl_rails 1.0 And the following for shared examples: module ExampleGroupMethods describe "an admin is logged in", :shared => true do before(:each) do controller.stubs(:logged_in? => true) controller.stubs(:current_user => Factory.create(:admin)) end end describe "a supporter is logged in", :shared => true do before(:each) do controller.stubs(:logged_in? => true) controller.stubs(:current_user => Factory.create(:supporter)) end end describe "a manager is logged in", :shared => true do before(:each) do controller.stubs(:logged_in? => true) controller.stubs(:current_user => Factory.create(:manager)) end end end And the follow controller spec: describe UsersController do it_should_behave_like "an admin is logged in" describe "handling /users" do before do @user = mock_model(User) end def do_get get :index end it "should assign users to the view" do User.should_receive(:all).with(:order => "last_name, first_name").and_return([ @user ]) do_get end end end And finally this spec_helper: # 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' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| # == Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr config.mock_with :rspec # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true # see http://asciicasts.com/episodes/157-rspec-matchers-macros config.include(ControllerMacros, :type => :controller) # see http://pastie.org/870928 config.include(ExampleGroupMethods, :type => :controller) end Anyone have a suggestion? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Thu Oct 7 17:53:29 2010 From: jko170 at gmail.com (Justin Ko) Date: Thu, 7 Oct 2010 14:53:29 -0700 (PDT) Subject: [rspec-users] Could not find shared example group named "an admin is logged in" In-Reply-To: References: Message-ID: On Oct 7, 5:36?pm, Tim Gremore wrote: > I'm stuck! Not sure what I'm missing but I'm struggling to get a shared > example group working with my controller specs. ?Here is a piece of the > backtrace: > > /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib /rspec/core/example_group.rb:68:in > `it_should_behave_like': Could not find shared example group named "an admin > is logged in" (RuntimeError) > ?from > /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:5 :in > `block in ' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib /rspec/core/example_group.rb:132:in > `module_eval' > ?from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib /rspec/core/example_group.rb:132:in > `subclass' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib /rspec/core/example_group.rb:119:in > `describe' > ?from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib /rspec/core/extensions/object.rb:7:in > `describe' > from > /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:3 :in > `' > > I'm using the following: > > rails 3.0 > rspec-rails 2.0.0.rc (and friends) > cucumber-rails 0.3.2 > factory_girl_rails 1.0 > > And the following for shared examples: > > module ExampleGroupMethods > > ? describe "an admin is logged in", :shared => true do > ? ? before(:each) do > ? ? ? controller.stubs(:logged_in? => true) > ? ? ? controller.stubs(:current_user => Factory.create(:admin)) > ? ? end > ? end > > ? describe "a supporter is logged in", :shared => true do > ? ? before(:each) do > ? ? ? controller.stubs(:logged_in? => true) > ? ? ? controller.stubs(:current_user => Factory.create(:supporter)) > ? ? end > ? end > > ? describe "a manager is logged in", :shared => true do > ? ? before(:each) do > ? ? ? controller.stubs(:logged_in? => true) > ? ? ? controller.stubs(:current_user => Factory.create(:manager)) > ? ? end > ? end > > end > > And the follow controller spec: > > describe UsersController do > > ? it_should_behave_like "an admin is logged in" > > ? describe "handling /users" do > > ? ? before do > ? ? ? @user = mock_model(User) > ? ? end > > ? ? def do_get > ? ? ? get :index > ? ? end > > ? ? it "should assign users to the view" do > ? ? ? User.should_receive(:all).with(:order => "last_name, > first_name").and_return([ @user ]) > ? ? ? do_get > ? ? end > > ? end > > end > > And finally this spec_helper: > > # 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' > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| > ? # == Mock Framework > ? # > ? # If you prefer to use mocha, flexmock or RR, uncomment the appropriate > line: > ? # > ? # config.mock_with :mocha > ? # config.mock_with :flexmock > ? # config.mock_with :rr > ? config.mock_with :rspec > > ? # Remove this line if you're not using ActiveRecord or ActiveRecord > fixtures > ? # config.fixture_path = "#{::Rails.root}/spec/fixtures" > > ? # If you're not using ActiveRecord, or you'd prefer not to run each of > your > ? # examples within a transaction, remove the following line or assign false > ? # instead of true. > ? config.use_transactional_fixtures = true > > ? # seehttp://asciicasts.com/episodes/157-rspec-matchers-macros > ? config.include(ControllerMacros, :type => :controller) > > ? # seehttp://pastie.org/870928 > ? config.include(ExampleGroupMethods, :type => :controller) > end > > Anyone have a suggestion? ?Thanks in advance > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Hello, You actually have to use the `shared_examples_for` method. So, your code should look like this: shared_examples_for "an admin is logged in" do describe "an admin is logged in", :shared => true do ..... From dchelimsky at gmail.com Thu Oct 7 21:25:59 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Oct 2010 20:25:59 -0500 Subject: [rspec-users] Could not find shared example group named "an admin is logged in" In-Reply-To: References: Message-ID: On Oct 7, 2010, at 4:36 PM, Tim Gremore wrote: > I'm stuck! Not sure what I'm missing but I'm struggling to get a shared example group working with my controller specs. Here is a piece of the backtrace: > > /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:68:in `it_should_behave_like': Could not find shared example group named "an admin is logged in" (RuntimeError) > from /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:5:in `block in ' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in `module_eval' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in `subclass' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:119:in `describe' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/extensions/object.rb:7:in `describe' > from /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:3:in `' > > I'm using the following: > > rails 3.0 > rspec-rails 2.0.0.rc (and friends) > cucumber-rails 0.3.2 > factory_girl_rails 1.0 > > And the following for shared examples: > > module ExampleGroupMethods > > describe "an admin is logged in", :shared => true do > before(:each) do > controller.stubs(:logged_in? => true) > controller.stubs(:current_user => Factory.create(:admin)) > end > end > > describe "a supporter is logged in", :shared => true do > before(:each) do > controller.stubs(:logged_in? => true) > controller.stubs(:current_user => Factory.create(:supporter)) > end > end > > describe "a manager is logged in", :shared => true do > before(:each) do > controller.stubs(:logged_in? => true) > controller.stubs(:current_user => Factory.create(:manager)) > end > end > > end > > And the follow controller spec: > > describe UsersController do > > it_should_behave_like "an admin is logged in" > > describe "handling /users" do > > before do > @user = mock_model(User) > end > > def do_get > get :index > end > > it "should assign users to the view" do > User.should_receive(:all).with(:order => "last_name, first_name").and_return([ @user ]) > do_get > end > > end > > end > > And finally this spec_helper: > > # 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' > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| > # == Mock Framework > # > # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: > # > # config.mock_with :mocha > # config.mock_with :flexmock > # config.mock_with :rr > config.mock_with :rspec > > # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures > # config.fixture_path = "#{::Rails.root}/spec/fixtures" > > # If you're not using ActiveRecord, or you'd prefer not to run each of your > # examples within a transaction, remove the following line or assign false > # instead of true. > config.use_transactional_fixtures = true > > # see http://asciicasts.com/episodes/157-rspec-matchers-macros > config.include(ControllerMacros, :type => :controller) > > # see http://pastie.org/870928 > config.include(ExampleGroupMethods, :type => :controller) > end > > Anyone have a suggestion? Thanks in advance Shared examples have changed significantly in rspec-2. See http://github.com/rspec/rspec-core/blob/master/features/example_groups/shared_example_group.feature to get a feel for how they work now. The first thing is that :shared = true no longer works. You need to use shared_examples_for. The other big change is that it_should_behave_like creates a nested group, so if you do this: shared_examples_for "foo" do it "does something" do end end describe "something" do it_behaves_like "foo" # it_behaves_like is an alias for it_should_behave_like end That's the same as doing this: describe "something" do context "behaves like foo" do it "does something" do end end end This is a good thing, because it prevents the context of the shared group from polluting the including group's scope, which can lead (and has led) to a lot of confusion. Now in your case, you're using the shared group as a means of sharing before blocks. While that works, it's the opposite of the intent of shared groups, which is that the enclosing group should provide the context for the shared group. What you _can_ do, however, to maintain the structure you have, is to pass a block to it_should_behave_like, so your example change from this: # rspec-1 describe UsersController do it_should_behave_like "an admin is logged in" describe "handling /users" do before do @user = mock_model(User) end def do_get get :index end it "should assign users to the view" do User.should_receive(:all).with(:order => "last_name, first_name").and_return([ @user ]) do_get end end end to this: #rspec-2 describe UsersController do it_should_behave_like "an admin is logged in" do describe "handling /users" do before do @user = mock_model(User) end def do_get get :index end it "should assign users to the view" do User.should_receive(:all).with(:order => "last_name, first_name").and_return([ @user ]) do_get end end end end HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Oct 8 00:00:01 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Oct 2010 23:00:01 -0500 Subject: [rspec-users] Unable to get rid of backtrace when running specs (rspec2, rails3) In-Reply-To: References: <657483E3-ACD4-4784-B647-80C92BC6C1E7@gmail.com> Message-ID: <972944A3-3E4C-4B02-A0D5-012EA0CDB58F@gmail.com> On Oct 6, 2010, at 2:33 AM, Katrina Owen wrote: > On Wed, Oct 6, 2010 at 1:44 AM, David Chelimsky wrote: >> >> On Oct 5, 2010, at 6:19 PM, Katrina Owen wrote: >>> I can't seem to silence the stack trace when running specs. >> >> This needs some docs, but there is a configuration option called backtrace_clean_patterns that you can append to: >> >> RSpec::configure do |c| >> backtrace_clean_patterns << /gems\// >> end >> >> Maybe we should make that part of the default list? >> > > Thank you, David -- this worked beautifully. > > It would be great to have that available in the default list. http://github.com/rspec/rspec-core/commit/fc591be26485ffafacec51e6b47208604324809c http://github.com/rspec/rspec-rails/commit/73051af796b143b9989287530fd5fdd52cbe9bfe Cheers, David From timgremore at gmail.com Fri Oct 8 09:20:09 2010 From: timgremore at gmail.com (Tim Gremore) Date: Fri, 8 Oct 2010 08:20:09 -0500 Subject: [rspec-users] Could not find shared example group named "an admin is logged in" In-Reply-To: References: Message-ID: Thanks much Justin and David - very helpful. David, you explained that I could accomplish my goal by sending a block to it_should_behave_like, even though that is not its intended purpose. Is there a cleaner way to accomplish my goal (spec'ing controller authentication and authorization)? On Thu, Oct 7, 2010 at 8:25 PM, David Chelimsky wrote: > On Oct 7, 2010, at 4:36 PM, Tim Gremore wrote: > > I'm stuck! Not sure what I'm missing but I'm struggling to get a shared > example group working with my controller specs. Here is a piece of the > backtrace: > > /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:68:in > `it_should_behave_like': Could not find shared example group named "an admin > is logged in" (RuntimeError) > from > /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:5:in > `block in ' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in > `module_eval' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in > `subclass' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:119:in > `describe' > from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/extensions/object.rb:7:in > `describe' > from > /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:3:in > `' > > I'm using the following: > > rails 3.0 > rspec-rails 2.0.0.rc (and friends) > cucumber-rails 0.3.2 > factory_girl_rails 1.0 > > > And the following for shared examples: > > module ExampleGroupMethods > > describe "an admin is logged in", :shared => true do > before(:each) do > controller.stubs(:logged_in? => true) > controller.stubs(:current_user => Factory.create(:admin)) > end > end > > describe "a supporter is logged in", :shared => true do > before(:each) do > controller.stubs(:logged_in? => true) > controller.stubs(:current_user => Factory.create(:supporter)) > end > end > > describe "a manager is logged in", :shared => true do > before(:each) do > controller.stubs(:logged_in? => true) > controller.stubs(:current_user => Factory.create(:manager)) > end > end > > end > > > And the follow controller spec: > > describe UsersController do > > it_should_behave_like "an admin is logged in" > > describe "handling /users" do > > before do > @user = mock_model(User) > end > > def do_get > get :index > end > > it "should assign users to the view" do > User.should_receive(:all).with(:order => "last_name, > first_name").and_return([ @user ]) > do_get > end > > end > > end > > > And finally this spec_helper: > > # 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' > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| > # == Mock Framework > # > # If you prefer to use mocha, flexmock or RR, uncomment the appropriate > line: > # > # config.mock_with :mocha > # config.mock_with :flexmock > # config.mock_with :rr > config.mock_with :rspec > > # Remove this line if you're not using ActiveRecord or ActiveRecord > fixtures > # config.fixture_path = "#{::Rails.root}/spec/fixtures" > > # If you're not using ActiveRecord, or you'd prefer not to run each of > your > # examples within a transaction, remove the following line or assign > false > # instead of true. > config.use_transactional_fixtures = true > > # see http://asciicasts.com/episodes/157-rspec-matchers-macros > config.include(ControllerMacros, :type => :controller) > > # see http://pastie.org/870928 > config.include(ExampleGroupMethods, :type => :controller) > end > > > Anyone have a suggestion? Thanks in advance > > > Shared examples have changed significantly in rspec-2. See > http://github.com/rspec/rspec-core/blob/master/features/example_groups/shared_example_group.feature to > get a feel for how they work now. > > The first thing is that :shared = true no longer works. You need to use > shared_examples_for. The other big change is that it_should_behave_like > creates a nested group, so if you do this: > > shared_examples_for "foo" do > it "does something" do > end > end > > describe "something" do > it_behaves_like "foo" # it_behaves_like is an alias for > it_should_behave_like > end > > That's the same as doing this: > > describe "something" do > context "behaves like foo" do > it "does something" do > end > end > end > > This is a good thing, because it prevents the context of the shared group > from polluting the including group's scope, which can lead (and has led) to > a lot of confusion. > > Now in your case, you're using the shared group as a means of sharing > before blocks. While that works, it's the opposite of the intent of shared > groups, which is that the enclosing group should provide the context for the > shared group. What you _can_ do, however, to maintain the structure you > have, is to pass a block to it_should_behave_like, so your example change > from this: > > # rspec-1 > describe UsersController do > it_should_behave_like "an admin is logged in" > describe "handling /users" do > before do > @user = mock_model(User) > end > > def do_get > get :index > end > > it "should assign users to the view" do > User.should_receive(:all).with(:order => "last_name, > first_name").and_return([ @user ]) > do_get > end > end > end > > to this: > > #rspec-2 > describe UsersController do > it_should_behave_like "an admin is logged in" do > describe "handling /users" do > before do > @user = mock_model(User) > end > > def do_get > get :index > end > > it "should assign users to the view" do > User.should_receive(:all).with(:order => "last_name, > first_name").and_return([ @user ]) > do_get > end > end > end > end > > HTH, > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Tim Gremore 920 471-1716 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Oct 8 10:21:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Oct 2010 09:21:12 -0500 Subject: [rspec-users] Could not find shared example group named "an admin is logged in" In-Reply-To: References: Message-ID: <635A333C-62AB-4E85-9D7A-34EC286C10D5@gmail.com> On Oct 8, 2010, at 8:20 AM, Tim Gremore wrote: > On Thu, Oct 7, 2010 at 8:25 PM, David Chelimsky wrote: > On Oct 7, 2010, at 4:36 PM, Tim Gremore wrote: > >> I'm stuck! Not sure what I'm missing but I'm struggling to get a shared example group working with my controller specs. Here is a piece of the backtrace: >> >> /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:68:in `it_should_behave_like': Could not find shared example group named "an admin is logged in" (RuntimeError) >> from /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:5:in `block in ' >> from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in `module_eval' >> from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in `subclass' >> from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:119:in `describe' >> from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/extensions/object.rb:7:in `describe' >> from /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:3:in `' >> >> I'm using the following: >> >> rails 3.0 >> rspec-rails 2.0.0.rc (and friends) >> cucumber-rails 0.3.2 >> factory_girl_rails 1.0 >> >> And the following for shared examples: >> >> module ExampleGroupMethods >> >> describe "an admin is logged in", :shared => true do >> before(:each) do >> controller.stubs(:logged_in? => true) >> controller.stubs(:current_user => Factory.create(:admin)) >> end >> end >> >> describe "a supporter is logged in", :shared => true do >> before(:each) do >> controller.stubs(:logged_in? => true) >> controller.stubs(:current_user => Factory.create(:supporter)) >> end >> end >> >> describe "a manager is logged in", :shared => true do >> before(:each) do >> controller.stubs(:logged_in? => true) >> controller.stubs(:current_user => Factory.create(:manager)) >> end >> end >> >> end >> >> And the follow controller spec: >> >> describe UsersController do >> >> it_should_behave_like "an admin is logged in" >> >> describe "handling /users" do >> >> before do >> @user = mock_model(User) >> end >> >> def do_get >> get :index >> end >> >> it "should assign users to the view" do >> User.should_receive(:all).with(:order => "last_name, first_name").and_return([ @user ]) >> do_get >> end >> >> end >> >> end >> >> And finally this spec_helper: >> >> # 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' >> >> # Requires supporting ruby files with custom matchers and macros, etc, >> # in spec/support/ and its subdirectories. >> Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} >> >> RSpec.configure do |config| >> # == Mock Framework >> # >> # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: >> # >> # config.mock_with :mocha >> # config.mock_with :flexmock >> # config.mock_with :rr >> config.mock_with :rspec >> >> # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures >> # config.fixture_path = "#{::Rails.root}/spec/fixtures" >> >> # If you're not using ActiveRecord, or you'd prefer not to run each of your >> # examples within a transaction, remove the following line or assign false >> # instead of true. >> config.use_transactional_fixtures = true >> >> # see http://asciicasts.com/episodes/157-rspec-matchers-macros >> config.include(ControllerMacros, :type => :controller) >> >> # see http://pastie.org/870928 >> config.include(ExampleGroupMethods, :type => :controller) >> end >> >> Anyone have a suggestion? Thanks in advance > > Shared examples have changed significantly in rspec-2. See http://github.com/rspec/rspec-core/blob/master/features/example_groups/shared_example_group.feature to get a feel for how they work now. > > The first thing is that :shared = true no longer works. You need to use shared_examples_for. The other big change is that it_should_behave_like creates a nested group, so if you do this: > > shared_examples_for "foo" do > it "does something" do > end > end > > describe "something" do > it_behaves_like "foo" # it_behaves_like is an alias for it_should_behave_like > end > > That's the same as doing this: > > describe "something" do > context "behaves like foo" do > it "does something" do > end > end > end > > This is a good thing, because it prevents the context of the shared group from polluting the including group's scope, which can lead (and has led) to a lot of confusion. > > Now in your case, you're using the shared group as a means of sharing before blocks. While that works, it's the opposite of the intent of shared groups, which is that the enclosing group should provide the context for the shared group. What you _can_ do, however, to maintain the structure you have, is to pass a block to it_should_behave_like, so your example change from this: > > # rspec-1 > describe UsersController do > it_should_behave_like "an admin is logged in" > describe "handling /users" do > before do > @user = mock_model(User) > end > > def do_get > get :index > end > > it "should assign users to the view" do > User.should_receive(:all).with(:order => "last_name, first_name").and_return([ @user ]) > do_get > end > end > end > > to this: > > #rspec-2 > describe UsersController do > it_should_behave_like "an admin is logged in" do > describe "handling /users" do > before do > @user = mock_model(User) > end > > def do_get > get :index > end > > it "should assign users to the view" do > User.should_receive(:all).with(:order => "last_name, first_name").and_return([ @user ]) > do_get > end > end > end > end > > HTH, > David > Thanks much Justin and David - very helpful. David, you explained that I could accomplish my goal by sending a block to it_should_behave_like, even though that is not its intended purpose. Is there a cleaner way to accomplish my goal (spec'ing controller authentication and authorization)? Not sure if I was clear. I didn't mean to imply that passing a block a bad thing. Quite the contrary. Passing blocks is a big part of what makes shared groups in rspec-2 better than rspec-1 for their intended purpose: to share examples for a conceptual (duck) type or a module, with the including group providing concrete context. What you're doing is the opposite - providing context using a shared group. Does that make sense? This is not to say that this is wrong, or evil. It's just the reverse of the intent. Take a close look at this scenario: http://github.com/rspec/rspec-core/blob/c5e6bc031404762edcda7789ecc04c6d340c8ef6/features/example_groups/shared_example_group.feature#L11. It demonstrates shared examples for a collection, applied to two different types, with the context provided by the "describe Array" group (which provides an instance of Array as the implicit subject) and the "describe Set" group (which provides a Set). Let me know if you have any questions. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From timgremore at gmail.com Fri Oct 8 11:52:40 2010 From: timgremore at gmail.com (Tim Gremore) Date: Fri, 8 Oct 2010 10:52:40 -0500 Subject: [rspec-users] Could not find shared example group named "an admin is logged in" In-Reply-To: <635A333C-62AB-4E85-9D7A-34EC286C10D5@gmail.com> References: <635A333C-62AB-4E85-9D7A-34EC286C10D5@gmail.com> Message-ID: Hi David - it's starting to sink in for me. Your explanation was clear but I have to ask if there is a better way when I hear that I'm using something opposite its intended purpose :) I've been able to send a block to my shared example group successfully - working great so far! Thanks again On Fri, Oct 8, 2010 at 9:21 AM, David Chelimsky wrote: > > On Oct 8, 2010, at 8:20 AM, Tim Gremore wrote: > > On Thu, Oct 7, 2010 at 8:25 PM, David Chelimsky wrote: > >> On Oct 7, 2010, at 4:36 PM, Tim Gremore wrote: >> >> I'm stuck! Not sure what I'm missing but I'm struggling to get a shared >> example group working with my controller specs. Here is a piece of the >> backtrace: >> >> /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:68:in >> `it_should_behave_like': Could not find shared example group named "an admin >> is logged in" (RuntimeError) >> from >> /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:5:in >> `block in ' >> from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in >> `module_eval' >> from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:132:in >> `subclass' >> from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/example_group.rb:119:in >> `describe' >> from /Users/20217633/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.rc/lib/rspec/core/extensions/object.rb:7:in >> `describe' >> from >> /Users/20217633/apps/curriculum/spec/controllers/users_controller_spec.rb:3:in >> `' >> >> I'm using the following: >> >> rails 3.0 >> rspec-rails 2.0.0.rc (and friends) >> cucumber-rails 0.3.2 >> factory_girl_rails 1.0 >> >> >> And the following for shared examples: >> >> module ExampleGroupMethods >> >> describe "an admin is logged in", :shared => true do >> before(:each) do >> controller.stubs(:logged_in? => true) >> controller.stubs(:current_user => Factory.create(:admin)) >> end >> end >> >> describe "a supporter is logged in", :shared => true do >> before(:each) do >> controller.stubs(:logged_in? => true) >> controller.stubs(:current_user => Factory.create(:supporter)) >> end >> end >> >> describe "a manager is logged in", :shared => true do >> before(:each) do >> controller.stubs(:logged_in? => true) >> controller.stubs(:current_user => Factory.create(:manager)) >> end >> end >> >> end >> >> >> And the follow controller spec: >> >> describe UsersController do >> >> it_should_behave_like "an admin is logged in" >> >> describe "handling /users" do >> >> before do >> @user = mock_model(User) >> end >> >> def do_get >> get :index >> end >> >> it "should assign users to the view" do >> User.should_receive(:all).with(:order => "last_name, >> first_name").and_return([ @user ]) >> do_get >> end >> >> end >> >> end >> >> >> And finally this spec_helper: >> >> # 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' >> >> # Requires supporting ruby files with custom matchers and macros, etc, >> # in spec/support/ and its subdirectories. >> Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} >> >> RSpec.configure do |config| >> # == Mock Framework >> # >> # If you prefer to use mocha, flexmock or RR, uncomment the appropriate >> line: >> # >> # config.mock_with :mocha >> # config.mock_with :flexmock >> # config.mock_with :rr >> config.mock_with :rspec >> >> # Remove this line if you're not using ActiveRecord or ActiveRecord >> fixtures >> # config.fixture_path = "#{::Rails.root}/spec/fixtures" >> >> # If you're not using ActiveRecord, or you'd prefer not to run each of >> your >> # examples within a transaction, remove the following line or assign >> false >> # instead of true. >> config.use_transactional_fixtures = true >> >> # see http://asciicasts.com/episodes/157-rspec-matchers-macros >> config.include(ControllerMacros, :type => :controller) >> >> # see http://pastie.org/870928 >> config.include(ExampleGroupMethods, :type => :controller) >> end >> >> >> Anyone have a suggestion? Thanks in advance >> >> >> Shared examples have changed significantly in rspec-2. See >> http://github.com/rspec/rspec-core/blob/master/features/example_groups/shared_example_group.feature to >> get a feel for how they work now. >> >> The first thing is that :shared = true no longer works. You need to use >> shared_examples_for. The other big change is that it_should_behave_like >> creates a nested group, so if you do this: >> >> shared_examples_for "foo" do >> it "does something" do >> end >> end >> >> describe "something" do >> it_behaves_like "foo" # it_behaves_like is an alias for >> it_should_behave_like >> end >> >> That's the same as doing this: >> >> describe "something" do >> context "behaves like foo" do >> it "does something" do >> end >> end >> end >> >> This is a good thing, because it prevents the context of the shared group >> from polluting the including group's scope, which can lead (and has led) to >> a lot of confusion. >> >> Now in your case, you're using the shared group as a means of sharing >> before blocks. While that works, it's the opposite of the intent of shared >> groups, which is that the enclosing group should provide the context for the >> shared group. What you _can_ do, however, to maintain the structure you >> have, is to pass a block to it_should_behave_like, so your example change >> from this: >> >> # rspec-1 >> describe UsersController do >> it_should_behave_like "an admin is logged in" >> describe "handling /users" do >> before do >> @user = mock_model(User) >> end >> >> def do_get >> get :index >> end >> >> it "should assign users to the view" do >> User.should_receive(:all).with(:order => "last_name, >> first_name").and_return([ @user ]) >> do_get >> end >> end >> end >> >> to this: >> >> #rspec-2 >> describe UsersController do >> it_should_behave_like "an admin is logged in" do >> describe "handling /users" do >> before do >> @user = mock_model(User) >> end >> >> def do_get >> get :index >> end >> >> it "should assign users to the view" do >> User.should_receive(:all).with(:order => "last_name, >> first_name").and_return([ @user ]) >> do_get >> end >> end >> end >> end >> >> HTH, >> David >> > > Thanks much Justin and David - very helpful. David, you explained that I >> could accomplish my goal by sending a block to it_should_behave_like, even >> though that is not its intended purpose. Is there a cleaner way to >> accomplish my goal (spec'ing controller authentication and authorization)? > > > Not sure if I was clear. I didn't mean to imply that passing a block a bad > thing. Quite the contrary. Passing blocks is a big part of what makes shared > groups in rspec-2 better than rspec-1 for their intended purpose: > > to share examples for a conceptual (duck) type or a module, with the > including group providing concrete context. > > What you're doing is the opposite - providing context using a shared > group. > > Does that make sense? This is not to say that this is wrong, or evil. It's > just the reverse of the intent. > > Take a close look at this scenario: > http://github.com/rspec/rspec-core/blob/c5e6bc031404762edcda7789ecc04c6d340c8ef6/features/example_groups/shared_example_group.feature#L11. > It demonstrates shared examples for a collection, applied to two different > types, with the context provided by the "describe Array" group (which > provides an instance of Array as the implicit subject) and the "describe > Set" group (which provides a Set). > > Let me know if you have any questions. > > Cheers, > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Tim Gremore 920 471-1716 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Oct 9 12:43:08 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 9 Oct 2010 11:43:08 -0500 Subject: [rspec-users] rspec-1.3.1.rc and rspec-rails-1.3.3.rc are released! In-Reply-To: References: <30B11EBC-6901-4CB3-8F4C-CAEAF032B8F1@gmail.com> Message-ID: <87D7BEC6-D0E2-48DA-BC13-4CFCFEFE3A13@gmail.com> On Oct 5, 2010, at 2:32 AM, Tom Stuart wrote: > Hi David, > > On 3 Oct 2010, at 23:41, David Chelimsky wrote: >> These are release candidate gems for updates 1.x series, including some bug fixes and deprecation warnings for functionality that will be removed in rspec-2. > > I'm having to maintain a fork of RSpec just so that I can revert the commit which caused the breakage in https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/1009. What are the chances of getting the failing example from that ticket into 1.3.1, along with either a reversion of the offending commit or (much better) an actual fix? To me this is a significant compatibility issue since it used to work in RSpec 1.2.9 and still does work in RSpec 2. I just don't understand enough about how this part of RSpec works to do a proper fix myself, but from a selfish perspective a revert of the bad commit is better than no fix at all. Hi Tom, Looks like it does work in rspec-2: http://github.com/rspec/rspec-mocks/commit/b8135d5d8d04930f09d606a96c2d84be910a12f2 As for rspec-1, if it were a simple matter of reverting the commit, I'd do it, but the revert fails w/ merge errors and I don't have the time to debug that right now. So 1.3.1 is going to go out without addressing this unless someone else submits a patch. Wish I could give you better news, but my plate is piled high and there is only so much time in a day. Cheers, David From dchelimsky at gmail.com Sat Oct 9 22:51:48 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 9 Oct 2010 21:51:48 -0500 Subject: [rspec-users] rspec-1.3.1 and rspec-rails-1.3.3 are released! Message-ID: I just released rspec-1.3.1 and rspec-rails-1.3.3. These are mostly bug fixes that have been sitting around for all to long as I focused on rspec-2 (coming very soon). Report issues for rspec[-rails]-1.x to https://rspec.lighthouseapp.com/projects/5645. Docs: http://rspec.info/ http://rdoc.info/gems/rspec/1.3.1/frames http://rdoc.info/gems/rspec-rails/1.3.3/frames Cheers, David === rspec-1.3.1 / 2010-10-09 * enhancements * Array =~ matcher works with subclasses of Array (Matthew Peychich & Pat Maddox) * config.suppress_deprecation_warnings! * bug fixes * QuitBacktraceTweaker no longer eats all paths with 'lib' (Tim Harper - #912) * Fix delegation of stubbed values on superclass class-level methods. (Scott Taylor - #496 - #957) * Fix pending to work with ruby-1.9 * deprecations * share_as (will be removed from rspec-core-2.0) * simple_matcher (will be removed from rspec-core-2.0) === rspec-rails-1.3.3 / 2010-10-09 * enhancements * replace use of 'returning' with 'tap' * bug fixes * support message expectation on template.render with locals (Sergey Nebolsin). Closes #941. * helper instance variable no longer persists across examples (alex rothenberg). Closes #627. * mock_model stubs marked_for_destruction? (returns false). From dchelimsky at gmail.com Sun Oct 10 18:57:34 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 10 Oct 2010 17:57:34 -0500 Subject: [rspec-users] RSpec-2.0.0 is released! Message-ID: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> ## RSpec-2.0.0 has been released! This marks the end of a year-long effort that improves RSpec in a number of ways, including modularity, cleaner code, and much better integration with Rails-3 than was possible before (see http://blog.davidchelimsky.net/2010/01/25/rspec-20-in-the-works/). ### Docs, with a little bit of relish In addition to the documentation available at all the places (see http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/), we've also got all of the Cucumber features posted to Justin Ko's new Cucumber presentation app, relish. http://relishapp.com/rspec We'll also have the RDoc up on http://rdoc.info in a day or so. ### Thanks! Big thanks to 80+ contributors who submitted patches for RSpec-2.0.0, including [1]: Aan, Adam Walters, Akira Matsuda, Alex Crichton, Anderson Dias, Andre Arko, Andreas Neuhaus, Ashley Moran, Ben Armston, Ben Rady, Brasten Sager, Brian J Reath, Carlhuda, Chad Humphries, Charles Lowell, Chris Redinger, Chuck Remes, Corey Ehmke, Corey Haines, Dan Peterson, Dave Newman, David Genord II, David S. Kang, Ethan Gunderson, Gon?alo Silva, Greg Sterndale, Hans de Graaff, Iain Hecker, Jacques Crocker, Jean-Daniel Guyot, Jeff Ramnani, Jim Breen, Johan Kiviniemi, Josep M? Bach, Josh Graham, Joshua Nichols, Kabari Hendrick, Kristian M, Lailson B, Len Smith, Leonardo Bessa, Les Hill, Luis Lavena, Marcin Kulik, Markus Schirp, Matt Remsik, Matt Yoho, Matthew Todd, Michael Niessner, Mike Gehard, Myron Marston, Nate Jackson, Neeraj Singh, Nestor Ovroy, Nick Ang, Nicolas Braem, Paul Rosania, Phil Smith, Postmodern, Prasad, Rob Sanheim, Roman Chernyatchik, Ryan Bigg, Ryan Briones, Sam Pohlenz, Scott Taylor, Shin-ichiro OGAWA, Thibaud Guillaume-Gentil, Tim Connor, Tim Harper, Tom Stuart, V?t Ondruch, Wincent Colaiuta, aslakhellesoy, eira, garren smith, grosser, hasimo, justinko, rup, speedmax, wycats Extra special thanks go to: * Chad Humphries for contributing his Micronaut gem which is the basis for rspec-core-2 * Yehuda Katz, Carl Lerche, and Jos? Valim, for their assistance with getting rspec-rails-2 to take advantage of new APIs in Rails-3, and for shepherding patches to Rails that made it far simpler for testing extensions like rspec-rails to hook into Rails' testing infrastructure. Their work here has significantly reduced the risk that Rails point-releases will break rspec-rails. * Myron Marston for a wealth of thoughtful contributions including Cucumber features that we can all learn from * Justin Ko for his direct contributions to rspec, and for relish (http://relishapp.com/), which makes executable documentation act more like documentation. ### What's next? #### rspec-rails-2 for rails-2 There are a couple of projects floating around that support rspec-2 and rails-2. I haven't had the chance to review any of these myself, but my hope is that we'll have be an official rspec-2 for rails-2 gem in the coming months. #### rspec-1 maintenance rspec-1 will continue to get maintenance releases, but these will be restricted, primarily, to bug fixes. Any new features will go into rspec-2, and will likely not be back-ported. [1] Contributor names were generated from the git commit logs. From sarahg.gray at gmail.com Sun Oct 10 19:36:15 2010 From: sarahg.gray at gmail.com (Sarah Gray) Date: Sun, 10 Oct 2010 18:36:15 -0500 Subject: [rspec-users] RSpec-2.0.0 is released! In-Reply-To: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> References: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> Message-ID: Congratulations! And thank you. On Sun, Oct 10, 2010 at 5:57 PM, David Chelimsky wrote: > ## RSpec-2.0.0 has been released! > > This marks the end of a year-long effort that improves RSpec in a number of > ways, including modularity, cleaner code, and much better integration with > Rails-3 than was possible before (see > http://blog.davidchelimsky.net/2010/01/25/rspec-20-in-the-works/). > > ### Docs, with a little bit of relish > > In addition to the documentation available at all the places (see > http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/), we've > also got all of the Cucumber features posted to Justin Ko's new Cucumber > presentation app, relish. > > http://relishapp.com/rspec > > We'll also have the RDoc up on http://rdoc.info in a day or so. > > ### Thanks! > > Big thanks to 80+ contributors who submitted patches for RSpec-2.0.0, > including [1]: > > Aan, Adam Walters, Akira Matsuda, Alex Crichton, Anderson Dias, Andre Arko, > Andreas Neuhaus, Ashley Moran, Ben Armston, Ben Rady, Brasten Sager, Brian J > Reath, Carlhuda, Chad Humphries, Charles Lowell, Chris Redinger, Chuck > Remes, Corey Ehmke, Corey Haines, Dan Peterson, Dave Newman, David Genord > II, David S. Kang, Ethan Gunderson, Gon?alo Silva, Greg Sterndale, Hans de > Graaff, Iain Hecker, Jacques Crocker, Jean-Daniel Guyot, Jeff Ramnani, Jim > Breen, Johan Kiviniemi, Josep M? Bach, Josh Graham, Joshua Nichols, Kabari > Hendrick, Kristian M, Lailson B, Len Smith, Leonardo Bessa, Les Hill, Luis > Lavena, Marcin Kulik, Markus Schirp, Matt Remsik, Matt Yoho, Matthew Todd, > Michael Niessner, Mike Gehard, Myron Marston, Nate Jackson, Neeraj Singh, > Nestor Ovroy, Nick Ang, Nicolas Braem, Paul Rosania, Phil Smith, Postmodern, > Prasad, Rob Sanheim, Roman Chernyatchik, Ryan Bigg, Ryan Briones, Sam > Pohlenz, Scott Taylor, Shin-ichiro OGAWA, Thibaud Guillaume-Gentil, Tim > Connor, Tim Harper, Tom Stuart, V?t Ondruch, Wincent Colaiuta, > aslakhellesoy, eira, garren smith, grosser, hasimo, justinko, rup, speedmax, > wycats > > Extra special thanks go to: > > * Chad Humphries for contributing his Micronaut gem which is the basis for > rspec-core-2 > * Yehuda Katz, Carl Lerche, and Jos? Valim, for their assistance with > getting rspec-rails-2 to take advantage of new APIs in Rails-3, and for > shepherding patches to Rails that made it far simpler for testing extensions > like rspec-rails to hook into Rails' testing infrastructure. Their work here > has significantly reduced the risk that Rails point-releases will break > rspec-rails. > * Myron Marston for a wealth of thoughtful contributions including Cucumber > features that we can all learn from > * Justin Ko for his direct contributions to rspec, and for relish ( > http://relishapp.com/), which makes executable documentation act more like > documentation. > > ### What's next? > > #### rspec-rails-2 for rails-2 > > There are a couple of projects floating around that support rspec-2 and > rails-2. I haven't had the chance to review any of these myself, but my hope > is that we'll have be an official rspec-2 for rails-2 gem in the coming > months. > > #### rspec-1 maintenance > > rspec-1 will continue to get maintenance releases, but these will be > restricted, primarily, to bug fixes. Any new features will go into rspec-2, > and will likely not be back-ported. > > [1] Contributor names were generated from the git commit logs. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.twitter.com/fablednet http://www.fabled.net/blog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmymartin at gmail.com Mon Oct 11 03:03:50 2010 From: jimmymartin at gmail.com (James Martin) Date: Mon, 11 Oct 2010 08:03:50 +0100 Subject: [rspec-users] RSpec-2.0.0 is released! In-Reply-To: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> References: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> Message-ID: Congrats on reaching this milestone and many thanks to all who contributed. Your efforts are much appreciated! RSpec2 is a massive improvement over 1 and I'm really enjoying using it. Thanks, James. On Sunday, October 10, 2010, David Chelimsky wrote: > ## RSpec-2.0.0 has been released! > > This marks the end of a year-long effort that improves RSpec in a number of ways, including modularity, cleaner code, and much better integration with Rails-3 than was possible before (see http://blog.davidchelimsky.net/2010/01/25/rspec-20-in-the-works/). > > ### Docs, with a little bit of relish > > In addition to the documentation available at all the places (see http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/), we've also got all of the Cucumber features posted to Justin Ko's new Cucumber presentation app, relish. > > ?http://relishapp.com/rspec > > We'll also have the RDoc up on http://rdoc.info in a day or so. > > ### Thanks! > > Big thanks to 80+ contributors who submitted patches for RSpec-2.0.0, including [1]: > > Aan, Adam Walters, Akira Matsuda, Alex Crichton, Anderson Dias, Andre Arko, Andreas Neuhaus, Ashley Moran, Ben Armston, Ben Rady, Brasten Sager, Brian J Reath, Carlhuda, Chad Humphries, Charles Lowell, Chris Redinger, Chuck Remes, Corey Ehmke, Corey Haines, Dan Peterson, Dave Newman, David Genord II, David S. Kang, Ethan Gunderson, Gon?alo Silva, Greg Sterndale, Hans de Graaff, Iain Hecker, Jacques Crocker, Jean-Daniel Guyot, Jeff Ramnani, Jim Breen, Johan Kiviniemi, Josep M? Bach, Josh Graham, Joshua Nichols, Kabari Hendrick, Kristian M, Lailson B, Len Smith, Leonardo Bessa, Les Hill, Luis Lavena, Marcin Kulik, Markus Schirp, Matt Remsik, Matt Yoho, Matthew Todd, Michael Niessner, Mike Gehard, Myron Marston, Nate Jackson, Neeraj Singh, Nestor Ovroy, Nick Ang, Nicolas Braem, Paul Rosania, Phil Smith, Postmodern, Prasad, Rob Sanheim, Roman Chernyatchik, Ryan Bigg, Ryan Briones, Sam Pohlenz, Scott Taylor, Shin-ichiro OGAWA, Thibaud Guillaume-Gentil, Tim Connor, Tim Harper, Tom Stuart, V?t Ondruch, Wincent Colaiuta, aslakhellesoy, eira, garren smith, grosser, hasimo, justinko, rup, speedmax, wycats > > Extra special thanks go to: > > * Chad Humphries for contributing his Micronaut gem which is the basis for rspec-core-2 > * Yehuda Katz, Carl Lerche, and Jos? Valim, for their assistance with getting rspec-rails-2 to take advantage of new APIs in Rails-3, and for shepherding patches to Rails that made it far simpler for testing extensions like rspec-rails to hook into Rails' testing infrastructure. Their work here has significantly reduced the risk that Rails point-releases will break rspec-rails. > * Myron Marston for a wealth of thoughtful contributions including Cucumber features that we can all learn from > * Justin Ko for his direct contributions to rspec, and for relish (http://relishapp.com/), which makes executable documentation act more like documentation. > > ### What's next? > > #### rspec-rails-2 for rails-2 > > There are a couple of projects floating around that support rspec-2 and rails-2. I haven't had the chance to review any of these myself, but my hope is that we'll have be an official rspec-2 for rails-2 gem in the coming months. > > #### rspec-1 maintenance > > rspec-1 will continue to get maintenance releases, but these will be restricted, primarily, to bug fixes. Any new features will go into rspec-2, and will likely not be back-ported. > > [1] Contributor names were generated from the git commit logs. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Oct 11 11:14:29 2010 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 11 Oct 2010 17:14:29 +0200 Subject: [rspec-users] RSpec-2.0.0 is released! In-Reply-To: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> References: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> Message-ID: > ## RSpec-2.0.0 has been released! > > David, I'm so impressed how you have managed to manage a half-rewrite, updating the RSpec book (which now soon goes to print) and coordinating everything with Rails and the 80+ contributors. The upgrade process has been extremely simple for me taken into account all of the great changes that have gone into the release. The end result is shining, and the Cucumber-based Relish docs are absolutely stunning - thanks especially to Justin, Myron and Matt. Good job! Aslak > This marks the end of a year-long effort that improves RSpec in a number of > ways, including modularity, cleaner code, and much better integration with > Rails-3 than was possible before (see > http://blog.davidchelimsky.net/2010/01/25/rspec-20-in-the-works/). > > ### Docs, with a little bit of relish > > In addition to the documentation available at all the places (see > http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/), we've > also got all of the Cucumber features posted to Justin Ko's new Cucumber > presentation app, relish. > > http://relishapp.com/rspec > > We'll also have the RDoc up on http://rdoc.info in a day or so. > > ### Thanks! > > Big thanks to 80+ contributors who submitted patches for RSpec-2.0.0, > including [1]: > > Aan, Adam Walters, Akira Matsuda, Alex Crichton, Anderson Dias, Andre Arko, > Andreas Neuhaus, Ashley Moran, Ben Armston, Ben Rady, Brasten Sager, Brian J > Reath, Carlhuda, Chad Humphries, Charles Lowell, Chris Redinger, Chuck > Remes, Corey Ehmke, Corey Haines, Dan Peterson, Dave Newman, David Genord > II, David S. Kang, Ethan Gunderson, Gon?alo Silva, Greg Sterndale, Hans de > Graaff, Iain Hecker, Jacques Crocker, Jean-Daniel Guyot, Jeff Ramnani, Jim > Breen, Johan Kiviniemi, Josep M? Bach, Josh Graham, Joshua Nichols, Kabari > Hendrick, Kristian M, Lailson B, Len Smith, Leonardo Bessa, Les Hill, Luis > Lavena, Marcin Kulik, Markus Schirp, Matt Remsik, Matt Yoho, Matthew Todd, > Michael Niessner, Mike Gehard, Myron Marston, Nate Jackson, Neeraj Singh, > Nestor Ovroy, Nick Ang, Nicolas Braem, Paul Rosania, Phil Smith, Postmodern, > Prasad, Rob Sanheim, Roman Chernyatchik, Ryan Bigg, Ryan Briones, Sam > Pohlenz, Scott Taylor, Shin-ichiro OGAWA, Thibaud Guillaume-Gentil, Tim > Connor, Tim Harper, Tom Stuart, V?t Ondruch, Wincent Colaiuta, > aslakhellesoy, eira, garren smith, grosser, hasimo, justinko, rup, speedmax, > wycats > > Extra special thanks go to: > > * Chad Humphries for contributing his Micronaut gem which is the basis for > rspec-core-2 > * Yehuda Katz, Carl Lerche, and Jos? Valim, for their assistance with > getting rspec-rails-2 to take advantage of new APIs in Rails-3, and for > shepherding patches to Rails that made it far simpler for testing extensions > like rspec-rails to hook into Rails' testing infrastructure. Their work here > has significantly reduced the risk that Rails point-releases will break > rspec-rails. > * Myron Marston for a wealth of thoughtful contributions including Cucumber > features that we can all learn from > * Justin Ko for his direct contributions to rspec, and for relish ( > http://relishapp.com/), which makes executable documentation act more like > documentation. > > ### What's next? > > #### rspec-rails-2 for rails-2 > > There are a couple of projects floating around that support rspec-2 and > rails-2. I haven't had the chance to review any of these myself, but my hope > is that we'll have be an official rspec-2 for rails-2 gem in the coming > months. > > #### rspec-1 maintenance > > rspec-1 will continue to get maintenance releases, but these will be > restricted, primarily, to bug fixes. Any new features will go into rspec-2, > and will likely not be back-ported. > > [1] Contributor names were generated from the git commit logs. > _______________________________________________ > 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 joe at josephwilk.net Mon Oct 11 11:55:54 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Mon, 11 Oct 2010 16:55:54 +0100 Subject: [rspec-users] RSpec-2.0.0 is released! In-Reply-To: References: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> Message-ID: <4CB3338A.9080206@josephwilk.net> On 11/10/2010 16:14, aslak hellesoy wrote: > > ## RSpec-2.0.0 has been released! > > > David, I'm so impressed how you have managed to manage a half-rewrite, > updating the RSpec book (which now soon goes to print) and > coordinating everything with Rails and the 80+ contributors. The > upgrade process has been extremely simple for me taken into account > all of the great changes that have gone into the release. > > The end result is shining, and the Cucumber-based Relish docs are > absolutely stunning - thanks especially to Justin, Myron and Matt. > > Good job! Here, Here! Thanks David and everyone that put blood, sweat and tears into Rspec 2.0. Much appreciated. -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 > > Aslak > > > This marks the end of a year-long effort that improves RSpec in a > number of ways, including modularity, cleaner code, and much > better integration with Rails-3 than was possible before (see > http://blog.davidchelimsky.net/2010/01/25/rspec-20-in-the-works/). > > ### Docs, with a little bit of relish > > In addition to the documentation available at all the places (see > http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/), > we've also got all of the Cucumber features posted to Justin Ko's > new Cucumber presentation app, relish. > > http://relishapp.com/rspec > > We'll also have the RDoc up on http://rdoc.info in a day or so. > > ### Thanks! > > Big thanks to 80+ contributors who submitted patches for > RSpec-2.0.0, including [1]: > > Aan, Adam Walters, Akira Matsuda, Alex Crichton, Anderson Dias, > Andre Arko, Andreas Neuhaus, Ashley Moran, Ben Armston, Ben Rady, > Brasten Sager, Brian J Reath, Carlhuda, Chad Humphries, Charles > Lowell, Chris Redinger, Chuck Remes, Corey Ehmke, Corey Haines, > Dan Peterson, Dave Newman, David Genord II, David S. Kang, Ethan > Gunderson, Gon?alo Silva, Greg Sterndale, Hans de Graaff, Iain > Hecker, Jacques Crocker, Jean-Daniel Guyot, Jeff Ramnani, Jim > Breen, Johan Kiviniemi, Josep M? Bach, Josh Graham, Joshua > Nichols, Kabari Hendrick, Kristian M, Lailson B, Len Smith, > Leonardo Bessa, Les Hill, Luis Lavena, Marcin Kulik, Markus > Schirp, Matt Remsik, Matt Yoho, Matthew Todd, Michael Niessner, > Mike Gehard, Myron Marston, Nate Jackson, Neeraj Singh, Nestor > Ovroy, Nick Ang, Nicolas Braem, Paul Rosania, Phil Smith, > Postmodern, Prasad, Rob Sanheim, Roman Chernyatchik, Ryan Bigg, > Ryan Briones, Sam Pohlenz, Scott Taylor, Shin-ichiro OGAWA, > Thibaud Guillaume-Gentil, Tim Connor, Tim Harper, Tom Stuart, V?t > Ondruch, Wincent Colaiuta, aslakhellesoy, eira, garren smith, > grosser, hasimo, justinko, rup, speedmax, wycats > > Extra special thanks go to: > > * Chad Humphries for contributing his Micronaut gem which is the > basis for rspec-core-2 > * Yehuda Katz, Carl Lerche, and Jos? Valim, for their assistance > with getting rspec-rails-2 to take advantage of new APIs in > Rails-3, and for shepherding patches to Rails that made it far > simpler for testing extensions like rspec-rails to hook into > Rails' testing infrastructure. Their work here has significantly > reduced the risk that Rails point-releases will break rspec-rails. > * Myron Marston for a wealth of thoughtful contributions including > Cucumber features that we can all learn from > * Justin Ko for his direct contributions to rspec, and for relish > (http://relishapp.com/), which makes executable documentation act > more like documentation. > > ### What's next? > > #### rspec-rails-2 for rails-2 > > There are a couple of projects floating around that support > rspec-2 and rails-2. I haven't had the chance to review any of > these myself, but my hope is that we'll have be an official > rspec-2 for rails-2 gem in the coming months. > > #### rspec-1 maintenance > > rspec-1 will continue to get maintenance releases, but these will > be restricted, primarily, to bug fixes. Any new features will go > into rspec-2, and will likely not be back-ported. > > [1] Contributor names were generated from the git commit logs. > _______________________________________________ > 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 jko170 at gmail.com Mon Oct 11 12:13:14 2010 From: jko170 at gmail.com (Justin Ko) Date: Mon, 11 Oct 2010 09:13:14 -0700 (PDT) Subject: [rspec-users] RSpec-2.0.0 is released! In-Reply-To: References: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> Message-ID: On Oct 11, 11:14?am, aslak hellesoy wrote: > > ## RSpec-2.0.0 has been released! > > David, I'm so impressed how you have managed to manage a half-rewrite, > updating the RSpec book (which now soon goes to print) and coordinating > everything with Rails and the 80+ contributors. The upgrade process has been > extremely simple for me taken into account all of the great changes that > have gone into the release. > > The end result is shining, and the Cucumber-based Relish docs are absolutely > stunning - thanks especially to Justin, Myron and Matt. > > Good job! > > Aslak > > > > > This marks the end of a year-long effort that improves RSpec in a number of > > ways, including modularity, cleaner code, and much better integration with > > Rails-3 than was possible before (see > >http://blog.davidchelimsky.net/2010/01/25/rspec-20-in-the-works/). > > > ### Docs, with a little bit of relish > > > In addition to the documentation available at all the places (see > >http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/), we've > > also got all of the Cucumber features posted to Justin Ko's new Cucumber > > presentation app, relish. > > > ?http://relishapp.com/rspec > > > We'll also have the RDoc up onhttp://rdoc.infoin a day or so. > > > ### Thanks! > > > Big thanks to 80+ contributors who submitted patches for RSpec-2.0.0, > > including [1]: > > > Aan, Adam Walters, Akira Matsuda, Alex Crichton, Anderson Dias, Andre Arko, > > Andreas Neuhaus, Ashley Moran, Ben Armston, Ben Rady, Brasten Sager, Brian J > > Reath, Carlhuda, Chad Humphries, Charles Lowell, Chris Redinger, Chuck > > Remes, Corey Ehmke, Corey Haines, Dan Peterson, Dave Newman, David Genord > > II, David S. Kang, Ethan Gunderson, Gon?alo Silva, Greg Sterndale, Hans de > > Graaff, Iain Hecker, Jacques Crocker, Jean-Daniel Guyot, Jeff Ramnani, Jim > > Breen, Johan Kiviniemi, Josep M? Bach, Josh Graham, Joshua Nichols, Kabari > > Hendrick, Kristian M, Lailson B, Len Smith, Leonardo Bessa, Les Hill, Luis > > Lavena, Marcin Kulik, Markus Schirp, Matt Remsik, Matt Yoho, Matthew Todd, > > Michael Niessner, Mike Gehard, Myron Marston, Nate Jackson, Neeraj Singh, > > Nestor Ovroy, Nick Ang, Nicolas Braem, Paul Rosania, Phil Smith, Postmodern, > > Prasad, Rob Sanheim, Roman Chernyatchik, Ryan Bigg, Ryan Briones, Sam > > Pohlenz, Scott Taylor, Shin-ichiro OGAWA, Thibaud Guillaume-Gentil, Tim > > Connor, Tim Harper, Tom Stuart, V?t Ondruch, Wincent Colaiuta, > > aslakhellesoy, eira, garren smith, grosser, hasimo, justinko, rup, speedmax, > > wycats > > > Extra special thanks go to: > > > * Chad Humphries for contributing his Micronaut gem which is the basis for > > rspec-core-2 > > * Yehuda Katz, Carl Lerche, and Jos? Valim, for their assistance with > > getting rspec-rails-2 to take advantage of new APIs in Rails-3, and for > > shepherding patches to Rails that made it far simpler for testing extensions > > like rspec-rails to hook into Rails' testing infrastructure. Their work here > > has significantly reduced the risk that Rails point-releases will break > > rspec-rails. > > * Myron Marston for a wealth of thoughtful contributions including Cucumber > > features that we can all learn from > > * Justin Ko for his direct contributions to rspec, and for relish ( > >http://relishapp.com/), which makes executable documentation act more like > > documentation. > > > ### What's next? > > > #### rspec-rails-2 for rails-2 > > > There are a couple of projects floating around that support rspec-2 and > > rails-2. I haven't had the chance to review any of these myself, but my hope > > is that we'll have be an official rspec-2 for rails-2 gem in the coming > > months. > > > #### rspec-1 maintenance > > > rspec-1 will continue to get maintenance releases, but these will be > > restricted, primarily, to bug fixes. Any new features will go into rspec-2, > > and will likely not be back-ported. > > > [1] Contributor names were generated from the git commit logs. > > _______________________________________________ > > 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 Thank you for the kind words Aslak! Obviously, Relish could not have been built if it weren't for Cucumber's amazing internal functionality/ api. It made things extremely easy for Relish. David's level of productive output really does boggle my mind. The Ruby community is extremely lucky to have him. Thank you everyone for RSpec 2! From dan at dannorth.net Mon Oct 11 17:06:56 2010 From: dan at dannorth.net (Dan North) Date: Mon, 11 Oct 2010 22:06:56 +0100 Subject: [rspec-users] RSpec-2.0.0 is released! In-Reply-To: References: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> Message-ID: What Aslak said. A lot. Good job indeed. Cheers, Dan On 11 October 2010 16:14, aslak hellesoy wrote: > > ## RSpec-2.0.0 has been released! >> >> > David, I'm so impressed how you have managed to manage a half-rewrite, > updating the RSpec book (which now soon goes to print) and coordinating > everything with Rails and the 80+ contributors. The upgrade process has been > extremely simple for me taken into account all of the great changes that > have gone into the release. > > The end result is shining, and the Cucumber-based Relish docs are > absolutely stunning - thanks especially to Justin, Myron and Matt. > > Good job! > > Aslak > > >> This marks the end of a year-long effort that improves RSpec in a number >> of ways, including modularity, cleaner code, and much better integration >> with Rails-3 than was possible before (see >> http://blog.davidchelimsky.net/2010/01/25/rspec-20-in-the-works/). >> >> ### Docs, with a little bit of relish >> >> In addition to the documentation available at all the places (see >> http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/), we've >> also got all of the Cucumber features posted to Justin Ko's new Cucumber >> presentation app, relish. >> >> http://relishapp.com/rspec >> >> We'll also have the RDoc up on http://rdoc.info in a day or so. >> >> ### Thanks! >> >> Big thanks to 80+ contributors who submitted patches for RSpec-2.0.0, >> including [1]: >> >> Aan, Adam Walters, Akira Matsuda, Alex Crichton, Anderson Dias, Andre >> Arko, Andreas Neuhaus, Ashley Moran, Ben Armston, Ben Rady, Brasten Sager, >> Brian J Reath, Carlhuda, Chad Humphries, Charles Lowell, Chris Redinger, >> Chuck Remes, Corey Ehmke, Corey Haines, Dan Peterson, Dave Newman, David >> Genord II, David S. Kang, Ethan Gunderson, Gon?alo Silva, Greg Sterndale, >> Hans de Graaff, Iain Hecker, Jacques Crocker, Jean-Daniel Guyot, Jeff >> Ramnani, Jim Breen, Johan Kiviniemi, Josep M? Bach, Josh Graham, Joshua >> Nichols, Kabari Hendrick, Kristian M, Lailson B, Len Smith, Leonardo Bessa, >> Les Hill, Luis Lavena, Marcin Kulik, Markus Schirp, Matt Remsik, Matt Yoho, >> Matthew Todd, Michael Niessner, Mike Gehard, Myron Marston, Nate Jackson, >> Neeraj Singh, Nestor Ovroy, Nick Ang, Nicolas Braem, Paul Rosania, Phil >> Smith, Postmodern, Prasad, Rob Sanheim, Roman Chernyatchik, Ryan Bigg, Ryan >> Briones, Sam Pohlenz, Scott Taylor, Shin-ichiro OGAWA, Thibaud >> Guillaume-Gentil, Tim Connor, Tim Harper, Tom Stuart, V?t Ondruch, Wincent >> Colaiuta, aslakhellesoy, eira, garren smith, grosser, hasimo, justinko, rup, >> speedmax, wycats >> >> Extra special thanks go to: >> >> * Chad Humphries for contributing his Micronaut gem which is the basis for >> rspec-core-2 >> * Yehuda Katz, Carl Lerche, and Jos? Valim, for their assistance with >> getting rspec-rails-2 to take advantage of new APIs in Rails-3, and for >> shepherding patches to Rails that made it far simpler for testing extensions >> like rspec-rails to hook into Rails' testing infrastructure. Their work here >> has significantly reduced the risk that Rails point-releases will break >> rspec-rails. >> * Myron Marston for a wealth of thoughtful contributions including >> Cucumber features that we can all learn from >> * Justin Ko for his direct contributions to rspec, and for relish ( >> http://relishapp.com/), which makes executable documentation act more >> like documentation. >> >> ### What's next? >> >> #### rspec-rails-2 for rails-2 >> >> There are a couple of projects floating around that support rspec-2 and >> rails-2. I haven't had the chance to review any of these myself, but my hope >> is that we'll have be an official rspec-2 for rails-2 gem in the coming >> months. >> >> #### rspec-1 maintenance >> >> rspec-1 will continue to get maintenance releases, but these will be >> restricted, primarily, to bug fixes. Any new features will go into rspec-2, >> and will likely not be back-ported. >> >> [1] Contributor names were generated from the git commit logs. >> _______________________________________________ >> 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 matt at matt-darby.com Tue Oct 5 09:03:55 2010 From: matt at matt-darby.com (Matt Darby) Date: Tue, 5 Oct 2010 06:03:55 -0700 (PDT) Subject: [rspec-users] render_template giving an odd error? Message-ID: <24eee1d2-e4a2-4002-b07f-be7ed0eb556c@c10g2000yqh.googlegroups.com> Hey all, I'm trying to migrate over to Rails3/RSpec2 and I cannot seem to get the specing of `render` right. I know there was some changes in RSpec2 that affect this, and I was hoping to get a bit of help. I have this is in a before block in a view spec: view.should render_template("attachments/index", :locals => {:obj => @obj}) When I run the spec, it bombs out with this error: expecting <"attachments/index"> but rendering with <"">. Expected block to return true value. This doesn't tell me much, and aside from the RSpec2 syntax updates the spec hasn't changed (and used to work in Rails2). This is a huge blocker for my app migration. I have 150+ models and use partials pretty often. Help is appreciated! From cyruscavalcante at gmail.com Wed Oct 6 13:44:54 2010 From: cyruscavalcante at gmail.com (Cyrus) Date: Wed, 6 Oct 2010 10:44:54 -0700 (PDT) Subject: [rspec-users] how to test named_scope Message-ID: how a can test this controller using rspec #home controller def home @recents = Article.publisheds.with_authorship.paginate(:page => 1, :per_page => 10, :total_entries => 10) @highlight = Article.publisheds.highlight.with_authorship end #article model named_scope :publisheds, lambda { { :conditions => ["published_at <= ? and status = 'publicado'", Time.now.utc] } } named_scope :highlight, lambda { { :conditions => ["highlight IS NOT NULL and highlight <> ''"], :order => "highlight desc, published_at desc", :limit => 4 } } named_scope :with_authorship, :include => [:authorships, :authors] i do this bat dont work: describe GeneralController do def mock_article(stubs={}) @mock_article ||= mock_model(Article, stubs) end describe "GET index" do it "should expose article as @articles" do articles = [mock_article] Article.should_receive(:publisheds).and_return(articles) articles.should_receive(:with_authorship).and_return(articles) articles.should_receive(:paginate).with(:per_page => 10,:total_entries=>10, :page => 1).and_return(articles) get :home assigns[:recents].should == articles end end end From campanolix at rhapsody.com Wed Oct 6 17:44:56 2010 From: campanolix at rhapsody.com (Xeno Campanoli) Date: Wed, 6 Oct 2010 16:44:56 -0500 Subject: [rspec-users] I am trying to subscribe to this group, and Google is saying: Message-ID: There is a problem with your choice of subscription type No other comment? WTF? W$7 install on Xeno's RI Laptop. -------------- next part -------------- An HTML attachment was scrubbed... URL: From campanolix at rhapsody.com Wed Oct 6 17:49:39 2010 From: campanolix at rhapsody.com (Xeno Campanoli) Date: Wed, 6 Oct 2010 16:49:39 -0500 Subject: [rspec-users] I am trying to find out a way to use the Selenium facility to get cross browser support in some simple way Message-ID: I would be glad to see: 1. Generation of usable Selenium Core Test Suites. 2. Instructions to create a proxy server to run the tests, like with Selenium Grid or some such thing. 3. Any other thing that allows me to run the Cucumber/RSpec tests without having to have the installation on the same machine as the browser. xc W$7 install on Xeno's RI Laptop. -------------- next part -------------- An HTML attachment was scrubbed... URL: From imoryc at gmail.com Thu Oct 7 10:24:19 2010 From: imoryc at gmail.com (ignacy.moryc) Date: Thu, 7 Oct 2010 07:24:19 -0700 (PDT) Subject: [rspec-users] Testing methods that yields a block Message-ID: <24c14042-b009-4a87-9efe-1f9d3e825b65@z28g2000yqh.googlegroups.com> I want to test a class method that sets some state and then yields a block. It looks something like that: class Cat class << self def start id = get_uuid begin yield if block_given? ensure set_some_other_state end end end #... end How can I test that id field was set? Or that set_some_other_state method was called, if I intend to use this class like this: Cat.start do # do what cat's do end I'm trying to do this like this: Cat.start { #some block } Cat.id.should be_something but this doesn't work. I also used: Cat.should_receive(:id=).once Cat.start {#some block} but this doesn't let me see to what the id field was set. Is there a better way to test this method? Thanks, From mack.talcott at gmail.com Mon Oct 11 13:05:16 2010 From: mack.talcott at gmail.com (Mack) Date: Mon, 11 Oct 2010 10:05:16 -0700 (PDT) Subject: [rspec-users] Nested attributes in fixtures Message-ID: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> I'm unable to get nested attributes in fixtures to work with Rspec. The models and fixtures function fine outside of rspec, but I get a mysql error (Unknown column "_attributes) when running tests with the same fixtures. I am able to get the specs to run by creating a separate fixture for the nested table. Shouldn't Rspec handle nested attributes in fixtures, though? From mail at russellquinn.com Fri Oct 8 20:20:49 2010 From: mail at russellquinn.com (Russell Quinn) Date: Fri, 8 Oct 2010 17:20:49 -0700 (PDT) Subject: [rspec-users] DateTime.now.utc in fixtures Message-ID: <9aa875c1-3f1e-4895-859b-83403b202988@g18g2000yqk.googlegroups.com> I have the following in my fixtures: publish_date: <%= DateTime.now.utc - 1.day %> But 'DateTime.now.utc' always evaluates to my system time. Does anyone have any ideas? Thanks, Russell. From dchelimsky at gmail.com Tue Oct 12 02:03:14 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Oct 2010 01:03:14 -0500 Subject: [rspec-users] Testing methods that yields a block In-Reply-To: <24c14042-b009-4a87-9efe-1f9d3e825b65@z28g2000yqh.googlegroups.com> References: <24c14042-b009-4a87-9efe-1f9d3e825b65@z28g2000yqh.googlegroups.com> Message-ID: On Thu, Oct 7, 2010 at 9:24 AM, ignacy.moryc wrote: > I want to test a class method that sets some state and then yields a > block. It looks something like that: > > class Cat > ?class << self > ? ? def start > ? ? ? ? ? id = get_uuid > ? ? ? ? ? begin > ? ? ? ? ? ? ?yield if block_given? > ? ? ? ? ? ensure > ? ? ? ? ? ? ? set_some_other_state > ? ? ? ? ? end > ? ? end > ? end > ? #... > end > > How can I test that id field was set? Or that set_some_other_state > method was called, if I intend to use this class like this: > > Cat.start do > ? # do what cat's do > end > > I'm trying to do this like this: > > Cat.start { #some block } > Cat.id.should be_something > > but this doesn't work. What do you mean "doesn't work"? Are you getting a failure message? What does it say? > > I also used: > > Cat.should_receive(:id=).once > Cat.start {#some block} > > but this doesn't let me see to what the id field was set. > > Is there a better way to test this method? > > Thanks, > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Oct 12 02:07:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Oct 2010 01:07:39 -0500 Subject: [rspec-users] Nested attributes in fixtures In-Reply-To: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> References: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> Message-ID: On Mon, Oct 11, 2010 at 12:05 PM, Mack wrote: > I'm unable to get nested attributes in fixtures to work with Rspec. > The models and fixtures function fine outside of rspec, but I get a > mysql error (Unknown column "_attributes) when running > tests with the same fixtures. > > I am able to get the specs to run by creating a separate fixture for > the nested table. ?Shouldn't Rspec handle nested attributes in > fixtures, though? The only fixture support provided by RSpec are hooks into the Rails configuration to tell it where fixtures are stored, whether to use instantiated fixtures, and whether to use transactions around each example. There is no specific support for fixture loading - that all comes from Rails. That said, maybe we can help you, but you'll need to provide some more info: * rspec version * rails version * spec code * implementation code * _full_ failure message Code and failure messages are fine in email or in gists. Cheers, David From dchelimsky at gmail.com Tue Oct 12 02:17:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Oct 2010 01:17:03 -0500 Subject: [rspec-users] render_template giving an odd error? In-Reply-To: <24eee1d2-e4a2-4002-b07f-be7ed0eb556c@c10g2000yqh.googlegroups.com> References: <24eee1d2-e4a2-4002-b07f-be7ed0eb556c@c10g2000yqh.googlegroups.com> Message-ID: On Tue, Oct 5, 2010 at 8:03 AM, Matt Darby wrote: > Hey all, I'm trying to migrate over to Rails3/RSpec2 and I cannot seem > to get the specing of `render` right. I know there was some changes in > RSpec2 that affect this, and I was hoping to get a bit of help. > > I have this is in a before block in a view spec: > > view.should render_template("attachments/index", :locals => {:obj => > @obj}) In rspec-2 you need to specify templates _after_ rendering: it " .... " do render view.should render_template("...") end > > When I run the spec, it bombs out with this error: > > expecting <"attachments/index"> but rendering with <"">. > Expected block to return true value. > > This doesn't tell me much, and aside from the RSpec2 syntax updates > the spec hasn't changed (and used to work in Rails2). In rspec-rails-1/rails-2, rspec monkey-patched the )(*&)(* out of rails to be able to do things like mock partial calls, etc. This led to a world of pain from release to release, so we're not doing that anymore. The bad news is that you need to set up all the necessary data to render any partials rendered by your views. The good news is you can still specify which templates get rendered, as described above. > This is a huge blocker for my app migration. I have 150+ models and > use partials pretty often. > > Help is appreciated! HTH, David From dchelimsky at gmail.com Tue Oct 12 02:37:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Oct 2010 01:37:12 -0500 Subject: [rspec-users] how to test named_scope In-Reply-To: References: Message-ID: On Wed, Oct 6, 2010 at 12:44 PM, Cyrus wrote: > how a can test this controller using rspec > > #home controller > ?def home > ? ? ?@recents = Article.publisheds.with_authorship.paginate(:page => 1, :per_page => 10, :total_entries => 10) > ? ? ?@highlight = Article.publisheds.highlight.with_authorship > ?end You can do this with stub_chain, but I would not recommend it: describe "GET home" do it "assigns recent articles to @recents" do recent = mock_model(Article) Article.stub_chain("publisheds.with_authorship.paginate") { [recent] } assigns(:recents).should eq(recents) end it "assigns the highlight to @highlight" do highlight = mock_model(Highlight) Article.stub_chain("publisheds.highlight.with_authorship") { highlight } assigns(:highlight).should eq(highlight) end end Instead, I'd recommend using the spec (written _first_) to drive out simpler APIs on Article. describe "GET home" do before do Article.stub(:recents) Article.stub(:highlight) end it "assigns recent articles to @recents" do recents = [mock_model(Article)] Article.stub(:recents) { recents } get :home assigns(:recents).should eq(recents) end it "paginates the recent articles" do recents = [mock_model(Article)] recents.should_receive(:paginate).with(:page => 1, :per_page => 10, :total_entries => 10) get :home end it "assigns the highlight to @highlight" do highlight = mock_model(Highlight) Article.stub(:highlight) { highlight } assigns(:highlight).should eq(highlight) end end Now the controller code gets a bit simpler: def home @recents = Article.recents.paginate(:page => 1, :per_page => 10, :total_entries => 10) @highlight = Article.highlight end And the examples specify the assorted responsibilities. Now you can spec the recents and highlight methods on the Article model, but instead of mentioning the named scopes and trying to stub everything that happens internally on Article, just set up the example data that you need: describe "recents" do it "includes articles written within the past two weeks" do too_old = Factory(:article, :published_at => 15.days.ago) just_young_enough = Factory(:article, :published_at => 14.days.ago) more_than_young_enough = Factory(:article, :published_at => 13.days.ago) Article.recents.should =~ [just_young_enough, more_than_young_enough] end end etc, etc. This way the responsibilities are nicely separated, the surface area between the controller and the model is smaller and more targeted, and you are free to refactor Article below a simpler API. HTH, David > > > #article model > > ?named_scope :publisheds, lambda { { :conditions => ["published_at > <= ? and status = 'publicado'", Time.now.utc] } } > ?named_scope :highlight, lambda { { :conditions => ["highlight IS NOT > NULL and highlight <> ''"], ?:order => "highlight desc, published_at > desc", :limit => 4 } } > named_scope :with_authorship, :include => [:authorships, :authors] > > > i do this bat dont work: > > > describe GeneralController do > ?def mock_article(stubs={}) > ? ?@mock_article ||= mock_model(Article, stubs) > ?end > > ?describe "GET index" do > ? ?it "should expose article as @articles" do > ? ? ?articles = [mock_article] > ? ? ?Article.should_receive(:publisheds).and_return(articles) > ? ? ?articles.should_receive(:with_authorship).and_return(articles) > ? ? ?articles.should_receive(:paginate).with(:per_page => > 10,:total_entries=>10, :page => 1).and_return(articles) > ? ? ?get :home > ? ? ?assigns[:recents].should == articles > ? ?end > end > end From jbrainsberger at gmail.com Tue Oct 12 05:57:02 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Tue, 12 Oct 2010 12:57:02 +0300 Subject: [rspec-users] DateTime.now.utc in fixtures In-Reply-To: <9aa875c1-3f1e-4895-859b-83403b202988@g18g2000yqk.googlegroups.com> References: <9aa875c1-3f1e-4895-859b-83403b202988@g18g2000yqk.googlegroups.com> Message-ID: <4CB430EE.1090803@gmail.com> Russell Quinn wrote: > I have the following in my fixtures: > > publish_date:<%= DateTime.now.utc - 1.day %> > > But 'DateTime.now.utc' always evaluates to my system time. Does anyone > have any ideas? You might not like it, but what about fixing the date? -- J. B. Rainsberger :: http://www.jbrains.ca :: http://www.thecodewhisperer.com From tomk32 at gmx.de Tue Oct 12 06:06:00 2010 From: tomk32 at gmx.de (Thomas R. Koll) Date: Tue, 12 Oct 2010 12:06:00 +0200 Subject: [rspec-users] DateTime.now.utc in fixtures In-Reply-To: <9aa875c1-3f1e-4895-859b-83403b202988@g18g2000yqk.googlegroups.com> References: <9aa875c1-3f1e-4895-859b-83403b202988@g18g2000yqk.googlegroups.com> Message-ID: Hi, It might sound strange, but you usually stub Time.now Read here: http://ariejan.net/2008/11/05/rspecing-with-timenow/ Am 09.10.2010 um 02:20 schrieb Russell Quinn: > I have the following in my fixtures: > > publish_date: <%= DateTime.now.utc - 1.day %> > > But 'DateTime.now.utc' always evaluates to my system time. Does anyone > have any ideas? -- Thomas R. "TomK32" Koll just a geek trying to change the world http://ananasblau.com || http://photostre.am || http://photolog.at From lailsonbm at gmail.com Tue Oct 12 08:41:52 2010 From: lailsonbm at gmail.com (Lailson Bandeira) Date: Tue, 12 Oct 2010 09:41:52 -0300 Subject: [rspec-users] RSpec-2.0.0 is released! In-Reply-To: References: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> Message-ID: David's level of productive output really does boggle my mind. The Ruby community is extremely lucky to have him. [2] =D Great job, David! -- LAILSON BANDEIRA http://lailsonbandeira.com/ On Mon, Oct 11, 2010 at 6:06 PM, Dan North wrote: > What Aslak said. A lot. > > Good job indeed. > > Cheers, > Dan > > > On 11 October 2010 16:14, aslak hellesoy wrote: > >> >> ## RSpec-2.0.0 has been released! >>> >>> >> David, I'm so impressed how you have managed to manage a half-rewrite, >> updating the RSpec book (which now soon goes to print) and coordinating >> everything with Rails and the 80+ contributors. The upgrade process has been >> extremely simple for me taken into account all of the great changes that >> have gone into the release. >> >> The end result is shining, and the Cucumber-based Relish docs are >> absolutely stunning - thanks especially to Justin, Myron and Matt. >> >> Good job! >> >> Aslak >> >> >>> This marks the end of a year-long effort that improves RSpec in a number >>> of ways, including modularity, cleaner code, and much better integration >>> with Rails-3 than was possible before (see >>> http://blog.davidchelimsky.net/2010/01/25/rspec-20-in-the-works/). >>> >>> ### Docs, with a little bit of relish >>> >>> In addition to the documentation available at all the places (see >>> http://blog.davidchelimsky.net/2010/07/01/rspec-2-documentation/), we've >>> also got all of the Cucumber features posted to Justin Ko's new Cucumber >>> presentation app, relish. >>> >>> http://relishapp.com/rspec >>> >>> We'll also have the RDoc up on http://rdoc.info in a day or so. >>> >>> ### Thanks! >>> >>> Big thanks to 80+ contributors who submitted patches for RSpec-2.0.0, >>> including [1]: >>> >>> Aan, Adam Walters, Akira Matsuda, Alex Crichton, Anderson Dias, Andre >>> Arko, Andreas Neuhaus, Ashley Moran, Ben Armston, Ben Rady, Brasten Sager, >>> Brian J Reath, Carlhuda, Chad Humphries, Charles Lowell, Chris Redinger, >>> Chuck Remes, Corey Ehmke, Corey Haines, Dan Peterson, Dave Newman, David >>> Genord II, David S. Kang, Ethan Gunderson, Gon?alo Silva, Greg Sterndale, >>> Hans de Graaff, Iain Hecker, Jacques Crocker, Jean-Daniel Guyot, Jeff >>> Ramnani, Jim Breen, Johan Kiviniemi, Josep M? Bach, Josh Graham, Joshua >>> Nichols, Kabari Hendrick, Kristian M, Lailson B, Len Smith, Leonardo Bessa, >>> Les Hill, Luis Lavena, Marcin Kulik, Markus Schirp, Matt Remsik, Matt Yoho, >>> Matthew Todd, Michael Niessner, Mike Gehard, Myron Marston, Nate Jackson, >>> Neeraj Singh, Nestor Ovroy, Nick Ang, Nicolas Braem, Paul Rosania, Phil >>> Smith, Postmodern, Prasad, Rob Sanheim, Roman Chernyatchik, Ryan Bigg, Ryan >>> Briones, Sam Pohlenz, Scott Taylor, Shin-ichiro OGAWA, Thibaud >>> Guillaume-Gentil, Tim Connor, Tim Harper, Tom Stuart, V?t Ondruch, Wincent >>> Colaiuta, aslakhellesoy, eira, garren smith, grosser, hasimo, justinko, rup, >>> speedmax, wycats >>> >>> Extra special thanks go to: >>> >>> * Chad Humphries for contributing his Micronaut gem which is the basis >>> for rspec-core-2 >>> * Yehuda Katz, Carl Lerche, and Jos? Valim, for their assistance with >>> getting rspec-rails-2 to take advantage of new APIs in Rails-3, and for >>> shepherding patches to Rails that made it far simpler for testing extensions >>> like rspec-rails to hook into Rails' testing infrastructure. Their work here >>> has significantly reduced the risk that Rails point-releases will break >>> rspec-rails. >>> * Myron Marston for a wealth of thoughtful contributions including >>> Cucumber features that we can all learn from >>> * Justin Ko for his direct contributions to rspec, and for relish ( >>> http://relishapp.com/), which makes executable documentation act more >>> like documentation. >>> >>> ### What's next? >>> >>> #### rspec-rails-2 for rails-2 >>> >>> There are a couple of projects floating around that support rspec-2 and >>> rails-2. I haven't had the chance to review any of these myself, but my hope >>> is that we'll have be an official rspec-2 for rails-2 gem in the coming >>> months. >>> >>> #### rspec-1 maintenance >>> >>> rspec-1 will continue to get maintenance releases, but these will be >>> restricted, primarily, to bug fixes. Any new features will go into rspec-2, >>> and will likely not be back-ported. >>> >>> [1] Contributor names were generated from the git commit logs. >>> _______________________________________________ >>> 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 >> > > > _______________________________________________ > 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 rick.denatale at gmail.com Tue Oct 12 08:51:03 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 12 Oct 2010 08:51:03 -0400 Subject: [rspec-users] DateTime.now.utc in fixtures In-Reply-To: References: <9aa875c1-3f1e-4895-859b-83403b202988@g18g2000yqk.googlegroups.com> Message-ID: On Tue, Oct 12, 2010 at 6:06 AM, Thomas R. Koll wrote: > Hi, > > It might sound strange, but you usually stub Time.now > Read here: http://ariejan.net/2008/11/05/rspecing-with-timenow/ I used to do this myself even with Test::Unit http://talklikeaduck.denhaven2.com/2007/07/18/time-flies-while-youre-having-fun-testing More recently I've been using timecop http://github.com/jtrupiano/timecop It allows time to be either frozen or offset, and it stubs Time, DateTime and Date to do the right thing. -- Rick DeNatale Help fund my talk at Ruby Conf 2010:http://pledgie.com/campaigns/13677 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 rick.denatale at gmail.com Tue Oct 12 09:06:43 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 12 Oct 2010 09:06:43 -0400 Subject: [rspec-users] RSpec-2.0.0 is released! In-Reply-To: References: <375A9EFC-4DEB-43D0-9E99-664BA3099555@gmail.com> Message-ID: On Tue, Oct 12, 2010 at 8:41 AM, Lailson Bandeira wrote: > David's level of productive output really does boggle my mind. The > Ruby community is extremely lucky to have him. [2] =D > Great job, David! Let's hope that David is rested and ready to do some more jamming at Ruby Conf next month. http://www.youtube.com/v/kEaB-Di89S8 -- Rick DeNatale Help fund my talk at Ruby Conf 2010:http://pledgie.com/campaigns/13677 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 cflipse at gmail.com Tue Oct 12 12:18:10 2010 From: cflipse at gmail.com (Chris Flipse) Date: Tue, 12 Oct 2010 12:18:10 -0400 Subject: [rspec-users] Testing methods that yields a block In-Reply-To: <24c14042-b009-4a87-9efe-1f9d3e825b65@z28g2000yqh.googlegroups.com> References: <24c14042-b009-4a87-9efe-1f9d3e825b65@z28g2000yqh.googlegroups.com> Message-ID: On Thu, Oct 7, 2010 at 10:24 AM, ignacy.moryc wrote: > I want to test a class method that sets some state and then yields a > block. It looks something like that: > > class Cat > class << self > def start > id = get_uuid > begin > yield if block_given? > ensure > set_some_other_state > end > end > end > #... > end > > How can I test that id field was set? Or that set_some_other_state > method was called, if I intend to use this class like this: > > Cat.start do > # do what cat's do > end > > I'm trying to do this like this: > > Cat.start { #some block } > Cat.id.should be_something > > but this doesn't work. > > I also used: > > Cat.should_receive(:id=).once > Cat.start {#some block} > > but this doesn't let me see to what the id field was set. > > I think you're seeing a legitimate failure ... You're tripping up against a scoping problem in the line where you set the id. You're setting a _local_ variable "id" to the value, which falls out of scope by the time your spec is verifying anything. You'll need something more like: self.id = get_uuid (and possibly an attr_accessor definition for :id as well ...) > Is there a better way to test this method? > > Thanks, > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- // anything worth taking seriously is worth making fun of // http://blog.devcaffeine.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From myron.marston at gmail.com Tue Oct 12 17:02:12 2010 From: myron.marston at gmail.com (Myron Marston) Date: Tue, 12 Oct 2010 14:02:12 -0700 (PDT) Subject: [rspec-users] Testing methods that yields a block In-Reply-To: <24c14042-b009-4a87-9efe-1f9d3e825b65@z28g2000yqh.googlegroups.com> References: <24c14042-b009-4a87-9efe-1f9d3e825b65@z28g2000yqh.googlegroups.com> Message-ID: <146a63a2-4296-4947-ba61-270eb4e648f1@u10g2000yqk.googlegroups.com> > class Cat > ? class << self > ? ? ?def start > ? ? ? ? ? ?id = get_uuid > ? ? ? ? ? ?begin > ? ? ? ? ? ? ? yield if block_given? > ? ? ? ? ? ?ensure > ? ? ? ? ? ? ? ?set_some_other_state > ? ? ? ? ? ?end > ? ? ?end > ? ?end > ? ?#... > end In spite of the fact that you have an #id= method, `id = get_uuid` is setting a local variable, not invoking the #id= method. Use `self.id = get_uuid` to invoke the method and set the attribute. Myron From nicolo.giorgi at gmail.com Tue Oct 12 10:31:57 2010 From: nicolo.giorgi at gmail.com (Nicolo) Date: Tue, 12 Oct 2010 07:31:57 -0700 (PDT) Subject: [rspec-users] Rails 3 and rspec 2 turning off transactional fixtures per test Message-ID: <7aa2759a-24f7-4918-8f7d-cb89dd53ee77@j18g2000yqd.googlegroups.com> I am having trouble turning off transactional fixtures per test in Rails 3 with rspec 2. I did this successfully with rspec 1.3.1 and rails 2. rspec version is 2.0.0.rc Below is my stack overflow question which provides more details: http://stackoverflow.com/questions/3907815/rails-3-and-rspec-2-turn-off-transactional-fixtures-for-individual-tests Any help is appreciated. Thanks! From felix.rafael at gmail.com Tue Oct 12 19:38:46 2010 From: felix.rafael at gmail.com (Rafael Felix) Date: Tue, 12 Oct 2010 16:38:46 -0700 (PDT) Subject: [rspec-users] Error Testing a view in RSpec 2 Message-ID: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> Well, I'be looking for test my views with rspec, looking the documentation at http://rspec.info/rails/writing/views.html we see some examples, in RSpec 2 the response was deprecated and now I'm using the rendered instead, but this code describe "tags/search.html.erb" do it "should be have an p when no company for the tag was found" do assigns[:name] = "Teste" render rendered.should have_tag('h4', "Visualizando empresas pela Tag Teste") end end and I get : Failures: 1) tags/search.html.erb should be have an p when no company for the tag was found Failure/Error: rendered.should have_tag('h4', "Visualizando empresas pela Tag Teste") undefined method `has_tag?' for # # ./spec/views/tags/search.html.erb_spec.rb:9 I don't know what method we use to check my views? thanks for all regards From dchelimsky at gmail.com Tue Oct 12 20:24:19 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Oct 2010 19:24:19 -0500 Subject: [rspec-users] Error Testing a view in RSpec 2 In-Reply-To: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> References: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> Message-ID: <0237F3DE-8757-4066-A8EF-2C27EB36B129@gmail.com> On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: > Well, I'be looking for test my views with rspec, looking the > documentation at http://rspec.info/rails/writing/views.html we see > some examples, in RSpec 2 the response was deprecated and now I'm > using the rendered instead, but this code > > describe "tags/search.html.erb" do > it "should be have an p when no company for the tag was found" do > assigns[:name] = "Teste" > render > rendered.should have_tag('h4', "Visualizando empresas pela Tag > Teste") > end > end > > and I get : > > > Failures: > 1) tags/search.html.erb should be have an p when no company for the > tag was found > Failure/Error: rendered.should have_tag('h4', "Visualizando > empresas pela Tag Teste") > undefined method `has_tag?' for # > # ./spec/views/tags/search.html.erb_spec.rb:9 > > I don't know what method we use to check my views? If you're using webrat, use have_selector or have_xpath. Otherwise, use Rails' assert_select. HTH, David From felix.rafael at gmail.com Tue Oct 12 20:33:37 2010 From: felix.rafael at gmail.com (Rafael Felix) Date: Tue, 12 Oct 2010 17:33:37 -0700 (PDT) Subject: [rspec-users] Error Testing a view in RSpec 2 In-Reply-To: <0237F3DE-8757-4066-A8EF-2C27EB36B129@gmail.com> References: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> <0237F3DE-8757-4066-A8EF-2C27EB36B129@gmail.com> Message-ID: <569c16f7-64af-40b2-914a-08395589a54c@28g2000yqm.googlegroups.com> Changing my test, for user assert_select, an new error is raised it "should be have an p when no company for the tag was found" do assigns[:name] = "Teste" render rendered.should assert_select('h4', "Visualizando empresas pela Tag") end And the error: Failures: 1) tags/search.html.erb should be have an p when no company for the tag was found Failure/Error: rendered.should assert_select('h4', "Visualizando empresas pela Tag") undefined method `matches?' for # # ./spec/views/tags/search.html.erb_spec.rb:7 thanks for response On Oct 12, 9:24?pm, David Chelimsky wrote: > On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: > > > > > > > Well, I'be looking for test my views with rspec, looking the > > documentation athttp://rspec.info/rails/writing/views.htmlwe see > > some examples, in RSpec 2 the response was deprecated and now I'm > > using the rendered instead, but this code > > > describe "tags/search.html.erb" do > > ?it "should be have an p when no company for the tag was found" do > > ? ?assigns[:name] = "Teste" > > ? ?render > > ? ?rendered.should have_tag('h4', "Visualizando empresas pela Tag > > Teste") > > ?end > > end > > > and I get : > > > Failures: > > ?1) tags/search.html.erb should be have an p when no company for the > > tag was found > > ? ? Failure/Error: rendered.should have_tag('h4', "Visualizando > > empresas pela Tag Teste") > > ? ? undefined method `has_tag?' for # > > ? ? # ./spec/views/tags/search.html.erb_spec.rb:9 > > > I don't know what method we use to check my views? > > If you're using webrat, use have_selector or have_xpath. Otherwise, use Rails' assert_select. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Oct 12 20:37:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Oct 2010 19:37:12 -0500 Subject: [rspec-users] Error Testing a view in RSpec 2 In-Reply-To: <569c16f7-64af-40b2-914a-08395589a54c@28g2000yqm.googlegroups.com> References: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> <0237F3DE-8757-4066-A8EF-2C27EB36B129@gmail.com> <569c16f7-64af-40b2-914a-08395589a54c@28g2000yqm.googlegroups.com> Message-ID: <3C6FE6CE-3E68-46AA-B822-1CF44B5DD22A@gmail.com> On Oct 12, 2010, at 7:33 PM, Rafael Felix wrote: > > On Oct 12, 9:24 pm, David Chelimsky wrote: >> On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: >> >> >> >> >> >>> Well, I'be looking for test my views with rspec, looking the >>> documentation athttp://rspec.info/rails/writing/views.htmlwe see >>> some examples, in RSpec 2 the response was deprecated and now I'm >>> using the rendered instead, but this code >> >>> describe "tags/search.html.erb" do >>> it "should be have an p when no company for the tag was found" do >>> assigns[:name] = "Teste" >>> render >>> rendered.should have_tag('h4', "Visualizando empresas pela Tag >>> Teste") >>> end >>> end >> >>> and I get : >> >>> Failures: >>> 1) tags/search.html.erb should be have an p when no company for the >>> tag was found >>> Failure/Error: rendered.should have_tag('h4', "Visualizando >>> empresas pela Tag Teste") >>> undefined method `has_tag?' for # >>> # ./spec/views/tags/search.html.erb_spec.rb:9 >> >>> I don't know what method we use to check my views? >> >> If you're using webrat, use have_selector or have_xpath. Otherwise, use Rails' assert_select. Please post inline or at the bottom. It makes it easier to follow the conversation. I moved your post to the bottom: > Changing my test, for user assert_select, an new error is raised > > it "should be have an p when no company for the tag was found" do > assigns[:name] = "Teste" > render > rendered.should assert_select('h4', "Visualizando empresas pela > Tag") assert_select is a Rails assertion that works by itself, not an RSpec matcher. Use it like this: assert_select('h4', "Visualizando empresas pela Tag") HTH, David > end > > And the error: > > Failures: > 1) tags/search.html.erb should be have an p when no company for the > tag was found > Failure/Error: rendered.should assert_select('h4', "Visualizando > empresas pela Tag") > undefined method `matches?' for # > # ./spec/views/tags/search.html.erb_spec.rb:7 > > thanks for response From felix.rafael at gmail.com Tue Oct 12 20:57:58 2010 From: felix.rafael at gmail.com (Rafael Felix) Date: Tue, 12 Oct 2010 17:57:58 -0700 (PDT) Subject: [rspec-users] Error Testing a view in RSpec 2 In-Reply-To: <3C6FE6CE-3E68-46AA-B822-1CF44B5DD22A@gmail.com> References: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> <0237F3DE-8757-4066-A8EF-2C27EB36B129@gmail.com> <569c16f7-64af-40b2-914a-08395589a54c@28g2000yqm.googlegroups.com> <3C6FE6CE-3E68-46AA-B822-1CF44B5DD22A@gmail.com> Message-ID: <0fcd3227-5d2d-4b81-a378-ea8aa5309bd2@j18g2000yqd.googlegroups.com> Woah, now works the test, thanks for response. Why the have_tag has removed from RSpec 2? regards On Oct 12, 9:37?pm, David Chelimsky wrote: > On Oct 12, 2010, at 7:33 PM, Rafael Felix wrote: > > > > > > > > > On Oct 12, 9:24 pm, David Chelimsky wrote: > >> On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: > > >>> Well, I'be looking for test my views with rspec, looking the > >>> documentation athttp://rspec.info/rails/writing/views.htmlwesee > >>> some examples, in RSpec 2 the response was deprecated and now I'm > >>> using the rendered instead, but this code > > >>> describe "tags/search.html.erb" do > >>> ?it "should be have an p when no company for the tag was found" do > >>> ? ?assigns[:name] = "Teste" > >>> ? ?render > >>> ? ?rendered.should have_tag('h4', "Visualizando empresas pela Tag > >>> Teste") > >>> ?end > >>> end > > >>> and I get : > > >>> Failures: > >>> ?1) tags/search.html.erb should be have an p when no company for the > >>> tag was found > >>> ? ? Failure/Error: rendered.should have_tag('h4', "Visualizando > >>> empresas pela Tag Teste") > >>> ? ? undefined method `has_tag?' for # > >>> ? ? # ./spec/views/tags/search.html.erb_spec.rb:9 > > >>> I don't know what method we use to check my views? > > >> If you're using webrat, use have_selector or have_xpath. Otherwise, use Rails' assert_select. > > Please post inline or at the bottom. It makes it easier to follow the conversation. I moved your post to the bottom: > > > Changing my test, for user assert_select, an new error is raised > > > it "should be have an p when no company for the tag was found" do > > ? ?assigns[:name] = "Teste" > > ? ?render > > ? ?rendered.should assert_select('h4', "Visualizando empresas pela > > Tag") > > assert_select is a Rails assertion that works by itself, not an RSpec matcher. Use it like this: > > assert_select('h4', "Visualizando empresas pela Tag") > > HTH, > David > > > ?end > > > And the error: > > > Failures: > > ?1) tags/search.html.erb should be have an p when no company for the > > tag was found > > ? ? Failure/Error: rendered.should assert_select('h4', "Visualizando > > empresas pela Tag") > > ? ? undefined method `matches?' for # > > ? ? # ./spec/views/tags/search.html.erb_spec.rb:7 > > > thanks for response > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Oct 12 21:08:04 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Oct 2010 20:08:04 -0500 Subject: [rspec-users] Error Testing a view in RSpec 2 In-Reply-To: <0fcd3227-5d2d-4b81-a378-ea8aa5309bd2@j18g2000yqd.googlegroups.com> References: <2eff9aff-febb-48e2-b152-f5a2a7c0a21b@k10g2000yqa.googlegroups.com> <0237F3DE-8757-4066-A8EF-2C27EB36B129@gmail.com> <569c16f7-64af-40b2-914a-08395589a54c@28g2000yqm.googlegroups.com> <3C6FE6CE-3E68-46AA-B822-1CF44B5DD22A@gmail.com> <0fcd3227-5d2d-4b81-a378-ea8aa5309bd2@j18g2000yqd.googlegroups.com> Message-ID: <3752FDCE-3422-460C-8B54-0FA1A6D50BF9@gmail.com> On Oct 12, 2010, at 7:57 PM, Rafael Felix wrote: > On Oct 12, 9:37 pm, David Chelimsky wrote: >> On Oct 12, 2010, at 7:33 PM, Rafael Felix wrote: >> >>> On Oct 12, 9:24 pm, David Chelimsky wrote: >>>> On Oct 12, 2010, at 6:38 PM, Rafael Felix wrote: >> >>>>> Well, I'be looking for test my views with rspec, looking the >>>>> documentation athttp://rspec.info/rails/writing/views.htmlwesee >>>>> some examples, in RSpec 2 the response was deprecated and now I'm >>>>> using the rendered instead, but this code >> >>>>> describe "tags/search.html.erb" do >>>>> it "should be have an p when no company for the tag was found" do >>>>> assigns[:name] = "Teste" >>>>> render >>>>> rendered.should have_tag('h4', "Visualizando empresas pela Tag >>>>> Teste") >>>>> end >>>>> end >> >>>>> and I get : >> >>>>> Failures: >>>>> 1) tags/search.html.erb should be have an p when no company for the >>>>> tag was found >>>>> Failure/Error: rendered.should have_tag('h4', "Visualizando >>>>> empresas pela Tag Teste") >>>>> undefined method `has_tag?' for # >>>>> # ./spec/views/tags/search.html.erb_spec.rb:9 >> >>>>> I don't know what method we use to check my views? >> >>>> If you're using webrat, use have_selector or have_xpath. Otherwise, use Rails' assert_select. >> >> Please post inline or at the bottom. It makes it easier to follow the conversation. I moved your post to the bottom: >> >>> Changing my test, for user assert_select, an new error is raised >> >>> it "should be have an p when no company for the tag was found" do >>> assigns[:name] = "Teste" >>> render >>> rendered.should assert_select('h4', "Visualizando empresas pela >>> Tag") >> >> assert_select is a Rails assertion that works by itself, not an RSpec matcher. Use it like this: >> >> assert_select('h4', "Visualizando empresas pela Tag") I had to move your post again. Please post inline or at the bottom. > Woah, now works the test, thanks for response. Why the have_tag has > removed from RSpec 2? have_tag wrapped assert_select in a way that was very brittle. Also Webrat and Capybara matchers are better :) Cheers, David >>> end >> >>> And the error: >> >>> Failures: >>> 1) tags/search.html.erb should be have an p when no company for the >>> tag was found >>> Failure/Error: rendered.should assert_select('h4', "Visualizando >>> empresas pela Tag") >>> undefined method `matches?' for # >>> # ./spec/views/tags/search.html.erb_spec.rb:7 >> >>> thanks for response >> From lists at ruby-forum.com Tue Oct 12 23:53:08 2010 From: lists at ruby-forum.com (Yuri Yuri art) Date: Wed, 13 Oct 2010 05:53:08 +0200 Subject: [rspec-users] Strange return value In-Reply-To: <306913FD-051F-4FDB-9164-8C7498CB315C@gmail.com> References: <306913FD-051F-4FDB-9164-8C7498CB315C@gmail.com> Message-ID: <5ec8eb99d3abad209e4a7db39e09f8c3@ruby-forum.com> Thanks you for the post. Hi guys, Im a newbie. Nice to join this forum. __________________ http://moviesonlinefree.biz -- Posted via http://www.ruby-forum.com/. From mail at russellquinn.com Wed Oct 13 01:54:56 2010 From: mail at russellquinn.com (Russell Quinn) Date: Tue, 12 Oct 2010 22:54:56 -0700 (PDT) Subject: [rspec-users] DateTime.now.utc in fixtures In-Reply-To: References: <9aa875c1-3f1e-4895-859b-83403b202988@g18g2000yqk.googlegroups.com> Message-ID: Great. Thanks for all the answers. Russell. On Oct 12, 5:51?am, Rick DeNatale wrote: > On Tue, Oct 12, 2010 at 6:06 AM, Thomas R. Koll wrote: > > > Hi, > > > It might sound strange, but you usually stub Time.now > > Read here:http://ariejan.net/2008/11/05/rspecing-with-timenow/ > > I used to do this myself even with Test::Unithttp://talklikeaduck.denhaven2.com/2007/07/18/time-flies-while-youre-... > > More recently I've been using timecop > > http://github.com/jtrupiano/timecop > > It allows time to be either frozen or offset, and it stubs Time, > DateTime and Date to do the right thing. > > -- > Rick DeNatale > > Help fund my talk at Ruby Conf 2010:http://pledgie.com/campaigns/13677 > 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 > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Wed Oct 13 07:20:47 2010 From: lists at ruby-forum.com (Matt Davies) Date: Wed, 13 Oct 2010 13:20:47 +0200 Subject: [rspec-users] no such file to load -- spec/rake/spectask Message-ID: <967fd3d30ff6d95225cfff40429f4d3b@ruby-forum.com> Hello there I'm running a rails 2.3.5 project and I can't run any rake tasks My error is no such file to load -- spec/rake/spectask Here's a relevant snippet of gem list output rails (2.3.5) rake (0.8.7) random_data (1.5.0) RedCloth (4.2.2) remarkable (3.1.13) remarkable_activerecord (3.1.13) remarkable_paperclip (0.6.3) remarkable_rails (3.1.11) rspec (2.0.0) rspec-core (2.0.0) rspec-expectations (2.0.0) rspec-mocks (2.0.0) rspec-rails (1.2.9) ruby-debug (0.10.3) ruby-debug-base (0.10.3) So I have rspec 2.0.0 installed. What is strange is that if I'm using a system that also has rspec 1.3.0 this error goes away. Has something changed in how you reference spec/rake/spectask in rspec 2.0.0, as compared to rspec 1.3.0? Here's the gemfile snippet if that is relevant. group :test do gem 'ruby-debug' gem 'cucumber', "0.4.4" # gem 'cucumber-rails' gem 'rspec-rails', '1.2.9' gem 'remarkable_rails', '3.1.11' gem 'remarkable_paperclip', '0.6.3' gem 'random_data', '1.5.0' gem 'machinist', '1.0.6' gem 'shoulda', '2.10.2' gem 'faker', '0.3.1' gem 'webrat', '0.6.0' end Any help, greatly appreciated. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Oct 13 07:30:22 2010 From: lists at ruby-forum.com (Matt Davies) Date: Wed, 13 Oct 2010 13:30:22 +0200 Subject: [rspec-users] no such file to load -- spec/rake/spectask In-Reply-To: <967fd3d30ff6d95225cfff40429f4d3b@ruby-forum.com> References: <967fd3d30ff6d95225cfff40429f4d3b@ruby-forum.com> Message-ID: I've found a solution. I upgraded rspec-rails to 1.3.3 in my gemfile, which in turn downgraded rspec from 2.0 to 1.3.1 in the gem list. This configuration now works ok. God knows what was happening there. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Oct 13 09:08:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 13 Oct 2010 08:08:12 -0500 Subject: [rspec-users] no such file to load -- spec/rake/spectask In-Reply-To: References: <967fd3d30ff6d95225cfff40429f4d3b@ruby-forum.com> Message-ID: <30B696A7-BBD9-4B76-9B6C-571FC85A413F@gmail.com> On Oct 13, 2010, at 6:30 AM, Matt Davies wrote: > I've found a solution. > > I upgraded rspec-rails to 1.3.3 in my gemfile, which in turn downgraded > rspec from 2.0 to 1.3.1 in the gem list. This configuration now works > ok. God knows what was happening there. rspec-rails-1.3.2 depends on rspec >= 1.3.0, so if you have rspec-2 installed, it tries to load it. rspec-rails-1.3.3 depends on rspec-1.3.1 explicitly. Make sense? Cheers, David From lists at ruby-forum.com Wed Oct 13 09:30:04 2010 From: lists at ruby-forum.com (Matt Davies) Date: Wed, 13 Oct 2010 15:30:04 +0200 Subject: [rspec-users] no such file to load -- spec/rake/spectask In-Reply-To: <967fd3d30ff6d95225cfff40429f4d3b@ruby-forum.com> References: <967fd3d30ff6d95225cfff40429f4d3b@ruby-forum.com> Message-ID: <336850a1c8af6c5a157558170327fc47@ruby-forum.com> Hi David I understand what you're saying, but the only thing I can think of(I'm using bundler and there are no gems installed prior to running bundle install) is that gem 'rspec-rails', '1.2.9' must depend on rspec >= 2.0 Otherwise I have no idea how rspec 2.0 was getting into the gem list Matt -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Oct 13 10:27:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 13 Oct 2010 09:27:56 -0500 Subject: [rspec-users] no such file to load -- spec/rake/spectask In-Reply-To: <336850a1c8af6c5a157558170327fc47@ruby-forum.com> References: <967fd3d30ff6d95225cfff40429f4d3b@ruby-forum.com> <336850a1c8af6c5a157558170327fc47@ruby-forum.com> Message-ID: On Wed, Oct 13, 2010 at 8:30 AM, Matt Davies wrote: > Hi David > > I understand what you're saying, but the only thing I can think of(I'm > using bundler and there are no gems installed prior to running bundle > install) is that > > gem 'rspec-rails', '1.2.9' > > must depend on rspec >= 2.0 It depends on rspec >= 1.2.9 (any version 1.2.9 and up). Bundler sees that and installs the newest version of rspec, which in this case was 2.0.0. Whereas, rspec-rails-1.3.3 depends on rspec = 1.3.1 (only 1.3.1), so it installs a compatible version. Future releases of rspec will use "pessimistic" version constraints for its requirements (see http://docs.rubygems.org/read/chapter/16#page74), so this shouldn't be a problem going forward. > Otherwise I have no idea how rspec 2.0 was getting into the gem list Cheers, David p.s. Please be sure to quote relevant parts of the discussion to make it easier for everyone to follow the conversation in a single message. From ivo.wever at gmail.com Wed Oct 13 11:02:25 2010 From: ivo.wever at gmail.com (Ivo Wever) Date: Wed, 13 Oct 2010 17:02:25 +0200 Subject: [rspec-users] Testing 'nil.should == something_not_nil' fails Message-ID: <4CB5CA01.1050105@gmail.com> Hello, After upgrading to rspec 2.0.0.rc, I ran into an issue that I reported at http://github.com/rspec/rspec-core/issues/issue/183/#issue/183. When testing something that returned nil, effectively executing 'nil.should == something_not_nil', rspec would come crashing down. It turned out not to be a bug in rspec (or, at least, David can't reproduce it). I initially wrote it off as something strange with my setup and worked around it for now (specs usually succeed, so nil == nil and everything works fine), but as 'scrymmyin' reported seeing the same behavior in issue 183, and as I also see it with rspec 2.0.0, I thought it might be nice to document it here. I can reproduce the behavior as follows: - gem install rspec --version=2.0.0 - mkdir sandbox; cd sandbox - create Gemfile with contents gem 'rspec', '2.0.0' - run bundle install - mkdir spec - create spec/nil_fail.rb with contents describe 'Sandbox' do it 'should show the difference' do nil.should == 'foo' end end - run rspec spec/nil_fail.rb The result is: user at machine:~/dev/ruby/sandbox$ rspec spec/nil_fail.rb F Failures: 1) Sandbox should show the difference $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:138:in find_failed_line': undefined methoddowncase' for nil:NilClass (NoMethodError) from $REE_gems_path/rspec-expectations-2.0.0.rc/lib/rspec/expectations/fail_with.rb:29:in `detect' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in `each' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in `detect' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in `find_failed_line' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:122:in `read_failed_line' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:27:in `dump_failures' from $REE_gems_path/rspec-expectations-2.0.0.rc/lib/rspec/expectations/fail_with.rb:29:in `each_with_index' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in `each' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in `each_with_index' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in `dump_failures' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:74:in `send' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:74:in `notify' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:73:in `each' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:73:in `notify' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:22:in `conclude' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:13:in `report' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/command_line.rb:23:in `run' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:55:in `run_in_process' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:46:in `run' from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:10:in `autorun' from $REE_path/bin/rspec:19 best regards, -- Ivo Wever From dchelimsky at gmail.com Wed Oct 13 21:11:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 13 Oct 2010 20:11:33 -0500 Subject: [rspec-users] Testing 'nil.should == something_not_nil' fails In-Reply-To: <4CB5CA01.1050105@gmail.com> References: <4CB5CA01.1050105@gmail.com> Message-ID: <0A02DA7A-D324-4B53-A792-9F286144EDDE@gmail.com> On Oct 13, 2010, at 10:02 AM, Ivo Wever wrote: > Hello, > > After upgrading to rspec 2.0.0.rc, I ran into an issue that I reported > at http://github.com/rspec/rspec-core/issues/issue/183/#issue/183. When > testing something that returned nil, effectively executing 'nil.should > == something_not_nil', rspec would come crashing down. It turned out not > to be a bug in rspec (or, at least, David can't reproduce it). > > I initially wrote it off as something strange with my setup and worked > around it for now (specs usually succeed, so nil == nil and everything > works fine), but as 'scrymmyin' reported seeing the same behavior in > issue 183, and as I also see it with rspec 2.0.0, I thought it might be > nice to document it here. > > I can reproduce the behavior as follows: > > - gem install rspec --version=2.0.0 > - mkdir sandbox; cd sandbox > - create Gemfile with contents > gem 'rspec', '2.0.0' > - run bundle install > - mkdir spec > - create spec/nil_fail.rb with contents > describe 'Sandbox' do > it 'should show the difference' do > nil.should == 'foo' > end > end > - run rspec spec/nil_fail.rb > > The result is: > > user at machine:~/dev/ruby/sandbox$ rspec spec/nil_fail.rb > F > > Failures: > 1) Sandbox should show the difference > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:138:in > find_failed_line': undefined methoddowncase' for nil:NilClass > (NoMethodError) > > from > $REE_gems_path/rspec-expectations-2.0.0.rc/lib/rspec/expectations/fail_with.rb:29:in > `detect' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in > `each' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in > `detect' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:136:in > `find_failed_line' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_formatter.rb:122:in > `read_failed_line' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:27:in > `dump_failures' > from > $REE_gems_path/rspec-expectations-2.0.0.rc/lib/rspec/expectations/fail_with.rb:29:in > `each_with_index' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in > `each' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in > `each_with_index' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/formatters/base_text_formatter.rb:17:in > `dump_failures' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:74:in > `send' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:74:in > `notify' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:73:in > `each' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:73:in > `notify' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:22:in > `conclude' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/reporter.rb:13:in > `report' > from > $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/command_line.rb:23:in > `run' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:55:in > `run_in_process' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:46:in `run' > from $REE_gems_path/rspec-core-2.0.0.rc/lib/rspec/core/runner.rb:10:in > `autorun' > from $REE_path/bin/rspec:19 FYI - setting an expectation on nil was a red herring. The example could have failed for any other reason ("foo".should eq("bar")) and the same error would have occurred. The problem was actually related to the filename. While rspec was able to load up the file named outside the _spec.rb convention (i.e. nil_fail.rb), it was not able to correctly report a failure in that file. Fixed: http://github.com/rspec/rspec-core/commit/9c6b6f74da382d0810ab337730828c5fd94e309b To be released in 2.0.1. Cheers, David From lists at ruby-forum.com Fri Oct 15 07:38:32 2010 From: lists at ruby-forum.com (Alexey Petrushin) Date: Fri, 15 Oct 2010 13:38:32 +0200 Subject: [rspec-users] RSpec tasks, JRuby and rvm In-Reply-To: <4BE353FD.6090509@yahoo.com.br> References: <4BE353FD.6090509@yahoo.com.br> Message-ID: <187512bdb62cd0808a215d9520da2a28@ruby-forum.com> The same problem, can't use 'rake spec', here's quick workaround, use rake spec:isolated namespace :spec do desc "Run RSpec code exapmples in isolated mode (every spec file in different Ruby process)" task :isolated do Dir.glob("spec/**/[^_]*_spec.rb").each do |spec_file| Kernel.system "rspec #{spec_file}" end end end it's terribly slow, btw :) -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Oct 15 07:39:43 2010 From: lists at ruby-forum.com (Rob Eastwood) Date: Fri, 15 Oct 2010 13:39:43 +0200 Subject: [rspec-users] Problems running RSpec 2 with autotest/autospec In-Reply-To: References: <4f66d4df-b0c0-43ec-960a-56a2a15a2f6d@j4g2000yqh.googlegroups.com>, , Message-ID: <2b8ca83e353d7908007738a36838063e@ruby-forum.com> Kristian Mandrup wrote in post #917131: > Thanks! I solved it all now and updated the RSpec 2 wiki about how to > set it all up ;) > > http://wiki.github.com/rspec/rspec/autotest > > Hope these instructions provides a good base and is helpful to others! Hi Kristian, just wanted to pass on my appreciation for your efforts re documenting rspec & autotest. As a newcomer to rspec (1 week and lovin' it!), thanks to your wiki post, I have now got this working. I almost had it, but your post sealed the deal. cheers Rob -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Oct 15 10:36:51 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 15 Oct 2010 09:36:51 -0500 Subject: [rspec-users] rspec-rails-2.0.1 is released! Message-ID: <5957D4AF-DF04-45BB-8166-32BE1FBD317B@gmail.com> The rails-3.0.1 release excluded a change that I had naively expected to be included. This upgrade is only necessary if you write view specs and are upgrading to rails-3.0.1. To upgrade, all you need to do is change your Gemfile to read: gem "rspec-rails", "2.0.1" And then run bundle update rspec-rails ## Release Notes ### 2.0.1 / 2010-10-15 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.0.0...v2.0.1) * Enhancements * Add option to not generate request spec (--skip-request-specs) * Bug fixes * Updated the mock_[model] method generated in controller specs so it adds any stubs submitted each time it is called. * Fixed bug where view assigns weren't making it to the view in view specs in Rails-3.0.1. (Emanuele Vicentini) Cheers, David From andrew at andrewtimberlake.com Sat Oct 16 00:05:54 2010 From: andrew at andrewtimberlake.com (Andrew Timberlake) Date: Sat, 16 Oct 2010 06:05:54 +0200 Subject: [rspec-users] Color not displaying when using an autowatchr script Message-ID: When running RSpec 2.0.0.beta22, I would get colour output in the console from my specs Now, with 2.0.0 no color is used. If I run the rspec command directly, color is displaying again. I have --color in my .rspec file Andrew Timberlake -------------- next part -------------- An HTML attachment was scrubbed... URL: From todd.sedano at sv.cmu.edu Mon Oct 18 02:24:12 2010 From: todd.sedano at sv.cmu.edu (Todd Sedano) Date: Sun, 17 Oct 2010 23:24:12 -0700 Subject: [rspec-users] no output from rspec Message-ID: At one point, I had rspec working with my system and I've must have changed the configuration because now I don't see anything in the output using rspec 1.3. Just to be clear, I see nothing when I type spec spec rake spec bundle exec spec spec bundle exec rake spec (or any of the above with a specific spec file.) I didn't see a debug option to see what is going wrong. I'm using bundler. (Gemfile http://gist.github.com/631809). I've tried uninstalling rspec 1.3 and rspec 2.0 (et al) My specs are in my rails directory (ie project/spec) I'm on leopard (10.5.8) Just to be safe, I blew out the bundler directories ( rm -rf ~/.bundle/ ~/.gem/ .bundle/ vendor/cache/ Gemfile.lock) and the ~/.rvm directory Ironically, everything works nicely on my build machine. I'm eagerly waiting for my move to Rails 3, this just isn't a good time for me yet I just tried creating a new project using the same Gemfile and it looks like it is working in a vanilla rails project. I'm not sure where to begin to see what my current project is doing to create this problem. Any thoughts? Thanks! Todd Ps. I'm assuming that I can't use rspec 2.0.0 and rspec-rails-1.3 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Oct 18 09:06:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Oct 2010 08:06:33 -0500 Subject: [rspec-users] Color not displaying when using an autowatchr script In-Reply-To: References: Message-ID: On Oct 15, 2010, at 11:05 PM, Andrew Timberlake wrote: > When running RSpec 2.0.0.beta22, I would get colour output in the console from my specs > Now, with 2.0.0 no color is used. > If I run the rspec command directly, color is displaying again. > I have --color in my .rspec file Please report bugs to http://github.com/rspec/rspec-core/issues. Thx From dchelimsky at gmail.com Mon Oct 18 09:26:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Oct 2010 08:26:36 -0500 Subject: [rspec-users] no output from rspec In-Reply-To: References: Message-ID: <36AEED78-6F69-43F7-BF8F-B627BAE10511@gmail.com> On Oct 18, 2010, at 1:24 AM, Todd Sedano wrote: > At one point, I had rspec working with my system and I've must have changed the configuration because now I don't see anything in the output using rspec 1.3. > > Just to be clear, I see nothing when I type > spec spec > rake spec > bundle exec spec spec > bundle exec rake spec > (or any of the above with a specific spec file.) > > I didn't see a debug option to see what is going wrong. $ spec -h Usage: spec (FILE(:LINE)?|DIRECTORY|GLOB)+ [options] ... -u, --debugger Enable ruby-debugging. > I'm using bundler. (Gemfile http://gist.github.com/631809). I've tried uninstalling rspec 1.3 and rspec 2.0 (et al) My specs are in my rails directory (ie project/spec) I'm on leopard (10.5.8) Just to be safe, I blew out the bundler directories ( rm -rf ~/.bundle/ ~/.gem/ .bundle/ vendor/cache/ Gemfile.lock) and the ~/.rvm directory > > Ironically, everything works nicely on my build machine. > > I'm eagerly waiting for my move to Rails 3, this just isn't a good time for me yet > > I just tried creating a new project using the same Gemfile and it looks like it is working in a vanilla rails project. I'm not sure where to begin to see what my current project is doing to create this problem. > > Any thoughts? First thought: that sucks! Second thought: this has happened before. Third thought: http://www.google.com/search?q=rspec+no+output I'm sure you'll find your answer in there. If someone else has the answer at the top of his/her head, please follow up here. Cheers, David > Thanks! > > Todd > > Ps. I'm assuming that I can't use rspec 2.0.0 and rspec-rails-1.3 ps - there is a project up on github that works with early beta versions of rspec-2: http://github.com/rsanheim/rspec-rails23 but it has yet to be updated to rspec-2.0.0. Someone should fork and update it. I will eventually if nobody else does, but it's going to be a few weeks before I can get to it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From walketim at gmail.com Mon Oct 18 10:07:39 2010 From: walketim at gmail.com (Tim Walker) Date: Mon, 18 Oct 2010 08:07:39 -0600 Subject: [rspec-users] no output from rspec In-Reply-To: <36AEED78-6F69-43F7-BF8F-B627BAE10511@gmail.com> References: <36AEED78-6F69-43F7-BF8F-B627BAE10511@gmail.com> Message-ID: Maybe you have syntax problems. can you do a ruby -c ? Anything in test.log? On Oct 18, 2010 7:49 AM, "David Chelimsky" wrote: On Oct 18, 2010, at 1:24 AM, Todd Sedano wrote: > > At one point, I had rspec working with my system... $ spec -h Usage: spec (FILE(:LINE)?|DIRECTORY|GLOB)+ [options] ... -u, --debugger Enable ruby-debugging. > I'm using bundler. (Gemfile http://gist.github.com/631809). I've tried uninstalling rspec 1.3 and ... First thought: that sucks! Second thought: this has happened before. Third thought: http://www.google.com/search?q=rspec+no+output I'm sure you'll find your answer in there. If someone else has the answer at the top of his/her head, please follow up here. Cheers, David > Thanks! > > Todd > > Ps. I'm assuming that I can't use rspec 2.0.0 and rspec-rails-1.3 ps - there is a project up on github that works with early beta versions of rspec-2: http://github.com/rsanheim/rspec-rails23 but it has yet to be updated to rspec-2.0.0. Someone should fork and update it. I will eventually if nobody else does, but it's going to be a few weeks before I can get to it. _______________________________________________ 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 srveit at gmail.com Mon Oct 18 16:27:35 2010 From: srveit at gmail.com (Stephen Veit) Date: Mon, 18 Oct 2010 13:27:35 -0700 (PDT) Subject: [rspec-users] "contain" not defined in view spec Message-ID: Using Rails 2 and rspec-rails 2.0.1. I have the following view spec: require 'spec_helper' describe "bookmarkers/show.html.haml" do include BookmarkersHelper before(:each) do @bookmarker = mock_model(Bookmarker) @bookmarker.stub!(:host_id).and_return("1") assign(:bookmarker, @bookmarker) view.stub! (:edit_object_path).and_return(edit_bookmarker_path(@bookmarker)) view.stub!(:collection_path).and_return(bookmarkers_path) end it "should render attributes in

" do render rendered.should contain("1") end end When I run /usr/bin/ruby -S bundle exec rspec "./spec/views/ bookmarkers/show.html.haml_spec.rb" I get: F Failures: 1) bookmarkers/show.html.haml should render attributes in

Failure/Error: rendered.should contain("1") undefined method `contain' for # # ./spec/views/bookmarkers/show.html.haml_spec.rb:19 Finished in 0.10042 seconds 1 example, 1 failure Where can I find the definition of "contain" or "contains?" Also here is my Gemfile: group :development, :test do gem "rspec", "~>2.0.0" gem "rspec-rails", ">= 2.0.1" end Thanks. Stephen Veit From srveit at gmail.com Mon Oct 18 16:27:35 2010 From: srveit at gmail.com (Stephen Veit) Date: Mon, 18 Oct 2010 13:27:35 -0700 (PDT) Subject: [rspec-users] "contain" not defined in view spec Message-ID: Using Rails 2 and rspec-rails 2.0.1. I have the following view spec: require 'spec_helper' describe "bookmarkers/show.html.haml" do include BookmarkersHelper before(:each) do @bookmarker = mock_model(Bookmarker) @bookmarker.stub!(:host_id).and_return("1") assign(:bookmarker, @bookmarker) view.stub! (:edit_object_path).and_return(edit_bookmarker_path(@bookmarker)) view.stub!(:collection_path).and_return(bookmarkers_path) end it "should render attributes in

" do render rendered.should contain("1") end end When I run /usr/bin/ruby -S bundle exec rspec "./spec/views/ bookmarkers/show.html.haml_spec.rb" I get: F Failures: 1) bookmarkers/show.html.haml should render attributes in

Failure/Error: rendered.should contain("1") undefined method `contain' for # # ./spec/views/bookmarkers/show.html.haml_spec.rb:19 Finished in 0.10042 seconds 1 example, 1 failure Where can I find the definition of "contain" or "contains?" Also here is my Gemfile: group :development, :test do gem "rspec", "~>2.0.0" gem "rspec-rails", ">= 2.0.1" end Thanks. Stephen Veit From dchelimsky at gmail.com Mon Oct 18 16:41:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Oct 2010 15:41:58 -0500 Subject: [rspec-users] "contain" not defined in view spec In-Reply-To: References: Message-ID: On Oct 18, 2010, at 3:27 PM, Stephen Veit wrote: > Using Rails 2 and rspec-rails 2.0.1. rspec-rails-2 does not support rails-2. Please use rspec-rails-1.3.3 for rails-2. HTH, David From srveit at gmail.com Mon Oct 18 17:53:35 2010 From: srveit at gmail.com (Stephen Veit) Date: Mon, 18 Oct 2010 14:53:35 -0700 (PDT) Subject: [rspec-users] "contain" not defined in view spec In-Reply-To: References: Message-ID: <6c34197f-5763-4825-b1d8-d57e08649916@v20g2000yqb.googlegroups.com> On Oct 18, 3:41?pm, David Chelimsky wrote: > On Oct 18, 2010, at 3:27 PM, Stephen Veit wrote: > > > Using Rails 2 and rspec-rails 2.0.1. > > rspec-rails-2 does not support rails-2. Please use rspec-rails-1.3.3 for rails-2. > > HTH, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users I meant to type "Rails 3". I am using Rails 3 and rspec-rails 2.0.1. From dchelimsky at gmail.com Mon Oct 18 19:53:13 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Oct 2010 18:53:13 -0500 Subject: [rspec-users] "contain" not defined in view spec In-Reply-To: References: Message-ID: <50E26D00-260D-4AF3-822F-F2AEA58467CB@gmail.com> On Oct 18, 2010, at 3:27 PM, Stephen Veit wrote: > Using Rails 2 and rspec-rails 2.0.1. > > I have the following view spec: > > > require 'spec_helper' > > describe "bookmarkers/show.html.haml" do > include BookmarkersHelper > > before(:each) do > @bookmarker = mock_model(Bookmarker) > @bookmarker.stub!(:host_id).and_return("1") > > assign(:bookmarker, @bookmarker) > > view.stub! > (:edit_object_path).and_return(edit_bookmarker_path(@bookmarker)) > view.stub!(:collection_path).and_return(bookmarkers_path) > end > > it "should render attributes in

" do > render > rendered.should contain("1") > end > end > > > When I run /usr/bin/ruby -S bundle exec rspec "./spec/views/ > bookmarkers/show.html.haml_spec.rb" I get: > > > F > > Failures: > 1) bookmarkers/show.html.haml should render attributes in

> Failure/Error: rendered.should contain("1") > undefined method `contain' for > # > # ./spec/views/bookmarkers/show.html.haml_spec.rb:19 > > Finished in 0.10042 seconds > 1 example, 1 failure > > Where can I find the definition of "contain" or "contains?" > > Also here is my Gemfile: > > group :development, :test do > gem "rspec", "~>2.0.0" > gem "rspec-rails", ">= 2.0.1" > end > > Thanks. > > Stephen Veit contain is a Webrat matcher (also Capybara, but Capybara matchers do not work in view specs), so you need to add that to your Gemfile: gem "webrat", ">= 0.7.2.beta.2" HTH, David From joe at faithfulgeek.org Mon Oct 18 14:20:48 2010 From: joe at faithfulgeek.org (Joe Fiorini) Date: Mon, 18 Oct 2010 11:20:48 -0700 (PDT) Subject: [rspec-users] RSpec Routing DSL Message-ID: <86f2ce8a-560d-4708-9d68-a9a4bfefb66e@i21g2000yqg.googlegroups.com> I started testing routes for the first time in Rails 3 this weekend during Rails Rumble. I was so exhausted that I found writing route specs a very painful task. I came up with my own routing DSL and I'd love to see it get included in RSpec itself. Before I start adding the code to rspec-rails, I'd like to get some feedback and see if there are some ways we could clean it up. Basically the DSL looks like: describe "My routes" do get "/blog" => { controller: "blogs-controller", action: "index" } end You can see all the details and the module used to make it work here: http://gist.github.com/630176. Thoughts? From dchelimsky at gmail.com Mon Oct 18 23:29:15 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Oct 2010 22:29:15 -0500 Subject: [rspec-users] RSpec Routing DSL In-Reply-To: <86f2ce8a-560d-4708-9d68-a9a4bfefb66e@i21g2000yqg.googlegroups.com> References: <86f2ce8a-560d-4708-9d68-a9a4bfefb66e@i21g2000yqg.googlegroups.com> Message-ID: <2AAC61F9-1728-415B-9AE9-C3D28C35D97B@gmail.com> On Oct 18, 2010, at 1:20 PM, Joe Fiorini wrote: > I started testing routes for the first time in Rails 3 this weekend > during Rails Rumble. I was so exhausted that I found writing route > specs a very painful task. I came up with my own routing DSL and I'd > love to see it get included in RSpec itself. Before I start adding the > code to rspec-rails, I'd like to get some feedback and see if there > are some ways we could clean it up. Basically the DSL looks like: > > describe "My routes" do > > get "/blog" => { controller: "blogs-controller", action: "index" } > > end > > You can see all the details and the module used to make it work here: > http://gist.github.com/630176. Thoughts? Hey Joe - I think this is really nice, but it's unlike any other matchers/macros that ship with RSpec, so I don't feel it belongs in RSpec as it stands today. If future versions move in a direction that better aligns with this we can revisit. That said, I think it's a nice clean DSL and recommend that you publish it as a gem and share it with those who wish to use it. In terms of improving it, the only thing I see missing is a way of specifying a route that is not supported. Maybe something like: get "/blog" => unroutable WDYT? From dchelimsky at gmail.com Tue Oct 19 00:43:38 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Oct 2010 23:43:38 -0500 Subject: [rspec-users] rspec-2.0.1 is released! Message-ID: This is primarily a bug-fix release for rspec-core: ### rspec-core-2.0.1 [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0...v2.0.1) * Bug fixes * restore color when using spork + autotest * Pending examples without docstrings render the correct message (Josep M. Bach) * Fixed bug where a failure in a spec file ending in anything but _spec.rb would fail in a confusing way. * Support backtrace lines from erb templates in html formatter (Alex Crichton) ### rspec-expectations-2.0.1 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0...v2.0.1) * Enhancements * Make dependencies on other rspec gems consistent across gems ### rspec-mocks-2.0.1 [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0...v2.0.1) * Enhancements * Make dependencies on other rspec gems consistent across gems From thehcdreamer at gmail.com Tue Oct 19 03:56:43 2010 From: thehcdreamer at gmail.com (Oscar Del Ben) Date: Tue, 19 Oct 2010 09:56:43 +0200 Subject: [rspec-users] Testing initialize methods and chained methods Message-ID: I'm having some troubles understanding how to test a couple of things. Usually, if I'm having trouble testing something, it means that my design could probably be improved or changed, but in these cases I think I'm doing the right thing. Here's the first scenario: class Foo def initialize do_something end end Here I have no idea how to test that the do_something method is called. Another issue I have is with the following code: my_method.another_chained_method.something_else Here I'm having trouble understanding how to test that my_method receives another_chained_method and so on. Any help would be very appreciated. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From win at wincent.com Tue Oct 19 03:05:39 2010 From: win at wincent.com (Wincent Colaiuta) Date: Tue, 19 Oct 2010 09:05:39 +0200 Subject: [rspec-users] RSpec Routing DSL In-Reply-To: <86f2ce8a-560d-4708-9d68-a9a4bfefb66e@i21g2000yqg.googlegroups.com> References: <86f2ce8a-560d-4708-9d68-a9a4bfefb66e@i21g2000yqg.googlegroups.com> Message-ID: El 18/10/2010, a las 20:20, Joe Fiorini escribi?: > I started testing routes for the first time in Rails 3 this weekend > during Rails Rumble. I was so exhausted that I found writing route > specs a very painful task. I came up with my own routing DSL and I'd > love to see it get included in RSpec itself. Before I start adding the > code to rspec-rails, I'd like to get some feedback and see if there > are some ways we could clean it up. Basically the DSL looks like: > > describe "My routes" do > > get "/blog" => { controller: "blogs-controller", action: "index" } > > end > > You can see all the details and the module used to make it work here: > http://gist.github.com/630176. Thoughts? I felt the same pain a while back and proposed a DSL too, but it never really got anywhere as there was no consensus about what a new DSL should look like. Full thread here: http://groups.google.com/group/rspec/browse_thread/thread/50b46ca3e4bd3a78/da928456061063c6 I never got as far as submitting a patch because I didn't really like the alternative proposals so wasn't going to code them up (I'd already posted my own working proposal). After several iterations, the implementation that I am currently using consists of "map_to", "map_from", "have_routing" (ie. map both ways) and "be_recognized" matchers; these were chosen largely because they don't clash with the existing matchers in RSpec and so I can use them on an "opt-in" basis: http://gist.github.com/633716 Some sample specs: http://gist.github.com/633723 One thing to note is how there are two assertions in there where I use "map_to" instead of "have_routing" because of what looks to be a bug in the Rails routing assertion macros. I think there is a Lighthouse ticket for this but the only ones related to "assert_generates" which I can find right now are: https://rails.lighthouseapp.com/projects/8994/tickets/5260 https://rails.lighthouseapp.com/projects/8994/tickets/5005 https://rails.lighthouseapp.com/projects/8994/tickets/5689 At least one of those issues (#5260, #5005) is supposedly resolved in 3.0.2. #5698 was marked as invalid. Tangentially related is this old ticket which I posted: https://rspec.lighthouseapp.com/projects/5645/tickets/907 I thought someone posted a pretty good analysis of exactly what the breakage is and why it happens, but I can't find it. :-( Guess when I get time will have to do some analysis of the Rails codebase and figure out what's happening and put together another ticket. While Googling, found this, however, describing changes in 2.0.0: http://github.com/rspec/rspec-rails/issues/221 Which notes that RSpec's "route_to" now delegates to "assert_recognizes" (a one-way assertion) rather than "assert_routing" (a two-way assertion). Cheers, Wincent From jko170 at gmail.com Tue Oct 19 09:09:29 2010 From: jko170 at gmail.com (Justin Ko) Date: Tue, 19 Oct 2010 06:09:29 -0700 (PDT) Subject: [rspec-users] Testing initialize methods and chained methods In-Reply-To: References: Message-ID: On Oct 19, 3:56?am, Oscar Del Ben wrote: > I'm having some troubles understanding how to test a couple of things. > Usually, if I'm having trouble testing something, it means that my design > could probably be improved or changed, but in these cases I think I'm doing > the right thing. > > Here's the first scenario: > > class Foo > ? def initialize > ? ? do_something > ? end > end > > Here I have no idea how to test that the do_something method is called. > > Another issue I have is with the following code: > > my_method.another_chained_method.something_else > > Here I'm having trouble understanding how to test that my_method receives > another_chained_method and so on. > > Any help would be very appreciated. Thanks! > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users How does the initialize method usually get called? By call ".new" on the class. Here is some docs on your new friend "stub_chain" http://relishapp.com/rspec/rspec-mocks/v/2-0/dir/stubs/stub-a-chain-of-methods I'm in a hurry, sorry I can't help more than that. From apremdas at gmail.com Tue Oct 19 13:12:08 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 19 Oct 2010 18:12:08 +0100 Subject: [rspec-users] Testing initialize methods and chained methods In-Reply-To: References: Message-ID: Set an expectation that do_something should be called once. Then create a new Foo. With the method chain set an expectation that your chained method should be called, then call the original method. You should be able to check that the original method is passed as a param. Further information in RSpec book which has some gr8 stuff on expectations HTH Andrew On 19 October 2010 08:56, Oscar Del Ben wrote: > I'm having some troubles understanding how to test a couple of things. > Usually, if I'm having trouble testing something, it means that my design > could probably be improved or changed, but in these cases I think I'm doing > the right thing. > > Here's the first scenario: > > class Foo > def initialize > do_something > end > end > > Here I have no idea how to test that the do_something method is called. > > Another issue I have is with the following code: > > my_method.another_chained_method.something_else > > Here I'm having trouble understanding how to test that my_method receives > another_chained_method and so on. > > Any help would be very appreciated. Thanks! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Oct 19 13:43:31 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Oct 2010 12:43:31 -0500 Subject: [rspec-users] RSpec Routing DSL In-Reply-To: References: <86f2ce8a-560d-4708-9d68-a9a4bfefb66e@i21g2000yqg.googlegroups.com> Message-ID: <33F76321-328E-4F30-A111-44553DA19CBF@gmail.com> On Oct 19, 2010, at 2:05 AM, Wincent Colaiuta wrote: > El 18/10/2010, a las 20:20, Joe Fiorini escribi?: > >> I started testing routes for the first time in Rails 3 this weekend >> during Rails Rumble. I was so exhausted that I found writing route >> specs a very painful task. I came up with my own routing DSL and I'd >> love to see it get included in RSpec itself. Before I start adding the >> code to rspec-rails, I'd like to get some feedback and see if there >> are some ways we could clean it up. Basically the DSL looks like: >> >> describe "My routes" do >> >> get "/blog" => { controller: "blogs-controller", action: "index" } >> >> end >> >> You can see all the details and the module used to make it work here: >> http://gist.github.com/630176. Thoughts? > > I felt the same pain a while back and proposed a DSL too, but it never really got anywhere as there was no consensus about what a new DSL should look like. Full thread here: > > http://groups.google.com/group/rspec/browse_thread/thread/50b46ca3e4bd3a78/da928456061063c6 > > I never got as far as submitting a patch because I didn't really like the alternative proposals so wasn't going to code them up (I'd already posted my own working proposal). > > After several iterations, the implementation that I am currently using consists of "map_to", "map_from", "have_routing" (ie. map both ways) and "be_recognized" matchers; these were chosen largely because they don't clash with the existing matchers in RSpec and so I can use them on an "opt-in" basis: > > http://gist.github.com/633716 > > Some sample specs: > > http://gist.github.com/633723 > > > > One thing to note is how there are two assertions in there where I use "map_to" instead of "have_routing" because of what looks to be a bug in the Rails routing assertion macros. I think there is a Lighthouse ticket for this but the only ones related to "assert_generates" which I can find right now are: > > https://rails.lighthouseapp.com/projects/8994/tickets/5260 > https://rails.lighthouseapp.com/projects/8994/tickets/5005 > https://rails.lighthouseapp.com/projects/8994/tickets/5689 > > At least one of those issues (#5260, #5005) is supposedly resolved in 3.0.2. #5698 was marked as invalid. Tangentially related is this old ticket which I posted: > > https://rspec.lighthouseapp.com/projects/5645/tickets/907 > > I thought someone posted a pretty good analysis of exactly what the breakage is and why it happens, but I can't find it. :-( Guess when I get time will have to do some analysis of the Rails codebase and figure out what's happening and put together another ticket. > > While Googling, found this, however, describing changes in 2.0.0: > > http://github.com/rspec/rspec-rails/issues/221 > > Which notes that RSpec's "route_to" now delegates to "assert_recognizes" (a one-way assertion) rather than "assert_routing" (a two-way assertion). The problem with the bi-directional expectation was that you can have two routes that map to the same path: resources :widgets root :to => "widgets#index" In this case, both of these are true if all we expect is the route recognition: { :get => "/" }.should route_to(:controller => "widgets", :action => "index") { :get => "/widgets/index" }.should route_to(:controller => "widgets", :action => "index") However, route generation would not generate "/" from (:controller => "widgets", :action => "index"). Assuming a bi-directional mapping for every case was wrong, so I changed it to uni-directional (route recognition). The other 1/2 of the motivation for this change was that route generation is something that is well specified and tested in Rails itself. In our apps, our specs should spec things like "generates a link to the widget," not "builds a link using the widget." So I don't see much value in expectations about generation, and I certainly don't see them as a routing concern any longer. They may be so within the rails framework, but they are unrelated to what I'm specifying when I specify routes. Make sense? So for me, all we need is uni-directional expectations for routes we want to exist and routes we want to not exist, hence: { :get => "/" }.should route_to(:controller => "foo", :action => "bar") { :get => "/private_stuff" }.should_not be_routable I would definitely be open to adding conveniences to clean this up: get("/").should route_to("foo#bar") get("/private_stuff").should_not be_routable Then Joe's DSL could exploit those and we'd get: get "/blog" => "blogs-controller#index" Still not sure about the negative (unroutable). Cheers, David > > > Cheers, > Wincent From joe at faithfulgeek.org Tue Oct 19 14:25:55 2010 From: joe at faithfulgeek.org (Joe Fiorini) Date: Tue, 19 Oct 2010 11:25:55 -0700 (PDT) Subject: [rspec-users] RSpec Routing DSL In-Reply-To: References: <86f2ce8a-560d-4708-9d68-a9a4bfefb66e@i21g2000yqg.googlegroups.com> Message-ID: David: you're right, it's not very rspecish :) There are two changes I made that I wonder if we could see in core are: 1) printing out the path and method in specdoc output 2) setting default scope options per context (not quite working in my example yet) Thoughts? Wincent: I like what you've come up with. Much more rspecish than mine. Doesn't seem too different from what's in rspec-rails 2.0. On Oct 19, 3:05?am, Wincent Colaiuta wrote: > El 18/10/2010, a las 20:20, Joe Fiorini escribi?: > > > I started testing routes for the first time in Rails 3 this weekend > > during Rails Rumble. I was so exhausted that I found writing route > > specs a very painful task. I came up with my own routing DSL and I'd > > love to see it get included in RSpec itself. Before I start adding the > > code to rspec-rails, I'd like to get some feedback and see if there > > are some ways we could clean it up. Basically the DSL looks like: > > > describe "My routes" do > > > ?get "/blog" => { controller: "blogs-controller", action: "index" } > > > end > > > You can see all the details and the module used to make it work here: > >http://gist.github.com/630176. Thoughts? > > I felt the same pain a while back and proposed a DSL too, but it never really got anywhere as there was no consensus about what a new DSL should look like. Full thread here: > > ?http://groups.google.com/group/rspec/browse_thread/thread/50b46ca3e4b... > > I never got as far as submitting a patch because I didn't really like the alternative proposals so wasn't going to code them up (I'd already posted my own working proposal). > > After several iterations, the implementation that I am currently using consists of "map_to", "map_from", "have_routing" (ie. map both ways) and "be_recognized" matchers; these were chosen largely because they don't clash with the existing matchers in RSpec and so I can use them on an "opt-in" basis: > > ?http://gist.github.com/633716 > > Some sample specs: > > ?http://gist.github.com/633723 > > > > One thing to note is how there are two assertions in there where I use "map_to" instead of "have_routing" because of what looks to be a bug in the Rails routing assertion macros. I think there is a Lighthouse ticket for this but the only ones related to "assert_generates" which I can find right now are: > > ?https://rails.lighthouseapp.com/projects/8994/tickets/5260 > ?https://rails.lighthouseapp.com/projects/8994/tickets/5005 > ?https://rails.lighthouseapp.com/projects/8994/tickets/5689 > > At least one of those issues (#5260, #5005) is supposedly resolved in 3.0.2. #5698 was marked as invalid. Tangentially related is this old ticket which I posted: > > ?https://rspec.lighthouseapp.com/projects/5645/tickets/907 > > I thought someone posted a pretty good analysis of exactly what the breakage is and why it happens, but I can't find it. :-( Guess when I get time will have to do some analysis of the Rails codebase and figure out what's happening and put together another ticket. > > While Googling, found this, however, describing changes in 2.0.0: > > ?http://github.com/rspec/rspec-rails/issues/221 > > Which notes that RSpec's "route_to" now delegates to "assert_recognizes" (a one-way assertion) rather than "assert_routing" (a two-way assertion). > > > > Cheers, > Wincent > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From patmaddox at me.com Tue Oct 19 15:04:59 2010 From: patmaddox at me.com (Pat Maddox) Date: Tue, 19 Oct 2010 12:04:59 -0700 Subject: [rspec-users] Testing initialize methods and chained methods In-Reply-To: References: Message-ID: <039C7064-BBE0-4DE8-A807-7D4865490C13@me.com> On Oct 19, 2010, at 12:56 AM, Oscar Del Ben wrote: > I'm having some troubles understanding how to test a couple of things. Usually, if I'm having trouble testing something, it means that my design could probably be improved or changed, but in these cases I think I'm doing the right thing. > > Here's the first scenario: > > class Foo > def initialize > do_something > end > end > > Here I have no idea how to test that the do_something method is called. What are the post-conditions of do_something? Check for those. Pat From dchelimsky at gmail.com Tue Oct 19 15:08:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Oct 2010 14:08:54 -0500 Subject: [rspec-users] Testing initialize methods and chained methods In-Reply-To: <039C7064-BBE0-4DE8-A807-7D4865490C13@me.com> References: <039C7064-BBE0-4DE8-A807-7D4865490C13@me.com> Message-ID: <2D7C143A-A625-42F2-8198-97E660E3293C@gmail.com> On Oct 19, 2010, at 2:04 PM, Pat Maddox wrote: > On Oct 19, 2010, at 12:56 AM, Oscar Del Ben wrote: > >> I'm having some troubles understanding how to test a couple of things. Usually, if I'm having trouble testing something, it means that my design could probably be improved or changed, but in these cases I think I'm doing the right thing. >> >> Here's the first scenario: >> >> class Foo >> def initialize >> do_something >> end >> end >> >> Here I have no idea how to test that the do_something method is called. > > What are the post-conditions of do_something? Check for those. Think "outcomes" as opposed to "post-conditions", which means something very specific (and subtly different) in the context of Design by Contract. From rusty.walters at gmail.com Tue Oct 19 16:46:37 2010 From: rusty.walters at gmail.com (Rusty Walters) Date: Tue, 19 Oct 2010 15:46:37 -0500 Subject: [rspec-users] rspec --help gives undefined method 'Pathname' Message-ID: Trying to setup environment on xandros linux. running ruby 1.9 gem 1.3.7 sudo gem install rspec but when I issue rspec?help I receive the following /usr/lib/ruby/gems/1.9/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb:31:in `ascend_until?: undefined method `Pathname? for RSpec::Core::RubyProject:Module (NoMethodError) from /usr/lib/ruby/gems/1.9/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb:27:in `find_first_parent_containing? from /usr/lib/ruby/gems/1.9/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb:23:in `determine_root? Any help greatly appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattvanhorn at gmail.com Tue Oct 19 17:11:19 2010 From: mattvanhorn at gmail.com (Matthew Van Horn) Date: Tue, 19 Oct 2010 17:11:19 -0400 Subject: [rspec-users] "contain" not defined in view spec In-Reply-To: <6c34197f-5763-4825-b1d8-d57e08649916@v20g2000yqb.googlegroups.com> References: <6c34197f-5763-4825-b1d8-d57e08649916@v20g2000yqb.googlegroups.com> Message-ID: <3DB48862-BC8D-4CD9-8B4F-6C8A34D3E9BD@gmail.com> I also ran into this today. Not sure where the "contain" matcher is, looked in rspec-rails and rspec-expectations, but came up empty. (Rails 3.0.0 / Rspec 2.0.0) -- matt On Oct 18, 2010, at 5:53 PM, Stephen Veit wrote: > > On Oct 18, 3:41 pm, David Chelimsky wrote: >> On Oct 18, 2010, at 3:27 PM, Stephen Veit wrote: >> >>> Using Rails 2 and rspec-rails 2.0.1. >> >> rspec-rails-2 does not support rails-2. Please use rspec- >> rails-1.3.3 for rails-2. >> >> HTH, >> David >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > I meant to type "Rails 3". > > I am using Rails 3 and rspec-rails 2.0.1. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Oct 19 18:24:55 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Oct 2010 17:24:55 -0500 Subject: [rspec-users] "contain" not defined in view spec In-Reply-To: <3DB48862-BC8D-4CD9-8B4F-6C8A34D3E9BD@gmail.com> References: <6c34197f-5763-4825-b1d8-d57e08649916@v20g2000yqb.googlegroups.com> <3DB48862-BC8D-4CD9-8B4F-6C8A34D3E9BD@gmail.com> Message-ID: <088421F9-B359-4EBF-83FC-B23057DD1F7A@gmail.com> On Oct 19, 2010, at 4:11 PM, Matthew Van Horn wrote: > I also ran into this today. Not sure where the "contain" matcher is, looked in rspec-rails and rspec-expectations, but came up empty. > (Rails 3.0.0 / Rspec 2.0.0) Webrat and Capybara each have a contain() matcher. Trick is that Capybara matchers are not available in view specs, so for those you've gotta use Webrat (if you want contain()). > -- matt > > On Oct 18, 2010, at 5:53 PM, Stephen Veit wrote: > >> >> On Oct 18, 3:41 pm, David Chelimsky wrote: >>> On Oct 18, 2010, at 3:27 PM, Stephen Veit wrote: >>> >>>> Using Rails 2 and rspec-rails 2.0.1. >>> >>> rspec-rails-2 does not support rails-2. Please use rspec-rails-1.3.3 for rails-2. >>> >>> HTH, >>> David >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> >> >> I meant to type "Rails 3". >> >> I am using Rails 3 and rspec-rails 2.0.1. >> _______________________________________________ >> 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 trey at 12spokes.com Tue Oct 19 22:07:22 2010 From: trey at 12spokes.com (Trey) Date: Tue, 19 Oct 2010 19:07:22 -0700 (PDT) Subject: [rspec-users] Routing errors with Rails 3.0.1 and Rspec 2.0.1 Message-ID: <1d99d392-45c4-4215-9c23-6cdb83765a51@b9g2000prc.googlegroups.com> I'm sure something is borked in my app, but I can't seem to track it down. A few commits back, my app was fully passing my spec suite. It was on Rails 3.0.0 and Rspec 2.0.0.beta.20. I've now upgraded to rails 3.0.1 and rspec 2.0.1 Now, I'm getting tons, and I mean tons of failures that say things like, to take a simple case: 113) SiteController GET 'about' should be successful Failure/Error: get 'about' No route matches {:action=>"about", :controller=>"site"} # ./spec/controllers/site_controller_spec.rb:21 Here's the spec: describe "GET 'about'" do it "should be successful" do get 'about' response.should be_success end end And the defined route showing up in rake routes about GET / about(.:format) {:controller=>"site", :action=>"about"} This fails if I run rspec by 'rake routes' or by 'bundle exec autotest'. But, and here's the weird thing, if I cause autotest to run that file again, or if I manually run bundle exec rspec spec/ controllers/site_controller_spec.rb, then it passes just fine. Did I miss something I needed to do in my upgrade? If it matters I'm using rvm gemsets. Thanks for any guidance. Trey From orengolan at gmail.com Tue Oct 19 22:15:24 2010 From: orengolan at gmail.com (oren) Date: Tue, 19 Oct 2010 19:15:24 -0700 (PDT) Subject: [rspec-users] rspec 2 - undefined method `redirect_to?' for # Message-ID: I try to test sinatra app using rspec 2.0.0 and rack-test 0.5.6 it "redirect non-authenticated user to logout page" do get '/' last_response.should be_redirect_to('/login) end and I get: undefined method `redirect_to?' for # where can I find reference/guide for methods I can use in rspec 2? I think it might be here, but I am not sure where: http://github.com/rspec/rspec http://github.com/rspec/rspec-core Thanks! From dchelimsky at gmail.com Wed Oct 20 00:55:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Oct 2010 23:55:56 -0500 Subject: [rspec-users] rspec 2 - undefined method `redirect_to?' for # In-Reply-To: References: Message-ID: On Oct 19, 2010, at 9:15 PM, oren wrote: > I try to test sinatra app using rspec 2.0.0 and rack-test 0.5.6 > > it "redirect non-authenticated user to logout page" do > get '/' > last_response.should be_redirect_to('/login) > end > > and I get: > undefined method `redirect_to?' for # Take a look at http://relishapp.com/rspec/rspec-expectations/v/2-0/dir/matchers/predicate-matchers to see how be_redirect_to tries to delegate to redirect_to? on the responses. There is a redirect_to matcher in rspec-rails, but it delegates to a Rails-specific assertion (assert_redirected_to), so you're not going to get that one in a Sinatra app. > where can I find reference/guide for methods I can use in rspec 2? > I think it might be here, but I am not sure where: > http://github.com/rspec/rspec > http://github.com/rspec/rspec-core Documentation is there, plus: http://github.com/rspec/rspec-expectations http://github.com/rspec/rspec-mocks http://relishapp.com/rspec And, of course, The RSpec Book: http://pragprog.com/titles/achbd/the-rspec-book HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicholas.wieland at gmail.com Wed Oct 20 02:30:03 2010 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Tue, 19 Oct 2010 23:30:03 -0700 Subject: [rspec-users] Routing errors with Rails 3.0.1 and Rspec 2.0.1 In-Reply-To: <1d99d392-45c4-4215-9c23-6cdb83765a51@b9g2000prc.googlegroups.com> References: <1d99d392-45c4-4215-9c23-6cdb83765a51@b9g2000prc.googlegroups.com> Message-ID: On Oct 19, 2010, at 7:07 PM, Trey wrote: > I'm sure something is borked in my app, but I can't seem to track it > down. Me too, and routing as well ... constraints( :subdomain => /.+/ ) do match '/dashboard' => 'users#show' end it "routes 'http://test.example.com/dashboard' to UsersController#dashboard with subdomain 'test'" do { :get => 'http://test.example.com/dashboard' }.should route_to( :controller => 'users', :action => 'show', :subdomain => 'test' ) end This fails, and unless I'm not crazy a very similar example was made by David himself some time ago: http://bit.ly/bIK8fA rails 3.0.1 and rspec 2.0.0 (and rvm too) Did we miss something ? ngw From thehcdreamer at gmail.com Wed Oct 20 02:55:21 2010 From: thehcdreamer at gmail.com (Oscar Del Ben) Date: Wed, 20 Oct 2010 08:55:21 +0200 Subject: [rspec-users] Testing initialize methods and chained methods In-Reply-To: <2D7C143A-A625-42F2-8198-97E660E3293C@gmail.com> References: <039C7064-BBE0-4DE8-A807-7D4865490C13@me.com> <2D7C143A-A625-42F2-8198-97E660E3293C@gmail.com> Message-ID: Thanks for all the replies and the help. On Tue, Oct 19, 2010 at 9:08 PM, David Chelimsky wrote: > On Oct 19, 2010, at 2:04 PM, Pat Maddox wrote: > > > On Oct 19, 2010, at 12:56 AM, Oscar Del Ben wrote: > > > >> I'm having some troubles understanding how to test a couple of things. > Usually, if I'm having trouble testing something, it means that my design > could probably be improved or changed, but in these cases I think I'm doing > the right thing. > >> > >> Here's the first scenario: > >> > >> class Foo > >> def initialize > >> do_something > >> end > >> end > >> > >> Here I have no idea how to test that the do_something method is called. > > > > What are the post-conditions of do_something? Check for those. > > Think "outcomes" as opposed to "post-conditions", which means something > very specific (and subtly different) in the context of Design by Contract. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Oscar Del Ben http://oscardelben.com http://freestylemind.com/ http://twitter.com/oscardelben http://facebook.com/freestylemind -------------- next part -------------- An HTML attachment was scrubbed... URL: From orengolan at gmail.com Wed Oct 20 16:11:17 2010 From: orengolan at gmail.com (oren) Date: Wed, 20 Oct 2010 13:11:17 -0700 (PDT) Subject: [rspec-users] rspec 2 - undefined method `redirect_to?' for # In-Reply-To: References: Message-ID: <7f2eb9ab-58d7-40c4-b49b-b686055d861b@a19g2000prb.googlegroups.com> thanks! On Oct 20, 4:55?am, David Chelimsky wrote: > On Oct 19, 2010, at 9:15 PM, oren wrote: > > > I try to test sinatra app using rspec 2.0.0 and rack-test 0.5.6 > > > ?it "redirect non-authenticated user to logout page" do > > ? ?get '/' > > ? ?last_response.should be_redirect_to('/login) > > ?end > > > and I get: > > undefined method `redirect_to?' for # > > Take a look athttp://relishapp.com/rspec/rspec-expectations/v/2-0/dir/matchers/pred...to see how be_redirect_to tries to delegate to redirect_to? on the responses. > > There is a redirect_to matcher in rspec-rails, but it delegates to a Rails-specific assertion (assert_redirected_to), so you're not going to get that one in a Sinatra app. > > > where can I find reference/guide for methods I can use in rspec 2? > > I think it might be here, but I am not sure where: > >http://github.com/rspec/rspec > >http://github.com/rspec/rspec-core > > Documentation is there, plus: > > http://github.com/rspec/rspec-expectationshttp://github.com/rspec/rspec-mocks > > http://relishapp.com/rspec > > And, of course, The RSpec Book:http://pragprog.com/titles/achbd/the-rspec-book > > HTH, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From orengolan at gmail.com Wed Oct 20 22:56:04 2010 From: orengolan at gmail.com (oren) Date: Wed, 20 Oct 2010 19:56:04 -0700 (PDT) Subject: [rspec-users] new syntax question and mocking HTTP_AUTHORIZATION Message-ID: I am specing a sinatra app. it "should send non-valid user to /login" do get '/' last_response.headers['Location'].should == '/reports' end this is working fine but I would like to know how to convert it to the new syntax or if there is a better way to do that. before(:each) { get '/' } subject { last_response } its(:status) {should == 302} require 'ap' its(:headers) {should include('/login')} another question: it "should send valid user to /reports" do get '/', { 'HTTP_AUTHORIZATION' => 'Basic c2cvbGFuOmFBITExMQ==' } last_response.headers['Location'].should == '/reports' end when i debug my method I see that request.env["HTTP_AUTHORIZATION"] is nil, so the header was not sent with it. how to mock it? Thanks From dchelimsky at gmail.com Wed Oct 20 23:19:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 20 Oct 2010 22:19:10 -0500 Subject: [rspec-users] new syntax question and mocking HTTP_AUTHORIZATION In-Reply-To: References: Message-ID: <9FA1D4E3-EB36-47EC-B1BD-63FAECAC5E4A@gmail.com> On Oct 20, 2010, at 9:56 PM, oren wrote: > I am specing a sinatra app. > > it "should send non-valid user to /login" do > get '/' > last_response.headers['Location'].should == '/reports' > end > > this is working fine but I would like to know how to convert it to the > new syntax or if there is a better way to do that. > > before(:each) { get '/' } > subject { last_response } > > its(:status) {should == 302} > require 'ap' > its(:headers) {should include('/login')} This is not "the new syntax." It is simply an alternate syntax that has been around for over a year and works well for a small subset of things you might want to specify like initial state: describe Array do context "when first created" do subject { Array.new } its(:length) { should eq(0) } end end It is not in any way an all-purpose replacement for more specifying _behaviour_. > another question: > > it "should send valid user to /reports" do > get '/', { 'HTTP_AUTHORIZATION' => 'Basic > c2cvbGFuOmFBITExMQ==' } > last_response.headers['Location'].should == '/reports' > end > > when i debug my method I see that request.env["HTTP_AUTHORIZATION"] is > nil, > so the header was not sent with it. how to mock it? I don't have any personal experience w/ Sinatra yet (I know, I know, but there are only so many hours in a day), so I'll leave it to someone else to comment on how to approach the Sinatra questions. Cheers, David From dchelimsky at gmail.com Thu Oct 21 07:53:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Oct 2010 06:53:05 -0500 Subject: [rspec-users] [rspec-devel] Want test case in rspec In-Reply-To: <30016587.post@talk.nabble.com> References: <30016587.post@talk.nabble.com> Message-ID: On Oct 21, 2010, at 1:35 AM, a-iparikh wrote: > I want test case in rspec for: > @drugs = Drug.where('drug_category_id = ?', params[:id]) > has anybody solution for it? Please use the rspec-users mailing list for usage questions (I CC'd rspec-devel to make sure you'd get this). You haven't provided much information here. You're asking how to test a line of code, but what we want to do is specify behaviour of objects at a higher level than that. I'm guessing that this is a controller in a Rails 3 app. Can you tell us which controller this is (DrugsController, DrugCategoriesController, DrugUsersController, etc), what action this is, and what you expect this action to do? From jbiolaz at gmail.com Tue Oct 19 05:49:44 2010 From: jbiolaz at gmail.com (Jbiolaz) Date: Tue, 19 Oct 2010 02:49:44 -0700 (PDT) Subject: [rspec-users] Lot of error when running all spec Message-ID: Hi, I'm pretty new to rspec. I'm writing some spec for a Rails 3.0 app with Devise (branch omniauth), rspec 2.0.1 and factory_girl. When I run spec file by file (ex: rspec spec/models/ document_spec.rb) , it run sometimes withtout error and sometimes with some errors (duplicate entry in DB). That's the first I don't understand: Why it's sometimes working and sometimes not ? How can I do to make this work all the time (except of course if there is some change in the model that really break the test) ?. I try also to run all my spec at once (rspec spec) but I have a lot of error with Devise: here is my stack error: Failure/Error: @user = Factory(:user) Could not find a valid mapping for # # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/lib/devise/ mapping.rb:40:in `find_scope!' # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ devise/mailer.rb:26:in `initialize_from_record' # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ devise/mailer.rb:21:in `setup_mail' # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ devise/mailer.rb:6:in `confirmation_instructions' # ./lock/ruby/1.8/gems/actionpack-3.0.1/lib/abstract_controller/ base.rb:150:in `send_action' # ./lock/ruby/1.8/gems/actionpack-3.0.1/lib/abstract_controller/ base.rb:150:in `process_action' # ./lock/ruby/1.8/gems/actionpack-3.0.1/lib/abstract_controller/ base.rb:119:in `process' # ./lock/ruby/1.8/gems/actionpack-3.0.1/lib/abstract_controller/ rendering.rb:40:in `process' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ old_api.rb:75:in `process' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ base.rb:446:in `process' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ base.rb:441:in `initialize' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ base.rb:425:in `new' # ./lock/ruby/1.8/gems/actionmailer-3.0.1/lib/action_mailer/ base.rb:425:in `method_missing' # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/lib/devise/ models/confirmable.rb:50:in `send_confirmation_instructions' # ./lock/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/ callbacks.rb:422:in `_run_create_callbacks' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ callbacks.rb:281:in `create' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ persistence.rb:247:in `create_or_update' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ callbacks.rb:277:in `create_or_update' # ./lock/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/ callbacks.rb:423:in `_run_save_callbacks' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ callbacks.rb:277:in `create_or_update' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ persistence.rb:56:in `save!' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ validations.rb:49:in `save!' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ attribute_methods/dirty.rb:30:in `save!' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:242:in `save!' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:289:in `with_transaction_returning_status' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ connection_adapters/abstract/database_statements.rb:139:in `transaction' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:204:in `transaction' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:287:in `with_transaction_returning_status' # ./lock/ruby/1.8/gems/activerecord-3.0.1/lib/active_record/ transactions.rb:242:in `save!' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/proxy/ create.rb:6:in `result' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/ factory.rb:327:in `run' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/ factory.rb:270:in `create' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/ factory.rb:301:in `send' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl/ factory.rb:301:in `default_strategy' # ./lock/ruby/1.8/gems/factory_girl-1.3.2/lib/factory_girl.rb: 20:in `Factory' # ./spec/models/user_spec.rb:62 # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:29:in `instance_eval' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:29:in `run_in' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:60:in `run_all' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:60:in `each' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:60:in `run_all' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/hooks.rb:106:in `run_hook' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:188:in `eval_before_eachs' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:188:in `each' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:188:in `eval_before_eachs' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:121:in `run_before_each' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:46:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:86:in `call' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:86:in `with_around_hooks' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:44:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:80:in `call' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:80:in `with_pending_capture' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:79:in `catch' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:79:in `with_pending_capture' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example.rb:43:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:260:in `run_examples' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:256:in `map' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:256:in `run_examples' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:230:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:231:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:231:in `map' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/example_group.rb:231:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/command_line.rb:26:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/command_line.rb:26:in `map' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/command_line.rb:26:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/reporter.rb:11:in `report' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/command_line.rb:23:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/runner.rb:55:in `run_in_process' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/runner.rb:46:in `run' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/gems/rspec-core-2.0.1/ lib/rspec/core/runner.rb:10:in `autorun' # /Users/migoo/.rvm/gems/ruby-1.8.7-p174/bin/rspec:19 So, what can I do to avoid this error and make my test running ? Thanks a lot for your help ! Jonathan From danpal at gmail.com Wed Oct 20 19:27:23 2010 From: danpal at gmail.com (Daniel Palacio) Date: Wed, 20 Oct 2010 18:27:23 -0500 Subject: [rspec-users] rspec error's when checking LayoutLinks from the railstutorials Message-ID: I am following the rails tutorial: http://railstutorial.org/chapters/filling-in-the-layout#top Basically the test is something like: spec/requests/layout_links_spec.rb require 'spec_helper' describe "LayoutLinks" do it "should have a Home page at '/'" do get '/' response.should have_selector('title', :content => "Home") end Routes: root :to => 'pages#home' 1. I already googled and found http://stackoverflow.com/questions/3517724/rspec-is-giving-an-error-with-my-layout-links-from-the-rails-tutorial-failure-e 2. I already tried changing the rspec version to 2.0.0.beta.18, but I still get the same error. Here is the output: dpalacio:sample_app dpalacio$ rspec -v 2.0.1 dpalacio:sample_app dpalacio$ rspec spec/requests/ FFFFF Finished in 0.55501 seconds 5 examples, 5 failures 1) LayoutLinks should have a Home page at '/' Failure/Error: Unable to find matching line from backtrace stack level too deep # /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185 ..... Is there any other thing that might be causing the problem ? Thanks -dan From dchelimsky at gmail.com Thu Oct 21 08:23:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Oct 2010 07:23:46 -0500 Subject: [rspec-users] rspec error's when checking LayoutLinks from the railstutorials In-Reply-To: References: Message-ID: <12940B11-128D-4CA7-92ED-B65287CD53F9@gmail.com> On Oct 20, 2010, at 6:27 PM, Daniel Palacio wrote: > I am following the rails tutorial: > http://railstutorial.org/chapters/filling-in-the-layout#top > > Basically the test is something like: > > spec/requests/layout_links_spec.rb > require 'spec_helper' > > describe "LayoutLinks" do > > it "should have a Home page at '/'" do > get '/' > response.should have_selector('title', :content => "Home") > end > > > Routes: > root :to => 'pages#home' > > > 1. I already googled and found > http://stackoverflow.com/questions/3517724/rspec-is-giving-an-error-with-my-layout-links-from-the-rails-tutorial-failure-e > > 2. I already tried changing the rspec version to 2.0.0.beta.18, but I > still get the same error. > > > Here is the output: > > dpalacio:sample_app dpalacio$ rspec -v > 2.0.1 > dpalacio:sample_app dpalacio$ rspec spec/requests/ > FFFFF > > Finished in 0.55501 seconds > 5 examples, 5 failures > > 1) LayoutLinks should have a Home page at '/' > Failure/Error: Unable to find matching line from backtrace > stack level too deep > # /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185 At this point you should be using rails-3.0.1 and rspec-rails-2.0.1, and webrat-0.7.2. Are those the versions you are using? From dchelimsky at gmail.com Thu Oct 21 08:29:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Oct 2010 07:29:53 -0500 Subject: [rspec-users] Lot of error when running all spec In-Reply-To: References: Message-ID: On Oct 19, 2010, at 4:49 AM, Jbiolaz wrote: > Hi, > > I'm pretty new to rspec. I'm writing some spec for a Rails 3.0 app > with Devise (branch omniauth), rspec 2.0.1 and factory_girl. > > When I run spec file by file (ex: rspec spec/models/ > document_spec.rb) , it run sometimes withtout error and sometimes with > some errors (duplicate entry in DB). Make sure you've got config.use_transactional_fixtures = true in spec/spec_helper.rb and that you are not setting up any models in before(:all) blocks. > That's the first I don't > understand: Why it's sometimes working and sometimes not ? How can I > do to make this work all the time (except of course if there is some > change in the model that really break the test) ?. > > I try also to run all my spec at once (rspec spec) but I have a lot of > error with Devise: > > here is my stack error: > > Failure/Error: @user = Factory(:user) > Could not find a valid mapping for # > # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/lib/devise/ > mapping.rb:40:in `find_scope!' > # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ > devise/mailer.rb:26:in `initialize_from_record' > # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ > devise/mailer.rb:21:in `setup_mail' > # ./lock/ruby/1.8/bundler/gems/devise-31edd76369a8/app/mailers/ > devise/mailer.rb:6:in `confirmation_instructions' > So, what can I do to avoid this error and make my test running ? > > Thanks a lot for your help ! > Jonathan Not sure about the Devise issue. I'd recommend checking http://groups.google.com/group/plataformatec-devise for that one. Good luck, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Thu Oct 21 09:10:29 2010 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 21 Oct 2010 09:10:29 -0400 Subject: [rspec-users] new syntax question and mocking HTTP_AUTHORIZATION In-Reply-To: <9FA1D4E3-EB36-47EC-B1BD-63FAECAC5E4A@gmail.com> References: <9FA1D4E3-EB36-47EC-B1BD-63FAECAC5E4A@gmail.com> Message-ID: On Wed, Oct 20, 2010 at 11:19 PM, David Chelimsky wrote: > On Oct 20, 2010, at 9:56 PM, oren wrote: > > > I am specing a sinatra app. > > > > it "should send non-valid user to /login" do > > get '/' > > last_response.headers['Location'].should == '/reports' > > end > > > > this is working fine but I would like to know how to convert it to the > > new syntax or if there is a better way to do that. > > > > before(:each) { get '/' } > > subject { last_response } > > > > its(:status) {should == 302} > > require 'ap' > > its(:headers) {should include('/login')} > > This is not "the new syntax." It is simply an alternate syntax that has > been around for over a year and works well for a small subset of things you > might want to specify like initial state: > > describe Array do > context "when first created" do > subject { Array.new } > its(:length) { should eq(0) } > end > end > > It is not in any way an all-purpose replacement for more specifying > _behaviour_. > > > another question: > > > > it "should send valid user to /reports" do > > get '/', { 'HTTP_AUTHORIZATION' => 'Basic > > c2cvbGFuOmFBITExMQ==' } > > last_response.headers['Location'].should == '/reports' > > end > > > > when i debug my method I see that request.env["HTTP_AUTHORIZATION"] is > > nil, > > so the header was not sent with it. how to mock it? > I think you are passing your headers in as the request params. I believe you're using rack-test under the covers and the api for #get is: get(uri, params = {}, env = {}, &block) I think env is where you want your headers. so maybe: get '/', {}, { 'HTTP_AUTHORIZATION' => 'Basic c2cvbGFuOmFBITExMQ==' } I haven't written a Sinatra app in a while, but I hope this helps, Zach > > I don't have any personal experience w/ Sinatra yet (I know, I know, but > there are only so many hours in a day), so I'll leave it to someone else to > comment on how to approach the Sinatra questions. > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) -------------- next part -------------- An HTML attachment was scrubbed... URL: From orengolan at gmail.com Thu Oct 21 13:41:40 2010 From: orengolan at gmail.com (oren) Date: Thu, 21 Oct 2010 10:41:40 -0700 (PDT) Subject: [rspec-users] new syntax question and mocking HTTP_AUTHORIZATION In-Reply-To: References: <9FA1D4E3-EB36-47EC-B1BD-63FAECAC5E4A@gmail.com> Message-ID: <9c37c854-2bf1-4e26-bb3b-102d719e9ead@35g2000prb.googlegroups.com> works! thanks so much for not only solving it but also mentioning rack- test. I see the get method here: http://github.com/brynary/rack-test/blob/master/lib/rack/test.rb but it's not clear how to use that (I guess it depends on your experience), I wish there was a usage/sample section.. On Oct 21, 1:10?pm, Zach Dennis wrote: > On Wed, Oct 20, 2010 at 11:19 PM, David Chelimsky wrote: > > > > > > > > > > > On Oct 20, 2010, at 9:56 PM, oren wrote: > > > > I am specing a sinatra app. > > > > it "should send non-valid user to /login" do > > > ?get '/' > > > ?last_response.headers['Location'].should == '/reports' > > > end > > > > this is working fine but I would like to know how to convert it to the > > > new syntax or if there is a better way to do that. > > > > before(:each) { get '/' } > > > subject { last_response } > > > > its(:status) {should == 302} > > > require 'ap' > > > its(:headers) {should include('/login')} > > > This is not "the new syntax." It is simply an alternate syntax that has > > been around for over a year and works well for a small subset of things you > > might want to specify like initial state: > > > describe Array do > > ?context "when first created" do > > ? ?subject { Array.new } > > ? ?its(:length) { should eq(0) } > > ?end > > end > > > It is not in any way an all-purpose replacement for more specifying > > _behaviour_. > > > > another question: > > > > ? it "should send valid user to /reports" do > > > ? ? ? ?get '/', { 'HTTP_AUTHORIZATION' => 'Basic > > > c2cvbGFuOmFBITExMQ==' } > > > ? ? ? ?last_response.headers['Location'].should == '/reports' > > > ? ? ?end > > > > when i debug my method I see that request.env["HTTP_AUTHORIZATION"] is > > > nil, > > > so the header was not sent with it. how to mock it? > > I think you are passing your headers in as the request params. I believe > you're using rack-test under the covers and the api for #get is: > > ? ? ? get(uri, params = {}, env = {}, &block) > > I think env is where you want your headers. so maybe: > > ? ? ? get '/', {}, { 'HTTP_AUTHORIZATION' => 'Basic c2cvbGFuOmFBITExMQ==' } > > I haven't written a Sinatra app in a while, but I hope this helps, > > Zach > > > > > I don't have any personal experience w/ Sinatra yet (I know, I know, but > > there are only so many hours in a day), so I'll leave it to someone else to > > comment on how to approach the Sinatra questions. > > > Cheers, > > David > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > -- > Zach Dennishttp://www.continuousthinking.com(personal)http://www.mutuallyhuman.com(hire me)http://ideafoundry.info/behavior-driven-development(first rate BDD > training) > @zachdennis (twitter) > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From rspec-users.20.dissolved at dfgh.net Thu Oct 21 16:20:29 2010 From: rspec-users.20.dissolved at dfgh.net (rspec-users.20.dissolved at dfgh.net) Date: Thu, 21 Oct 2010 16:20:29 -0400 Subject: [rspec-users] Tests Not Detected, Says 0 Examples Message-ID: <23E30416-D7D1-45DA-99DF-9AD6F3FC105B@fountainlogic.com> Hi, I'm trying to get tests running on a gem I forked on github. When I try to run tests, it says "0 examples", despite lots of tests in the /spec directory. Here is some pertinent information: Code at: http://github.com/dissolved/yahoo_stock RSpec version 2.0.1 Some examples: 01:05:43 [xenon:~/Development/ruby/yahoo_stock] [ruby-1.9.2-p0 at rails3.0] master $ rspec spec Finished in 0.00005 seconds 0 examples, 0 failures 01:09:03 [xenon:~/Development/ruby/yahoo_stock] [ruby-1.9.2-p0 at rails3.0] master $ rspec spec/yahoo_stock/history_spec.rb Finished in 0.00004 seconds 0 examples, 0 failures I've got an email out to the primary developer of the original gem, but think I may be having a more general problem. The readme for the project does say to use 'rake spec' using RSpec 1.2.2, but that yields a "No Rakefile found" error. What am I missing here? Thanks for any help! Ryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From cassiommc at gmail.com Thu Oct 21 10:13:07 2010 From: cassiommc at gmail.com (=?ISO-8859-1?Q?C=E1ssio_Marques?=) Date: Thu, 21 Oct 2010 07:13:07 -0700 (PDT) Subject: [rspec-users] ExampleGroup in Rspec 2 Message-ID: Hello, In Rspec 1.x I I could create custom ExampleGroups that would have behaviour similar to controller specs. How can I accomplish something similar to this in Rspec 2? I would like to create an example group to test my Cells instances ( http://github.com/apotonick/cells ). Thanks! From jarmo.p at gmail.com Fri Oct 22 08:46:18 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Fri, 22 Oct 2010 05:46:18 -0700 (PDT) Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? Message-ID: Hello! I'm trying to run autotest under Windows when using Rails 3.0.1 and RSpec 2.0.1. It's not working so far. This is what happens: C:\Users\jarmo\Desktop\minu\projects\Ruby\sample_app>autotest loading autotest/rails_rspec2 style: RailsRspec2 bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby -S C:/bin/pik/Ruby-187- p302/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/bin/rspec --autotest 'C:/ Users/jarmo /Desktop/minu/projects/Ruby/sample_app/spec/controllers/ pages_controller_spec.rb' bundler: command not found: C:\bin\pik\Ruby-187-p302\bin\ruby Install missing gem binaries with `bundle install` ... and then i have to interrupt it manually. I have installed gems autotest and autotest-rails-pure. Anything else i have to do to get it running? Jarmo From katrina.owen at gmail.com Sat Oct 23 15:40:37 2010 From: katrina.owen at gmail.com (Katrina) Date: Sat, 23 Oct 2010 12:40:37 -0700 (PDT) Subject: [rspec-users] Symbols in strings out in stubbed response Message-ID: <9f513946-b504-469a-a4cd-be45ac50bdf9@a37g2000yqi.googlegroups.com> I have a test that looks like this: describe ChannelsController, "GET edit" do it "assigns the greetings summary" do summary = {:total => 139, :submitted => 97, :published => 82, :removed => 12} Greeting.stub(:summary).and_return summary get :index assigns(:summary).should eq(summary) end end It fails with the following: expected {:total=>139, :submitted=>97, :published=>82, :removed=>12} got {"total"=>139, "submitted"=>97, "published"=>82, "removed"=>12} The code that is getting called is this: # ChannelsController def index @summary = Greeting.summary end # Greeting def self.summary { :total => self.count, :submitted => self.submitted.count, :published => self.published.count, :removed => self.removed.count } end I expected this example to pass, and I can't figure out if I should be doing something differently either in the code itself or in the test. Any insights? Thanks, Katrina From dchelimsky at gmail.com Sat Oct 23 20:21:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Oct 2010 22:21:53 -0200 Subject: [rspec-users] Symbols in strings out in stubbed response In-Reply-To: <9f513946-b504-469a-a4cd-be45ac50bdf9@a37g2000yqi.googlegroups.com> References: <9f513946-b504-469a-a4cd-be45ac50bdf9@a37g2000yqi.googlegroups.com> Message-ID: On Oct 23, 2010, at 5:40 PM, Katrina wrote: > I have a test that looks like this: > > describe ChannelsController, "GET edit" do > it "assigns the greetings summary" do > summary = {:total => 139, :submitted => 97, :published => > 82, :removed => 12} > Greeting.stub(:summary).and_return summary > get :index > assigns(:summary).should eq(summary) > end > end > > It fails with the following: > expected {:total=>139, :submitted=>97, :published=>82, :removed=>12} > got {"total"=>139, "submitted"=>97, "published"=>82, > "removed"=>12} > > The code that is getting called is this: > > # ChannelsController > def index > @summary = Greeting.summary > end > > # Greeting > def self.summary > { > :total => self.count, > :submitted => self.submitted.count, > :published => self.published.count, > :removed => self.removed.count > } > end The definition of self.summary shouldn't matter here since it's being stubbed in the example. > I expected this example to pass, I would have too, but it looks like Rails is converting hashes that get assigned to views to HashWithIndifferentAccess, which only looks at Strings in its implementation of ==. Take a look at http://gist.github.com/642878. The problem here is that it would be unwise for HashWithIndifferentAccess to implement == any differently, because you'd end up with surprising results (a == b would pass, but b == a would fail). So you have to assume that the keys are Strings regardless of what you set in the example. Therefore, I'd recommend setting Strings in the example in order to keep sane :) HTH, David > and I can't figure out if I should be > doing something differently either in the code itself or in the test. > > Any insights? > > Thanks, > Katrina From arno.rosemann at googlemail.com Fri Oct 22 16:34:38 2010 From: arno.rosemann at googlemail.com (mkorfmann) Date: Fri, 22 Oct 2010 13:34:38 -0700 (PDT) Subject: [rspec-users] Tests Not Detected, Says 0 Examples In-Reply-To: <23E30416-D7D1-45DA-99DF-9AD6F3FC105B@fountainlogic.com> References: <23E30416-D7D1-45DA-99DF-9AD6F3FC105B@fountainlogic.com> Message-ID: <13dff015-fb2c-4ba8-9219-4dcd6b4f10f4@c10g2000yqh.googlegroups.com> Hey, I second that, exactly the same happened to me today while trying to run the spec's for the simple-navigation gem. ------------------------------ Manuel-Korfmanns-MacBook-Pro:simple-navigation mkorfmann$ rspec spec/ Finished in 0.00005 seconds 0 examples, 0 failures ----------------------------- << version information >> Manuel-Korfmanns-MacBook-Pro:simple-navigation mkorfmann$ which rspec /Users/mkorfmann/.rvm/gems/ruby-1.9.2-head/bin/rspec Manuel-Korfmanns-MacBook-Pro:simple-navigation mkorfmann$ rspec -v 2.0.0 Manuel-Korfmanns-MacBook-Pro:simple-navigation mkorfmann$ ----------------------------- Best regards, Manuel On Oct 21, 10:20?pm, rspec-users.20.dissol... at dfgh.net wrote: > Hi, > > I'm trying to get tests running on a gem I forked on github. When I try to run tests, it says "0 examples", despite lots of tests in the /spec directory. Here is some pertinent information: > > Code at:http://github.com/dissolved/yahoo_stock > RSpec version 2.0.1 > > Some examples: > > 01:05:43 [xenon:~/Development/ruby/yahoo_stock] > [ruby-1.9.2... at rails3.0] master $ rspec spec > > Finished in 0.00005 seconds > 0 examples, 0 failures > > 01:09:03 [xenon:~/Development/ruby/yahoo_stock] > [ruby-1.9.2... at rails3.0] master $ rspec spec/yahoo_stock/history_spec.rb > > Finished in 0.00004 seconds > 0 examples, 0 failures > > I've got an email out to the primary developer of the original gem, but think I may be having a more general problem. The readme for the project does say to use 'rake spec' using RSpec 1.2.2, but that yields a "No Rakefile found" error. > > What am I missing here? > > Thanks for any help! > Ryan > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From deyolped at gmail.com Sat Oct 23 09:04:12 2010 From: deyolped at gmail.com (deploy) Date: Sat, 23 Oct 2010 06:04:12 -0700 (PDT) Subject: [rspec-users] Spec'ing methods which essentially filter associations Message-ID: I've been spec'ing for a long time, but I've never discovered the answer to this, so a definitive answer would be great! Whats the best way to spec a method which basically filters an association? class Thing < ActiveRecord::Base has_many :others def foos others.all(:conditions => { ... }) end end I don't like the idea of creating a load of associated records in my spec and testing the returned result as I am not testing the associated model and as such would prefer any references to it to be mocked out, so the best I can some up with is this super lame test which is clearly way too implementation specific and essentially useless. describe Thing do describe 'foos' do before :each do @thing = Thing.new @others_proxy = mock('others proxy') @others_proxy.stub!(:all) @thing.stub!(:others).and_return(@others_proxy) end it 'should return the associated others which meet the conditions' do @others_proxy.should_receive(:all).with({ :conditions => ' ... ' }) @thing.foos end end end So what's the best practice in this case? Pastie is here for pretty formatting: http://pastie.org/1242892 Thanks. P.S. This is old code I've inherited so I'm just trying to retrofit RSpec 1.3x to it before I start refactoring and bringing up to date with rails 3/rspec 2, so basically what I mean is what's the answer if the model simply is how it is and can't be changed? From peter.havens at gmail.com Sat Oct 23 17:29:54 2010 From: peter.havens at gmail.com (Peter Havens) Date: Sat, 23 Oct 2010 14:29:54 -0700 (PDT) Subject: [rspec-users] Symbols in strings out in stubbed response In-Reply-To: <9f513946-b504-469a-a4cd-be45ac50bdf9@a37g2000yqi.googlegroups.com> References: <9f513946-b504-469a-a4cd-be45ac50bdf9@a37g2000yqi.googlegroups.com> Message-ID: <00e2645e-9236-4daf-9ed0-e8f5c93228f5@k22g2000yqh.googlegroups.com> On Oct 23, 1:40?pm, Katrina wrote: > > [...] > It fails with the following: > expected {:total=>139 #... > ? ? ? ?got {"total"=>139 #... > [...} I think the problem you're having is that you're expecting/stubbing symbols for your keys, but the keys for parameters are strings. Good luck, Pete From dchelimsky at gmail.com Sat Oct 23 21:51:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Oct 2010 23:51:05 -0200 Subject: [rspec-users] Symbols in strings out in stubbed response In-Reply-To: <00e2645e-9236-4daf-9ed0-e8f5c93228f5@k22g2000yqh.googlegroups.com> References: <9f513946-b504-469a-a4cd-be45ac50bdf9@a37g2000yqi.googlegroups.com> <00e2645e-9236-4daf-9ed0-e8f5c93228f5@k22g2000yqh.googlegroups.com> Message-ID: <23E12ADD-BA16-4B84-A3CD-C90085034FD5@gmail.com> On Oct 23, 2010, at 7:29 PM, Peter Havens wrote: > On Oct 23, 1:40 pm, Katrina wrote: >> >> [...] >> It fails with the following: >> expected {:total=>139 #... >> got {"total"=>139 #... >> [...} > > I think the problem you're having is that you're expecting/stubbing > symbols for your keys, but the keys for parameters are strings. This hash wasn't a params hash - it was coming directly from a model, and then exposed to the view by Rails. The problem is that Rails converts hashes assigned to views into HashWithIndifferentAccess, which do not treat Symbols and Strings indifferently when comparing complete hashes, even though they let you access the keys indifferently. in Katrina's case, this would pass: assigns(:summary)[:total].should eq(139) assigns(:summary)[:submitted].should eq(97) assigns(:summary)[:published].should eq(82) assigns(:summary)[:removed].should eq(12) Make sense? From dchelimsky at gmail.com Sat Oct 23 22:03:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 24 Oct 2010 00:03:12 -0200 Subject: [rspec-users] Tests Not Detected, Says 0 Examples In-Reply-To: <23E30416-D7D1-45DA-99DF-9AD6F3FC105B@fountainlogic.com> References: <23E30416-D7D1-45DA-99DF-9AD6F3FC105B@fountainlogic.com> Message-ID: <247EBA3E-E2F3-463C-B331-BE44254D6358@gmail.com> On Oct 21, 2010, at 6:20 PM, rspec-users.20.dissolved at dfgh.net wrote: > Hi, > > I'm trying to get tests running on a gem I forked on github. When I try to run tests, it says "0 examples", despite lots of tests in the /spec directory. Here is some pertinent information: > > Code at: http://github.com/dissolved/yahoo_stock > RSpec version 2.0.1 > > Some examples: > > 01:05:43 [xenon:~/Development/ruby/yahoo_stock] > [ruby-1.9.2-p0 at rails3.0] master $ rspec spec > > Finished in 0.00005 seconds > 0 examples, 0 failures > > 01:09:03 [xenon:~/Development/ruby/yahoo_stock] > [ruby-1.9.2-p0 at rails3.0] master $ rspec spec/yahoo_stock/history_spec.rb > > Finished in 0.00004 seconds > 0 examples, 0 failures > > > I've got an email out to the primary developer of the original gem, but think I may be having a more general problem. The readme for the project does say to use 'rake spec' using RSpec 1.2.2, but that yields a "No Rakefile found" error. > > What am I missing here? RSpec-2 is nearly 100% backward compatible when it comes to how specs are structured, matchers, etc, but there are changes to important pieces that could lead to what your seeing. For example the top level directory is 'rspec' instead of 'spec', so if the spec_helper in the app says "require 'spec'", then things are likely to fall apart. I'd stick with rspec-1.2.2 if that's what the project says works. In terms of the "No Rakefile found" error, that comes directly from rake, so if there _is_ a Rakefile in the directory you're calling "rake spec" in, then I'm at a loss. Anybody else have any insights? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Oct 23 22:34:31 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 24 Oct 2010 00:34:31 -0200 Subject: [rspec-users] Spec'ing methods which essentially filter associations In-Reply-To: References: Message-ID: On Oct 23, 2010, at 11:04 AM, deploy wrote: > I've been spec'ing for a long time, but I've never discovered the > answer to this, so a definitive answer would be great! > > Whats the best way to spec a method which basically filters an > association? > > class Thing < ActiveRecord::Base > has_many :others > > def foos > others.all(:conditions => { ... }) > end > end > > I don't like the idea of creating a load of associated records in my > spec and testing the returned result as I am not testing the > associated model and as such would prefer any references to it to be > mocked out, so the best I can some up with is this super lame test > which is clearly way too implementation specific and essentially > useless. > > describe Thing do > describe 'foos' do > before :each do > @thing = Thing.new > @others_proxy = mock('others proxy') > @others_proxy.stub!(:all) > @thing.stub!(:others).and_return(@others_proxy) > end > > it 'should return the associated others which meet the conditions' > do > @others_proxy.should_receive(:all).with({ :conditions => ' ... > ' }) > @thing.foos > end > end > end > > So what's the best practice in this case? There are no 'best practices' absent _all_ of the context of the application, dev stack, dev team, other apps the team builds, etc. That aside ... When it comes to spec'ing filters, I tend to just use ActiveRecord (or whatever ORM I'm using). It's OK for some examples to hit the DB, and this is a good case for allowing it in my view, as the examples end up being more clear and readable and less brittle. HTH, David > Pastie is here for pretty formatting: http://pastie.org/1242892 > > Thanks. > > P.S. This is old code I've inherited so I'm just trying to retrofit > RSpec 1.3x to it before I start refactoring and bringing up to date > with rails 3/rspec 2, so basically what I mean is what's the answer if > the model simply is how it is and can't be changed? From katrina.owen at gmail.com Sun Oct 24 04:58:38 2010 From: katrina.owen at gmail.com (Katrina Owen) Date: Sun, 24 Oct 2010 10:58:38 +0200 Subject: [rspec-users] Symbols in strings out in stubbed response In-Reply-To: <23E12ADD-BA16-4B84-A3CD-C90085034FD5@gmail.com> References: <9f513946-b504-469a-a4cd-be45ac50bdf9@a37g2000yqi.googlegroups.com> <00e2645e-9236-4daf-9ed0-e8f5c93228f5@k22g2000yqh.googlegroups.com> <23E12ADD-BA16-4B84-A3CD-C90085034FD5@gmail.com> Message-ID: On Sun, Oct 24, 2010 at 3:51 AM, David Chelimsky wrote: > The problem is that Rails converts hashes assigned to views into HashWithIndifferentAccess, which do not treat Symbols and Strings indifferently when comparing complete hashes, even though they let you access the keys indifferently. > > (snip) > > Make sense? Ah, sanity returns. Thanks :) From deyolped at gmail.com Sun Oct 24 12:13:26 2010 From: deyolped at gmail.com (deploy) Date: Sun, 24 Oct 2010 09:13:26 -0700 (PDT) Subject: [rspec-users] Spec'ing methods which essentially filter associations In-Reply-To: References: Message-ID: <5da8ba51-5486-46a4-9ad7-dd1c7efb0620@t20g2000yqa.googlegroups.com> Thanks David, This is just indicative of a big problem I think all my tests have. I rarely/never use fixtures or the ORM for models that I'm not directly testing. I just can't bring myself to do. Instead I tend to stub and mock things out like above. The consequence is that all my specs (of which there are a lot) are very tightly bound to the implementation rather than the behaviour and as such are very brittle. If a show action contains this (old Rails I know) @thing = Thing.find(:first, :order => "created_at DESC") I'll end up stubbing it out with @thing = mock_model(Thing) Thing.stub!(:find).with(:first, :order => "created_at DESC").and_return(@thing) which obviously breaks as soon as someone refactors. I don't know ... maybe I'm just not a natural tester :( Is everyone else using factories and fixtures these days or am I not alone? On Oct 24, 3:34?am, David Chelimsky wrote: > On Oct 23, 2010, at 11:04 AM, deploy wrote: > > > > > > > > > > > I've been spec'ing for a long time, but I've never discovered the > > answer to this, so a definitive answer would be great! > > > Whats the best way to spec a method which basically filters an > > association? > > > class Thing < ActiveRecord::Base > > ?has_many :others > > > ?def foos > > ? ?others.all(:conditions => { ... }) > > ?end > > end > > > I don't like the idea of creating a load of associated records in my > > spec and testing the returned result as I am not testing the > > associated model and as such would prefer any references to it to be > > mocked out, so the best I can some up with is this super lame test > > which is clearly way too implementation specific and essentially > > useless. > > > describe Thing do > > ?describe 'foos' do > > ? ?before :each do > > ? ? ?@thing = Thing.new > > ? ? ?@others_proxy = mock('others proxy') > > ? ? ?@others_proxy.stub!(:all) > > ? ? ?@thing.stub!(:others).and_return(@others_proxy) > > ? ?end > > > ? ?it 'should return the associated others which meet the conditions' > > do > > ? ? ?@others_proxy.should_receive(:all).with({ :conditions => ' ... > > ' }) > > ? ? ?@thing.foos > > ? ?end > > ?end > > end > > > So what's the best practice in this case? > > > There are no 'best practices' absent _all_ of the context of the application, dev stack, dev team, other apps the team builds, etc. That aside ... > > > When it comes to spec'ing filters, I tend to just use ActiveRecord (or whatever ORM I'm using). It's OK for some examples to hit the DB, and this is a good case for allowing it in my view, as the examples end up being more clear and readable and less brittle. > > HTH, > David > > > Pastie is here for pretty formatting:http://pastie.org/1242892 > > > Thanks. > > > P.S. This is old code I've inherited so I'm just trying to retrofit > > RSpec 1.3x to it before I start refactoring and bringing up to date > > with rails 3/rspec 2, so basically what I mean is what's the answer if > > the model simply is how it is and can't be changed? > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Oct 24 13:33:40 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 24 Oct 2010 15:33:40 -0200 Subject: [rspec-users] Spec'ing methods which essentially filter associations In-Reply-To: <5da8ba51-5486-46a4-9ad7-dd1c7efb0620@t20g2000yqa.googlegroups.com> References: <5da8ba51-5486-46a4-9ad7-dd1c7efb0620@t20g2000yqa.googlegroups.com> Message-ID: <81D831D6-6D9A-4BF9-9BF1-8BC8757331C7@gmail.com> On Oct 24, 2010, at 2:13 PM, deploy wrote: > On Oct 24, 3:34 am, David Chelimsky wrote: >> On Oct 23, 2010, at 11:04 AM, deploy wrote: >>> I've been spec'ing for a long time, but I've never discovered the >>> answer to this, so a definitive answer would be great! >> >>> Whats the best way to spec a method which basically filters an >>> association? >> >>> class Thing < ActiveRecord::Base >>> has_many :others >> >>> def foos >>> others.all(:conditions => { ... }) >>> end >>> end >> >>> I don't like the idea of creating a load of associated records in my >>> spec and testing the returned result as I am not testing the >>> associated model and as such would prefer any references to it to be >>> mocked out, so the best I can some up with is this super lame test >>> which is clearly way too implementation specific and essentially >>> useless. >> >>> describe Thing do >>> describe 'foos' do >>> before :each do >>> @thing = Thing.new >>> @others_proxy = mock('others proxy') >>> @others_proxy.stub!(:all) >>> @thing.stub!(:others).and_return(@others_proxy) >>> end >> >>> it 'should return the associated others which meet the conditions' >>> do >>> @others_proxy.should_receive(:all).with({ :conditions => ' ... >>> ' }) >>> @thing.foos >>> end >>> end >>> end >> >>> So what's the best practice in this case? >> >> >> There are no 'best practices' absent _all_ of the context of the application, dev stack, dev team, other apps the team builds, etc. That aside ... >> >> >> When it comes to spec'ing filters, I tend to just use ActiveRecord (or whatever ORM I'm using). It's OK for some examples to hit the DB, and this is a good case for allowing it in my view, as the examples end up being more clear and readable and less brittle. > Thanks David, > > This is just indicative of a big problem I think all my tests have. I > rarely/never use fixtures or the ORM for models that I'm not directly > testing. I just can't bring myself to do. Instead I tend to stub and > mock things out like above. The consequence is that all my specs (of > which there are a lot) are very tightly bound to the implementation > rather than the behaviour and as such are very brittle. > > If a show action contains this (old Rails I know) > > @thing = Thing.find(:first, :order => "created_at DESC") > > I'll end up stubbing it out with > > @thing = mock_model(Thing) > Thing.stub!(:find).with(:first, :order => "created_at > DESC").and_return(@thing) > > which obviously breaks as soon as someone refactors. > > I don't know ... maybe I'm just not a natural tester :( > > Is everyone else using factories and fixtures these days or am I not > alone? (I moved your post inline to make it easier to follow the conversation.) To be clear, I tend to use stubs and message expectations in controller specs, but that is different from model specs that deal with filters. I also try to keep the model APIs high level, so rather than Thing.stub(:find).with(;first, :order ....), I'd say Thing.stub(:most_recent) and add that method to Thing. See the difference? There is an old saying that you should "mock your own APIs, not everyone else's." This approach does not bind the examples to ActiveRecord or any other ORM, and if/when you want to switch, you just change the implementation within the methods you've added to the model. For model specs, I prefer to use factories over fixtures, and specify exactly what I need for example, interacting with the real database under the hood, but keeping the examples at a high level. In many cases, you can get away with not saving records (Factory.build(:widget) using FactoryGirl, for example), which I don't believe is an option you get with Fixtures. HTH, David > >> >> HTH, >> David >> >>> Pastie is here for pretty formatting:http://pastie.org/1242892 >> >>> Thanks. >> >>> P.S. This is old code I've inherited so I'm just trying to retrofit >>> RSpec 1.3x to it before I start refactoring and bringing up to date >>> with rails 3/rspec 2, so basically what I mean is what's the answer if >>> the model simply is how it is and can't be changed? From jarmo.p at gmail.com Sun Oct 24 15:20:09 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Sun, 24 Oct 2010 12:20:09 -0700 (PDT) Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: References: Message-ID: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> No ideas, what might cause that problem? Could it be a Windows-only- issue? Jarmo On Oct 22, 3:46?pm, Jarmo Pertman wrote: > Hello! > > I'm trying to run autotest under Windows when using Rails 3.0.1 and > RSpec 2.0.1. It's not working so far. This is what happens: > C:\Users\jarmo\Desktop\minu\projects\Ruby\sample_app>autotest > loading autotest/rails_rspec2 > style: RailsRspec2 > bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby -S C:/bin/pik/Ruby-187- > p302/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/bin/rspec --autotest 'C:/ > Users/jarmo > /Desktop/minu/projects/Ruby/sample_app/spec/controllers/ > pages_controller_spec.rb' > bundler: command not found: C:\bin\pik\Ruby-187-p302\bin\ruby > Install missing gem binaries with `bundle install` > > ... and then i have to interrupt it manually. > > I have installed gems autotest and autotest-rails-pure. Anything else > i have to do to get it running? > > Jarmo > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From haim.ashkenazi at gmail.com Sun Oct 24 11:21:30 2010 From: haim.ashkenazi at gmail.com (Haim Ashkenazi) Date: Sun, 24 Oct 2010 17:21:30 +0200 Subject: [rspec-users] Why does this stub doesn't work? Message-ID: <1BE078E8-D72A-472A-886D-0AE16A22E7B1@gmail.com> Hi I wonder why this stub doesn't work: # ruby 1.8.7, rspec 2.0.1 require 'rubygems' require 'rspec' Rspec.configure do |c| c.mock_with :rspec end class SayHello def say_hello "hello" end end describe "test string" do it "should interpret stub correctly" do SayHello.stub!(:say_hello).and_return('NO') sh = SayHello.new() sh.say_hello.should eql('NO') end end The result is: tryouts ? rspec -f n test_spec.rb test string should interpret stub correctly (FAILED - 1) Failures: 1) test string should interpret stub correctly Failure/Error: sh.say_hello.should eql('NO') expected "NO" got "hello" (compared using eql?) # ./test_spec.rb:18 Finished in 0.0016 seconds 1 example, 1 failure Any ideas? Bye Haim Ashkenazi -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part URL: From zach.dennis at gmail.com Sun Oct 24 17:04:37 2010 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 24 Oct 2010 17:04:37 -0400 Subject: [rspec-users] Why does this stub doesn't work? In-Reply-To: <1BE078E8-D72A-472A-886D-0AE16A22E7B1@gmail.com> References: <1BE078E8-D72A-472A-886D-0AE16A22E7B1@gmail.com> Message-ID: On Sun, Oct 24, 2010 at 11:21 AM, Haim Ashkenazi wrote: > Hi > > I wonder why this stub doesn't work: > > # ruby 1.8.7, rspec 2.0.1 > require 'rubygems' > require 'rspec' > > Rspec.configure do |c| > c.mock_with :rspec > end > > class SayHello > def say_hello > "hello" > end > end > > describe "test string" do > it "should interpret stub correctly" do > SayHello.stub!(:say_hello).and_return('NO') > sh = SayHello.new() > sh.say_hello.should eql('NO') > end > end > > In your example you are stubbing a class method. In your implementation you have defined an instance method. To have this work for your given implementation you need to know about the instance you are working with, ie: it "should interpret stub correctly" do sh = SayHello.new() sh.stub!(:say_hello).and_return 'NO' sh.say_hello.should eql('NO') end Hope this helps, Zach > > The result is: > > tryouts ? rspec -f n test_spec.rb > > test string > should interpret stub correctly (FAILED - 1) > > Failures: > 1) test string should interpret stub correctly > Failure/Error: sh.say_hello.should eql('NO') > > expected "NO" > got "hello" > > (compared using eql?) > # ./test_spec.rb:18 > > Finished in 0.0016 seconds > 1 example, 1 failure > > Any ideas? > > Bye > > Haim Ashkenazi > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) -------------- next part -------------- An HTML attachment was scrubbed... URL: From haim.ashkenazi at gmail.com Mon Oct 25 01:20:10 2010 From: haim.ashkenazi at gmail.com (Haim Ashkenazi) Date: Mon, 25 Oct 2010 07:20:10 +0200 Subject: [rspec-users] Why does this stub doesn't work? In-Reply-To: References: <1BE078E8-D72A-472A-886D-0AE16A22E7B1@gmail.com> Message-ID: <92B83E32-A659-4381-A345-DEFC63CF90D7@gmail.com> Hi Zach, On Oct 24, 2010, at 11:04 PM, Zach Dennis wrote: > > > On Sun, Oct 24, 2010 at 11:21 AM, Haim Ashkenazi wrote: > Hi > > I wonder why this stub doesn't work: > > # ruby 1.8.7, rspec 2.0.1 > require 'rubygems' > require 'rspec' > > Rspec.configure do |c| > > c.mock_with :rspec > end > > class SayHello > def say_hello > "hello" > end > end > > describe "test string" do > it "should interpret stub correctly" do > SayHello.stub!(:say_hello).and_return('NO') > > sh = SayHello.new() > sh.say_hello.should eql('NO') > end > end > In your example you are stubbing a class method. In your implementation you have defined an instance method. To have this work for your given implementation you need to know about the instance you are working with, ie: > > it "should interpret stub correctly" do > sh = SayHello.new() > sh.stub!(:say_hello).and_return 'NO' > sh.say_hello.should eql('NO') > end > > Hope this helps, Thanks for your help. I've found in the archives that you have to use mocha to do these kind of things. I tried a different approach (to mock the initializer) but although this works on a simple setup, it didn't work for me on my real classes. I'm probably doing something wrong so I'll upload it to github and ask this list again for help. Thanks. Bye > > Zach > > > > The result is: > tryouts ? rspec -f n test_spec.rb > > test string > should interpret stub correctly (FAILED - 1) > > Failures: > 1) test string should interpret stub correctly > Failure/Error: sh.say_hello.should eql('NO') > > expected "NO" > got "hello" > > (compared using eql?) > # ./test_spec.rb:18 > > Finished in 0.0016 seconds > 1 example, 1 failure > Any ideas? > Bye > Haim Ashkenazi > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Zach Dennis > http://www.continuousthinking.com (personal) > http://www.mutuallyhuman.com (hire me) > http://ideafoundry.info/behavior-driven-development (first rate BDD training) > @zachdennis (twitter) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part URL: From haim.ashkenazi at gmail.com Mon Oct 25 03:09:53 2010 From: haim.ashkenazi at gmail.com (Haim Ashkenazi) Date: Mon, 25 Oct 2010 09:09:53 +0200 Subject: [rspec-users] Need help to figure out why this expectation isn't met. Message-ID: <394534B8-76D1-437C-ADB8-6A80A6AE1E06@gmail.com> Hi This is my first ruby script, so sorry if it's trivial :) I have a should_receive expectation on :new which should work (and works on a simple test I wrote) but it doesn't work in my case and I can't figure out why. The source is on github (commit: 5197b763f391d6d358ca7bc5838375c9247271d8). The spec that doesn't work is in spec/runsshlib/cli_spec.rb line 127 (currently commented out). Can someone pls help me figure out why the expectation doesn't work? Thanks in advance Haim -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part URL: From dchelimsky at gmail.com Mon Oct 25 05:23:25 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 25 Oct 2010 07:23:25 -0200 Subject: [rspec-users] Why does this stub doesn't work? In-Reply-To: <92B83E32-A659-4381-A345-DEFC63CF90D7@gmail.com> References: <1BE078E8-D72A-472A-886D-0AE16A22E7B1@gmail.com> <92B83E32-A659-4381-A345-DEFC63CF90D7@gmail.com> Message-ID: <77231634-50F0-4411-BC2E-B7AA39A36B72@gmail.com> On Oct 25, 2010, at 3:20 AM, Haim Ashkenazi wrote: > Hi Zach, > > On Oct 24, 2010, at 11:04 PM, Zach Dennis wrote: > >> >> >> On Sun, Oct 24, 2010 at 11:21 AM, Haim Ashkenazi wrote: >> Hi >> >> I wonder why this stub doesn't work: >> >> # ruby 1.8.7, rspec 2.0.1 >> require 'rubygems' >> require 'rspec' >> >> Rspec.configure do |c| >> >> c.mock_with :rspec >> end >> >> class SayHello >> def say_hello >> "hello" >> end >> end >> >> describe "test string" do >> it "should interpret stub correctly" do >> SayHello.stub!(:say_hello).and_return('NO') >> >> sh = SayHello.new() >> sh.say_hello.should eql('NO') >> end >> end >> In your example you are stubbing a class method. In your implementation you have defined an instance method. To have this work for your given implementation you need to know about the instance you are working with, ie: >> >> it "should interpret stub correctly" do >> sh = SayHello.new() >> sh.stub!(:say_hello).and_return 'NO' >> sh.say_hello.should eql('NO') >> end >> >> Hope this helps, > > Thanks for your help. I've found in the archives that you have to use mocha to do these kind of things. This is incorrect. You are free to use mocha, but rspec-mocks, RR, and flexmock are all perfectly capable of stubbing class methods, so you don't _have_ to use mocha. > I tried a different approach (to mock the initializer) but although this works on a simple setup, it didn't work for me on my real classes. What Zach suggested is the correct approach. What problem are you seeing when you try it? > I'm probably doing something wrong so I'll upload it to github and ask this list again for help. > > Thanks. > > Bye > >> >> Zach >> >> >> >> The result is: >> tryouts ? rspec -f n test_spec.rb >> >> test string >> should interpret stub correctly (FAILED - 1) >> >> Failures: >> 1) test string should interpret stub correctly >> Failure/Error: sh.say_hello.should eql('NO') >> >> expected "NO" >> got "hello" >> >> (compared using eql?) >> # ./test_spec.rb:18 >> >> Finished in 0.0016 seconds >> 1 example, 1 failure >> Any ideas? >> Bye >> Haim Ashkenazi >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> -- >> Zach Dennis >> http://www.continuousthinking.com (personal) >> http://www.mutuallyhuman.com (hire me) >> http://ideafoundry.info/behavior-driven-development (first rate BDD training) >> @zachdennis (twitter) >> _______________________________________________ >> 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 haim.ashkenazi at gmail.com Mon Oct 25 06:43:07 2010 From: haim.ashkenazi at gmail.com (Haim Ashkenazi) Date: Mon, 25 Oct 2010 12:43:07 +0200 Subject: [rspec-users] Why does this stub doesn't work? In-Reply-To: <77231634-50F0-4411-BC2E-B7AA39A36B72@gmail.com> References: <1BE078E8-D72A-472A-886D-0AE16A22E7B1@gmail.com> <92B83E32-A659-4381-A345-DEFC63CF90D7@gmail.com> <77231634-50F0-4411-BC2E-B7AA39A36B72@gmail.com> Message-ID: Hi David, On Oct 25, 2010, at 11:23 AM, David Chelimsky wrote: > On Oct 25, 2010, at 3:20 AM, Haim Ashkenazi wrote: > >> Hi Zach, >> >> On Oct 24, 2010, at 11:04 PM, Zach Dennis wrote: >> >>> >>> >>> On Sun, Oct 24, 2010 at 11:21 AM, Haim Ashkenazi wrote: >>> Hi >>> >>> I wonder why this stub doesn't work: >>> >>> # ruby 1.8.7, rspec 2.0.1 >>> require 'rubygems' >>> require 'rspec' >>> >>> Rspec.configure do |c| >>> >>> c.mock_with :rspec >>> end >>> >>> class SayHello >>> def say_hello >>> "hello" >>> end >>> end >>> >>> describe "test string" do >>> it "should interpret stub correctly" do >>> SayHello.stub!(:say_hello).and_return('NO') >>> >>> sh = SayHello.new() >>> sh.say_hello.should eql('NO') >>> end >>> end >>> In your example you are stubbing a class method. In your implementation you have defined an instance method. To have this work for your given implementation you need to know about the instance you are working with, ie: >>> >>> it "should interpret stub correctly" do >>> sh = SayHello.new() >>> sh.stub!(:say_hello).and_return 'NO' >>> sh.say_hello.should eql('NO') >>> end >>> >>> Hope this helps, >> >> Thanks for your help. I've found in the archives that you have to use mocha to do these kind of things. > > This is incorrect. You are free to use mocha, but rspec-mocks, RR, and flexmock are all perfectly capable of stubbing class methods, so you don't _have_ to use mocha. Sorry, I didn't mean it this way. I actually tried it with RR and mocha and for some reason it didn't work for me (see next comment). > >> I tried a different approach (to mock the initializer) but although this works on a simple setup, it didn't work for me on my real classes. > > What Zach suggested is the correct approach. What problem are you seeing when you try it? The problem I'm trying to solve is a little more complicated then the example. I've sent a new email with a better description of the problem here: http://rubyforge.org/pipermail/rspec-users/2010-October/018571.html Somehow the links are not displayed (I've sent a follow-up message but it's not in the archive yet), so here they are: The repository is here: http://github.com/babysnakes/runssh The spec with the problem is http://github.com/babysnakes/runssh/blob/5197b763f391d6d358ca7bc5838375c9247271d8/spec/runsshlib/cli_spec.rb (line 127). The problem is that I have a SshBackend class which initializes with arguments. It also has a shell method which invokes exec. The SshBackend is invoked from the CLI class. I was trying to make sure that :new was called with the correct arguments and that :shellI is executed. One way would be to mock the :shell method (this email was about that) so that :exec would not be called and the other was to mock the :new method and return a mocked object (my second email). Somehow, non of these works for me. Thanks in advance Haim -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part URL: From lists at ruby-forum.com Mon Oct 25 18:49:07 2010 From: lists at ruby-forum.com (Fredrik Westermark) Date: Tue, 26 Oct 2010 00:49:07 +0200 Subject: [rspec-users] Fail to load spec/rake/spectask Message-ID: <240e56de44552b24db7df66e4af6256c@ruby-forum.com> Hi! I'm a newbie at Ruby. I'm trying to run rspec tests using rake. In my rake file I include spec/rake/spectask. It fails to load giving me the following message: rake aborted! no such file to load -- spec/rake/spectask C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile' I'm using version 1.8.7 of Ruby. I have installed rake and rspec using: gem install rake gem install rspec Here is the list of installed gems: builder (2.1.2) childprocess (0.1.3) ci_reporter (1.6.3) diff-lcs (1.1.2) ffi (0.6.3 x86-mingw32) json_pure (1.4.6) rake (0.8.7) rspec (2.0.1) rspec-core (2.0.1) rspec-expectations (2.0.1) rspec-mocks (2.0.1) rspec-rails (2.0.1) rubyzip (0.9.4) selenium-webdriver (0.0.29) What am I doing wrong? Why doesn't spec/rake/spectask load? Best regards /Fredrik -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Oct 25 20:48:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 25 Oct 2010 22:48:43 -0200 Subject: [rspec-users] Fail to load spec/rake/spectask In-Reply-To: <240e56de44552b24db7df66e4af6256c@ruby-forum.com> References: <240e56de44552b24db7df66e4af6256c@ruby-forum.com> Message-ID: On Oct 25, 2010, at 8:49 PM, Fredrik Westermark wrote: > Hi! > > I'm a newbie at Ruby. I'm trying to run rspec tests using rake. In my > rake file I include spec/rake/spectask. > > It fails to load giving me the following message: > rake aborted! > no such file to load -- spec/rake/spectask > C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in > `raw_load_rakefile' > > I'm using version 1.8.7 of Ruby. > I have installed rake and rspec using: > gem install rake > gem install rspec > > Here is the list of installed gems: > builder (2.1.2) > childprocess (0.1.3) > ci_reporter (1.6.3) > diff-lcs (1.1.2) > ffi (0.6.3 x86-mingw32) > json_pure (1.4.6) > rake (0.8.7) > rspec (2.0.1) > rspec-core (2.0.1) > rspec-expectations (2.0.1) > rspec-mocks (2.0.1) > rspec-rails (2.0.1) > rubyzip (0.9.4) > selenium-webdriver (0.0.29) > > What am I doing wrong? Why doesn't spec/rake/spectask load? Because it doesn't exist in rspec-2! See http://github.com/rspec/rspec-core/blob/master/Upgrade.markdown for more info. I've re-added it for the next rspec-2 release (2.0.2) with a deprecation notice, so other folks trying this out won't be surprised after that. Use rspec/core/rake_task instead (and RSpec::Core::RakeTask in the Rakefile). HTH, David > > Best regards > /Fredrik > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From haim at comns.co.il Mon Oct 25 04:54:54 2010 From: haim at comns.co.il (Haim Ashkenazi) Date: Mon, 25 Oct 2010 10:54:54 +0200 Subject: [rspec-users] Need help to figure out why this expectation isn't met. In-Reply-To: <394534B8-76D1-437C-ADB8-6A80A6AE1E06@gmail.com> References: <394534B8-76D1-437C-ADB8-6A80A6AE1E06@gmail.com> Message-ID: <64293697-91CF-4584-BCEB-77363E521104@comns.co.il> Hi I'm not sure if the URLs in the original post can be viewed :( so here they are: The repository is here: http://github.com/babysnakes/runssh The spec with the problem is http://github.com/babysnakes/runssh/blob/5197b763f391d6d358ca7bc5838375c9247271d8/spec/runsshlib/cli_spec.rb (line 127). Thanks Haim On Oct 25, 2010, at 9:09 AM, Haim Ashkenazi wrote: > Hi > > This is my first ruby script, so sorry if it's trivial :) > > I have a should_receive expectation on :new which should work (and works on a simple test I wrote) but it doesn't work in my case and I can't figure out why. The source is on github (commit: 5197b763f391d6d358ca7bc5838375c9247271d8). The spec that doesn't work is in spec/runsshlib/cli_spec.rb line 127 (currently commented out). > > Can someone pls help me figure out why the expectation doesn't work? > > Thanks in advance > > Haim > Haim Ashkenazi Com-n-Sense Mobile: +972-52-6188488 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part URL: From lipu.paul at gmail.com Mon Oct 25 17:47:49 2010 From: lipu.paul at gmail.com (Lipu) Date: Mon, 25 Oct 2010 14:47:49 -0700 (PDT) Subject: [rspec-users] rspec error's when checking LayoutLinks from the railstutorials In-Reply-To: References: Message-ID: <048d0a20-91a1-4f25-8137-71dbd36395aa@m7g2000yqm.googlegroups.com> Hi Daniel, Did you figure out a way to solve this problem? I run into the same problem tool. Regards Lipu On Oct 21, 1:27?am, Daniel Palacio wrote: > I am following the rails tutorial:http://railstutorial.org/chapters/filling-in-the-layout#top > > Basically the test is something like: > > spec/requests/layout_links_spec.rb > require 'spec_helper' > > describe "LayoutLinks" do > > ? it "should have a Home page at '/'" do > ? ? get '/' > ? ? response.should have_selector('title', :content => "Home") > ? end > > Routes: > ? ?root :to => 'pages#home' > > 1. I already googled and foundhttp://stackoverflow.com/questions/3517724/rspec-is-giving-an-error-w... > > 2. I already tried changing the rspec version to 2.0.0.beta.18, but I > still get the same error. > > Here is the output: > > dpalacio:sample_app dpalacio$ rspec -v > 2.0.1 > dpalacio:sample_app dpalacio$ rspec spec/requests/ > FFFFF > > Finished in 0.55501 seconds > 5 examples, 5 failures > > 1) LayoutLinks should have a Home page at '/' > ? ? Failure/Error: Unable to find matching line from backtrace > ? ? stack level too deep > ? ? # /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185 > ..... > > Is there any other thing that might be causing the problem ? > Thanks > -dan > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From chrismear at gmail.com Tue Oct 26 05:15:38 2010 From: chrismear at gmail.com (Chris Mear) Date: Tue, 26 Oct 2010 10:15:38 +0100 Subject: [rspec-users] Need help to figure out why this expectation isn't met. In-Reply-To: <64293697-91CF-4584-BCEB-77363E521104@comns.co.il> References: <394534B8-76D1-437C-ADB8-6A80A6AE1E06@gmail.com> <64293697-91CF-4584-BCEB-77363E521104@comns.co.il> Message-ID: <278E5933-3ADE-40D2-AEB1-9E4EE0D44F87@gmail.com> On 25 Oct 2010, at 09:54, Haim Ashkenazi wrote: > On Oct 25, 2010, at 9:09 AM, Haim Ashkenazi wrote: > >> Hi >> >> This is my first ruby script, so sorry if it's trivial :) >> >> I have a should_receive expectation on :new which should work (and works on a simple test I wrote) but it doesn't work in my case and I can't figure out why. The source is on github (commit: 5197b763f391d6d358ca7bc5838375c9247271d8). The spec that doesn't work is in spec/runsshlib/cli_spec.rb line 127 (currently commented out). >> >> Can someone pls help me figure out why the expectation doesn't work? >> >> Thanks in advance >> >> Haim > > Hi > > I'm not sure if the URLs in the original post can be viewed :( so here they are: > > ? The repository is here: http://github.com/babysnakes/runssh > ? The spec with the problem is http://github.com/babysnakes/runssh/blob/5197b763f391d6d358ca7bc5838375c9247271d8/spec/runsshlib/cli_spec.rb (line 127). > > Thanks > > Haim > (Moved your reply inline.) The rescuing that you do in line 56 of CLI#run was obscuring the real error here: 1) The CLI interface when run with subcommand shell should correctly initialize SshBackend Failure/Error: cli.run host definition (cust2 => dc => somehost) doesn't exist! # ./lib/runsshlib/config_file.rb:101:in `get_host' # ./lib/runsshlib/cli.rb:228:in `run_shell' # ./lib/runsshlib/cli.rb:54:in `call' # ./lib/runsshlib/cli.rb:54:in `run' # ./spec/runsshlib/cli_spec.rb:133 I found this by commenting out the lines where you rescue the exception and raise a Trollop error instead. So the example wasn't even reaching the line in CLI#run_shell where you create the SshBackend, because it was failing on the get_host call (since the example uses dummy data). I got the example to pass by also mocking/stubbing the ConfigFile stored in @c, and stubbing its get_host method: http://github.com/chrismear/runssh/commit/87ca98a1429b975e00b87ffadbb0b4c81d849af8 If you want to mock everything outside of the CLI object in this spec, that's one (not hugely elegant) way to do it. When you have problems like this, it's helpful to dig down and find the exact place the error is occurring. Chris From haim.ashkenazi at gmail.com Tue Oct 26 09:34:51 2010 From: haim.ashkenazi at gmail.com (Haim Ashkenazi) Date: Tue, 26 Oct 2010 15:34:51 +0200 Subject: [rspec-users] Need help to figure out why this expectation isn't met. In-Reply-To: <278E5933-3ADE-40D2-AEB1-9E4EE0D44F87@gmail.com> References: <394534B8-76D1-437C-ADB8-6A80A6AE1E06@gmail.com> <64293697-91CF-4584-BCEB-77363E521104@comns.co.il> <278E5933-3ADE-40D2-AEB1-9E4EE0D44F87@gmail.com> Message-ID: <359244A9-93D8-4D77-A83E-927E8F3A080C@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Chris, On Oct 26, 2010, at 11:15 AM, Chris Mear wrote: > > On 25 Oct 2010, at 09:54, Haim Ashkenazi wrote: > >> On Oct 25, 2010, at 9:09 AM, Haim Ashkenazi wrote: >> >>> Hi >>> >>> This is my first ruby script, so sorry if it's trivial :) >>> >>> I have a should_receive expectation on :new which should work (and works on a simple test I wrote) but it doesn't work in my case and I can't figure out why. The source is on github (commit: 5197b763f391d6d358ca7bc5838375c9247271d8). The spec that doesn't work is in spec/runsshlib/cli_spec.rb line 127 (currently commented out). >>> >>> Can someone pls help me figure out why the expectation doesn't work? >>> >>> Thanks in advance >>> >>> Haim >> >> Hi >> >> I'm not sure if the URLs in the original post can be viewed :( so here they are: >> >> ? The repository is here: http://github.com/babysnakes/runssh >> ? The spec with the problem is http://github.com/babysnakes/runssh/blob/5197b763f391d6d358ca7bc5838375c9247271d8/spec/runsshlib/cli_spec.rb (line 127). >> >> Thanks >> >> Haim >> > > (Moved your reply inline.) > > The rescuing that you do in line 56 of CLI#run was obscuring the real error here: > > 1) The CLI interface when run with subcommand shell should correctly initialize SshBackend > Failure/Error: cli.run > host definition (cust2 => dc => somehost) doesn't exist! > # ./lib/runsshlib/config_file.rb:101:in `get_host' > # ./lib/runsshlib/cli.rb:228:in `run_shell' > # ./lib/runsshlib/cli.rb:54:in `call' > # ./lib/runsshlib/cli.rb:54:in `run' > # ./spec/runsshlib/cli_spec.rb:133 > > I found this by commenting out the lines where you rescue the exception and raise a Trollop error instead. > > So the example wasn't even reaching the line in CLI#run_shell where you create the SshBackend, because it was failing on the get_host call (since the example uses dummy data). > > I got the example to pass by also mocking/stubbing the ConfigFile stored in @c, and stubbing its get_host method: > > http://github.com/chrismear/runssh/commit/87ca98a1429b975e00b87ffadbb0b4c81d849af8 > > If you want to mock everything outside of the CLI object in this spec, that's one (not hugely elegant) way to do it. > > When you have problems like this, it's helpful to dig down and find the exact place the error is occurring. > > Chris Wow, that was a stupid mistake. Thanks for the time, the good eye and the advice :) I actually don't need to stub everything, I just had to fix the path to match the fixtures. Thanks Haim -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin) iEYEARECAAYFAkzG2PsACgkQhwMtGgRKzT1NsACeJ5MTWvcBCxqbPaHqGfy/QLuJ +G4AoJD2hLjZ/eguqJFCOTs96dIQEa9W =2UGK -----END PGP SIGNATURE----- From lists at ruby-forum.com Tue Oct 26 17:53:05 2010 From: lists at ruby-forum.com (Fredrik Westermark) Date: Tue, 26 Oct 2010 23:53:05 +0200 Subject: [rspec-users] Fail to load spec/rake/spectask In-Reply-To: <240e56de44552b24db7df66e4af6256c@ruby-forum.com> References: <240e56de44552b24db7df66e4af6256c@ruby-forum.com> Message-ID: <20eaaee0bb6674986d867acaa0823c51@ruby-forum.com> Many thanks David! My rspec tests can now be executed and presented from Hudson using rake and the ci_reporter. Best regards /Fredrik -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Oct 27 10:40:18 2010 From: lists at ruby-forum.com (Eugen Ciur) Date: Wed, 27 Oct 2010 16:40:18 +0200 Subject: [rspec-users] how to mock url_for ? Message-ID: <9da45354a1c325d54e1d0c6609290f6d@ruby-forum.com> Hi, I am testing a model A, which calls inside url_for method; rspec complains that url_for is undefined (which I suppose is because url_for is called outside view's context) How can I mock url_for rails method? Please help, Thank you. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Oct 27 16:30:31 2010 From: lists at ruby-forum.com (Mack T.) Date: Wed, 27 Oct 2010 22:30:31 +0200 Subject: [rspec-users] Nested attributes in fixtures In-Reply-To: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> References: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> Message-ID: <3b223bdec29be893d7d0a1481d0a905a@ruby-forum.com> I appreciate the quick response! Sorry for the delay. The relevant code is attached. Our model's name is Scale, which has_many ScaleElements. We're loading fixtures in specs with config.fixture_path = "#{::Rails.root}/spec/fixtures" Nested attributes don't work (although they do outside of Rspec in Rails), and we're currently solving the problem by creating a scale_elements.yml fixture and not nesting attributes. rspec version: 2.0.1 rails version: 3.0.0 Attachments: http://www.ruby-forum.com/attachment/5251/code.txt -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Oct 27 19:07:42 2010 From: lists at ruby-forum.com (Vadim Comanescu) Date: Thu, 28 Oct 2010 01:07:42 +0200 Subject: [rspec-users] Autotest with rspec2 notifications on windows Message-ID: <34ecf07c01614c6f7fa6e2db32c25cdd@ruby-forum.com> Hello. I've been trying for the last 2 days to make autotest with rspec2 send notifications on windows7 but without any success. First i used only the autotest gem with autotest-growl and the latest version of growl for windows including the growlnotifier. Made all the proper adjustments : created an autotest directory to import the rspec2 into autotest (got this from David Chelimsky's blog). Created the .autotest file and appended the require for autotest/growl. The autotest was working just it was not registering to growl in any way. Then i tried using a different approach with the gem ruby-snarl and instead of autotest installed the latest version of the ZenTest gem. Installed the latest version of snarl, set my HOME environment variable, installed the GNU Diff utils package just for safety , then the latest version of Snarl. The notifications are still not sent. I would appreciate any more suggestions. Thank you in advance. Vadim Comanescu -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Oct 28 04:03:44 2010 From: lists at ruby-forum.com (Ar Vicco) Date: Thu, 28 Oct 2010 10:03:44 +0200 Subject: [rspec-users] Autotest+RSpec2+Win32console = no color Message-ID: <24ab1b4904d06444f0a1818259efc8a5@ruby-forum.com> I have the same problem with the combination above with Ruby 1.9.2 on Windows XP, as described here: http://www.ruby-forum.com/topic/205569 Calling Rspec directly produces colored output, but autotest spits out ANSI sequences. The issue was supposed to be closed with win32console 1.3.0, but obviously it didn't for the above-mentioned combination. -- Posted via http://www.ruby-forum.com/. From bluesman.alex at gmail.com Thu Oct 28 05:40:02 2010 From: bluesman.alex at gmail.com (Alexey Ilyichev) Date: Thu, 28 Oct 2010 13:40:02 +0400 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: I have made 2 examples for this and I can't figure out how to make both pass. Take a look please: require 'spec_helper' describe "Mock" do class A def self.method_missing(name, *args, &block) '*a_method_missing*' end def self.present_method(arg) '*present_method*' end end class B < A def self.method_missing(name, *args, &block) '*b_method_missing*' end end it 'should call derived class method_missing when args differ from what is stubbed' do B.stub!(:missing_method).with(1).and_return '*stub*' B.missing_method(2).should == '*b_method_missing*' end it 'should call present_method when it is defined in parent class and args differ from what is stubbed' do B.stub!(:present_method).with(1).and_return '*stub*' B.present_method(2).should == '*present_method*' end end ---------- Forwarded message ---------- From: Alexey Ilyichev Date: Thu, Oct 28, 2010 at 12:44 PM Subject: Issue with AR::Base descendants with certain argument To: rspec-users at rubyforge.org Hi! I am trying to upgrade rspec-rails to 1.3.3, and one of my specs fails. In before :each I stub finder method like this: Payment.stub!(:find_by_id).with(@payment.id.to_s).and_return @payment Payment class is derived from AR::Base And then in one of the examples I call Payment.find_by_id((@payment.id + 1).to_s), and I am expecting it to return null, as it used to with 1.2.9 version, however it leads to an exception in active_record/base.rb. Analyzing the stack trace I figured that in line 115 of mock/proxy.rb method find_by_id is called for ActiveRecord::Base, which is not correct. I'm not familiar with rspec internals, so I don't have an idea on where in code the actual problem is. So any help would be greatly appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Oct 28 06:35:42 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 28 Oct 2010 08:35:42 -0200 Subject: [rspec-users] Nested attributes in fixtures In-Reply-To: <3b223bdec29be893d7d0a1481d0a905a@ruby-forum.com> References: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> <3b223bdec29be893d7d0a1481d0a905a@ruby-forum.com> Message-ID: On Wed, Oct 27, 2010 at 6:30 PM, Mack T. wrote: > I appreciate the quick response! ?Sorry for the delay. ?The relevant > code is attached. ?Our model's name is Scale, which has_many > ScaleElements. > > We're loading fixtures in specs with config.fixture_path = > "#{::Rails.root}/spec/fixtures" > > Nested attributes don't work (although they do outside of Rspec in > Rails), and we're currently solving the problem by creating a > scale_elements.yml fixture and not nesting attributes. > > rspec version: 2.0.1 > rails version: 3.0.0 > > Attachments: > http://www.ruby-forum.com/attachment/5251/code.txt I haven't used fixtures myself in a couple of years, and never used nested attributes. Does anyone else on the list have any advice to offer about this? From joseph.delcioppio at gmail.com Wed Oct 27 12:49:50 2010 From: joseph.delcioppio at gmail.com (Joseph DelCioppio) Date: Wed, 27 Oct 2010 09:49:50 -0700 (PDT) Subject: [rspec-users] Understanding routing specs that use constraints Message-ID: <4e881a5e-ba95-4531-8bb0-eb728a3f63b7@l17g2000yqe.googlegroups.com> Hello all, I'm trying to perform a pretty simple routing constraint Here are my routes, my constraint, and my spec. http://gist.github.com/649430 As you can see, I've attempted to stub my RootConstraints.matches? method to just return true or false. However, this doesn't seem to work correctly. Even when I stub RootConstraints.matches? to return false, it still always routes root to :controller => "lists", :action => "show", :id => "name". Here is the error that I receive: http://gist.github.com/649432 Can anybody enlighten me as to why this happens? Thanks, Joe From bluesman.alex at gmail.com Thu Oct 28 04:44:18 2010 From: bluesman.alex at gmail.com (Alexey Ilyichev) Date: Thu, 28 Oct 2010 12:44:18 +0400 Subject: [rspec-users] Issue with AR::Base descendants with certain argument Message-ID: Hi! I am trying to upgrade rspec-rails to 1.3.3, and one of my specs fails. In before :each I stub finder method like this: Payment.stub!(:find_by_id).with(@payment.id.to_s).and_return @payment Payment class is derived from AR::Base And then in one of the examples I call Payment.find_by_id((@payment.id + 1).to_s), and I am expecting it to return null, as it used to with 1.2.9 version, however it leads to an exception in active_record/base.rb. Analyzing the stack trace I figured that in line 115 of mock/proxy.rb method find_by_id is called for ActiveRecord::Base, which is not correct. I'm not familiar with rspec internals, so I don't have an idea on where in code the actual problem is. So any help would be greatly appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Oct 28 07:06:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 28 Oct 2010 09:06:43 -0200 Subject: [rspec-users] how to mock url_for ? In-Reply-To: <9da45354a1c325d54e1d0c6609290f6d@ruby-forum.com> References: <9da45354a1c325d54e1d0c6609290f6d@ruby-forum.com> Message-ID: On Oct 27, 2010, at 12:40 PM, Eugen Ciur wrote: > Hi, > > I am testing a model A, which calls inside url_for method; rspec > complains that url_for is undefined Sometimes error messages tell you exactly what you need to know. In this case, url_is not defined in ActiveRecord models. This is true whether you're in a spec or in the console: class Gadget < ActiveRecord::Base def gimme_your_url url_for(self) end end $ script/rails c Loading development environment (Rails 3.0.2.pre) ruby-1.8.7-p302 > Gadget.new.gimme_your_url NoMethodError: undefined method `url_for' for # > (which I suppose is because url_for > is called outside view's context) > > How can I mock url_for rails method? Stubbing this doesn't make sense if it's not normally available in the model. Why do you want to call url_for from a model instead of a view template or a helper? From lists at ruby-forum.com Thu Oct 28 13:25:20 2010 From: lists at ruby-forum.com (Mack T.) Date: Thu, 28 Oct 2010 19:25:20 +0200 Subject: [rspec-users] Nested attributes in fixtures In-Reply-To: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> References: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> Message-ID: Figured this out. Our fixtures outside Rspec are actually being used to create instances of ActiveRecord models. AR supports accepts_nested_attributes_for, but the Rspec fixtures bypass AR and simply attempt to set database values. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Oct 28 14:35:32 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 28 Oct 2010 16:35:32 -0200 Subject: [rspec-users] Nested attributes in fixtures In-Reply-To: References: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> Message-ID: <46FBC7E4-FFA8-4EF9-9540-D6D400EB5A1A@gmail.com> On Oct 28, 2010, at 3:25 PM, Mack T. wrote: > Figured this out. Our fixtures outside Rspec are actually being used to > create instances of ActiveRecord models. AR supports > accepts_nested_attributes_for, but the Rspec fixtures bypass AR and > simply attempt to set database values. There are no "RSpec fixtures," so I don't really understand what you mean here. The only thing RSpec does with regard to fixtures is expose a couple of configuration bits in the RSpec.configure block. The rest is all managed by the Rails' testing framework. What do you mean "our fixtures outside rspec"? From dchelimsky at gmail.com Thu Oct 28 17:58:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 28 Oct 2010 19:58:45 -0200 Subject: [rspec-users] Understanding routing specs that use constraints In-Reply-To: <4e881a5e-ba95-4531-8bb0-eb728a3f63b7@l17g2000yqe.googlegroups.com> References: <4e881a5e-ba95-4531-8bb0-eb728a3f63b7@l17g2000yqe.googlegroups.com> Message-ID: <32B728A2-49CB-459C-824E-D88A15180FB2@gmail.com> On Oct 27, 2010, at 2:49 PM, Joseph DelCioppio wrote: > Hello all, > > I'm trying to perform a pretty simple routing constraint > > Here are my routes, my constraint, and my spec. http://gist.github.com/649430 > > As you can see, I've attempted to stub my RootConstraints.matches? > method to just return true or false. However, this doesn't seem to > work correctly. Even when I stub RootConstraints.matches? to return > false, it still always routes root to :controller => "lists", :action > => "show", :id => "name". > > Here is the error that I receive: http://gist.github.com/649432 > > > Can anybody enlighten me as to why this happens? The issue is within assert_recognizes in Rails (to which route_to delegates). See http://github.com/rspec/rspec-rails/issues/closed#issue/239 and https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5805 for more info. HTH, David From matthewcalebsmith at gmail.com Fri Oct 29 11:57:29 2010 From: matthewcalebsmith at gmail.com (Matthew Smith) Date: Fri, 29 Oct 2010 08:57:29 -0700 Subject: [rspec-users] Rails Model Test In-Reply-To: References: Message-ID: Given this model: class Organization < ActiveRecord::Base has_many :users validates :name, :presence => true validates :subdomain, :presence => true validate :has_at_least_one_user private def has_at_least_one_user errors.add(:users, "Must have at least one user.") unless users.length > 0 end end And this set of examples: require 'spec_helper' describe Organization do before do @organization = Organization.new(name:"an org", subdomain:"anorg") end it 'is valid with valid attributes' do @organization.users << mock_model("User") @organization.should be_valid end it 'is not valid without an organization name' do @organization.name = nil @organization.should_not be_valid end it 'is not valid without a subdomain' do @organization.subdomain = nil @organization.should_not be_valid end it 'is not valid if subdomain is not unique' it 'is not valid without at least one user' do @organization.users = [] @organization.should_not be_valid end end I get this failure: Failures: 1) Organization is valid with valid attributes Failure/Error: @organization.users << mock_model("User") Mock "User_1001" received unexpected message :to_ary with (no args) # ./spec/models/organization_spec.rb:9:in `block (2 levels) in ' Question 1: Why can't I seem to add a mock User this way? Question 2: Are there any better ways to test/implement a model that requires at least one association? Thanks! Matt Smith From lists at ruby-forum.com Fri Oct 29 12:41:57 2010 From: lists at ruby-forum.com (Mack T.) Date: Fri, 29 Oct 2010 18:41:57 +0200 Subject: [rspec-users] Nested attributes in fixtures In-Reply-To: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> References: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> Message-ID: <3cf7d9b9a09c7a801dd0143a6a36cebc@ruby-forum.com> By "fixtures outside Rspec", I was referring to files in our db/fixtures directory, which I assumed were fixtures. On further investigation, I found these files are actually being used by some custom 'seeding' code a coworker of mine wrote. The seeding is reading the fixtures and creating AR objects, so they aren't actually fixtures. This is how accepts_nested_attributes is working - fixtures don't appear to support that out of the box. Also, when I said Rspec fixtures, I meant the files in spec/fixtures. In short, never mind - this really has nothing to do with Rspec :) I appreciate the quick responses. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Oct 29 13:46:52 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 29 Oct 2010 15:46:52 -0200 Subject: [rspec-users] Nested attributes in fixtures In-Reply-To: <3cf7d9b9a09c7a801dd0143a6a36cebc@ruby-forum.com> References: <0c1f5a86-a36a-4a7f-bbe9-63ac25b32ea6@u13g2000vbo.googlegroups.com> <3cf7d9b9a09c7a801dd0143a6a36cebc@ruby-forum.com> Message-ID: <0E8391FF-665F-4E59-90DD-02EB768BCD1E@gmail.com> On Oct 29, 2010, at 2:41 PM, Mack T. wrote: > By "fixtures outside Rspec", I was referring to files in our db/fixtures > directory, which I assumed were fixtures. On further investigation, I > found these files are actually being used by some custom 'seeding' code > a coworker of mine wrote. The seeding is reading the fixtures and > creating AR objects, so they aren't actually fixtures. This is how > accepts_nested_attributes is working - fixtures don't appear to support > that out of the box. > > Also, when I said Rspec fixtures, I meant the files in spec/fixtures. > > In short, never mind - this really has nothing to do with Rspec :) > I appreciate the quick responses. Glad you got it resolved :) Cheers, David From wagner.andrew at gmail.com Sat Oct 30 09:40:10 2010 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Sat, 30 Oct 2010 09:40:10 -0400 Subject: [rspec-users] What should I test/specify? Message-ID: Ok, so here's the scenario. I have a top-level module, with a method called load_file. It should take a file name, get the YAML module (Syck) to parse it, and then send the result to a class, which should convert that result into a series of objects. I'm not sure what specs, if any, I should write for load_file. I can get into the nitty gritty details of exactly what methods it should be calling, but that seems brittle. I can skip all that and just make assertions about the final series of objects, but I'd rather put those specs on the class that's actually doing the conversion. Suggestions? Here's the code that I (think I) want to drive out: module BTree def self.load_file file_name raw = YAML::load_file file_name tree = BehaviorTreeCreator.new(raw).create end end -------------- next part -------------- An HTML attachment was scrubbed... URL: From johnf at distb.net Sat Oct 30 12:47:43 2010 From: johnf at distb.net (John Feminella) Date: Sat, 30 Oct 2010 12:47:43 -0400 Subject: [rspec-users] What should I test/specify? In-Reply-To: References: Message-ID: If you're writing a unit test for a method, the general rule of thumb is to test what the method itself does. That sounds tautological, but it's meant to define the boundary of what you should and shouldn't care about. In this case, you only care about the fact that `YAML::load_file` is called, and that `BehaviorTreeCreator.new` is then called with the result of that, and that *that* result has `create` invoked on it. That's it: if those three things happen, then this method is working as you expect. Your unit tests for BehaviorTreeCreator.new and .create will probably be richer. ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/fjsquared SO: http://stackoverflow.com/users/75170/ From dchelimsky at gmail.com Sat Oct 30 12:46:48 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 30 Oct 2010 14:46:48 -0200 Subject: [rspec-users] What should I test/specify? In-Reply-To: References: Message-ID: On Oct 30, 2010, at 11:40 AM, Andrew Wagner wrote: > Ok, so here's the scenario. I have a top-level module, with a method called load_file. It should take a file name, get the YAML module (Syck) to parse it, and then send the result to a class, which should convert that result into a series of objects. > > I'm not sure what specs, if any, I should write for load_file. I can get into the nitty gritty details of exactly what methods it should be calling, but that seems brittle. I can skip all that and just make assertions about the final series of objects, but I'd rather put those specs on the class that's actually doing the conversion. > > Suggestions? Here's the code that I (think I) want to drive out: > > module BTree > def self.load_file file_name > raw = YAML::load_file file_name > tree = BehaviorTreeCreator.new(raw).create > end > end One approach would be: describe BTree do describe "::load_file" do let(:filename) { '/tmp/btree_example.yml' } let(:content) { "---\na: 1\n" } before { File.open(filename,'w') {|f| f.write content } } after { File.delete filename } it "reads and parses the content of the file" do BTree.load_file(filename).should eq(BehaviorTreeCreator.new(content).create end end end Assuming there are specs for BehaviorTreeCreator.new(content).create, then this tells the story pretty well without being terribly invasive. WDYT? David From wagner.andrew at gmail.com Sat Oct 30 13:12:52 2010 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Sat, 30 Oct 2010 13:12:52 -0400 Subject: [rspec-users] What should I test/specify? In-Reply-To: References: Message-ID: Yeah, that's about what I figured, thanks. This is what I came up with: require 'spec_helper.rb' require 'yaml' describe "BTree" do describe ".load_file" do context "when the file exists" do before(:all) { File.open("test_file.yaml", 'w') {|f| } } after(:all) { File.delete "test_file.yaml"} after(:each) { BTree.load_file "test_file.yaml" } it "parses the yaml in the file" do YAML.stub!(:load_file).and_return(:foo) YAML.should_receive(:load_file).with("test_file.yaml").and_return(:foo) end it "converts the raw data into a tree" do fake_creator = Object.new fake_creator.stub! :create YAML.stub!(:load_file).and_return(:data) BehaviorCreator.stub!(:new).and_return :tree BehaviorCreator.should_receive(:new).with(:data).and_return fake_creator fake_creator.should_receive :create end end context "when the file doesn't exist" do it "raises an error" do lambda { BTree.load_file "non_existent.yaml" }.should raise_error end end end end On Sat, Oct 30, 2010 at 12:47 PM, John Feminella wrote: > If you're writing a unit test for a method, the general rule of thumb > is to test what the method itself does. That sounds tautological, but > it's meant to define the boundary of what you should and shouldn't > care about. > > In this case, you only care about the fact that `YAML::load_file` is > called, and that `BehaviorTreeCreator.new` is then called with the > result of that, and that *that* result has `create` invoked on it. > That's it: if those three things happen, then this method is working > as you expect. > > Your unit tests for BehaviorTreeCreator.new and .create will probably be > richer. > > ~ jf > -- > John Feminella > Principal Consultant, BitsBuilder > LI: http://www.linkedin.com/in/fjsquared > SO: http://stackoverflow.com/users/75170/ > _______________________________________________ > 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 wagner.andrew at gmail.com Sat Oct 30 13:35:10 2010 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Sat, 30 Oct 2010 13:35:10 -0400 Subject: [rspec-users] What should I test/specify? In-Reply-To: References: Message-ID: On Sat, Oct 30, 2010 at 12:46 PM, David Chelimsky wrote: > On Oct 30, 2010, at 11:40 AM, Andrew Wagner wrote: > > > Ok, so here's the scenario. I have a top-level module, with a method > called load_file. It should take a file name, get the YAML module (Syck) to > parse it, and then send the result to a class, which should convert that > result into a series of objects. > > > > I'm not sure what specs, if any, I should write for load_file. I can get > into the nitty gritty details of exactly what methods it should be calling, > but that seems brittle. I can skip all that and just make assertions about > the final series of objects, but I'd rather put those specs on the class > that's actually doing the conversion. > > > > Suggestions? Here's the code that I (think I) want to drive out: > > > > module BTree > > def self.load_file file_name > > raw = YAML::load_file file_name > > tree = BehaviorTreeCreator.new(raw).create > > end > > end > > One approach would be: > > describe BTree do > describe "::load_file" do > let(:filename) { '/tmp/btree_example.yml' } > let(:content) { "---\na: 1\n" } > before { File.open(filename,'w') {|f| f.write content } } > after { File.delete filename } > > it "reads and parses the content of the file" do > BTree.load_file(filename).should > eq(BehaviorTreeCreator.new(content).create > end > end > end > > Assuming there are specs for BehaviorTreeCreator.new(content).create, then > this tells the story pretty well without being terribly invasive. > > WDYT? > > David > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I like this, though it's missing a YAML::load(content). I.e., BTree.load_file(filename).should eq(BehaviorTreeCreator.new(YAML::load content).create -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Oct 30 16:51:38 2010 From: lists at ruby-forum.com (Andrei Kulakov) Date: Sat, 30 Oct 2010 22:51:38 +0200 Subject: [rspec-users] rspec error's when checking LayoutLinks from the railstutorials In-Reply-To: References: Message-ID: <6caad5acc3926b3f4d7f193bb307028a@ruby-forum.com> This is webrat 0.7.2 problem https://webrat.lighthouseapp.com/projects/10503/tickets/398-failureerror-unable-to-find-matching-line-from-backtrace Everything works fine with webrat 0.7.1 -- Posted via http://www.ruby-forum.com/. From apremdas at gmail.com Sat Oct 30 21:54:48 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Sun, 31 Oct 2010 01:54:48 +0000 Subject: [rspec-users] What should I test/specify? In-Reply-To: References: Message-ID: On 30 October 2010 14:40, Andrew Wagner wrote: > Ok, so here's the scenario. I have a top-level module, with a method called > load_file. It should take a file name, get the YAML module (Syck) to parse > it, and then send the result to a class, which should convert that result > into a series of objects. > > I'm not sure what specs, if any, I should write for load_file. I can get > into the nitty gritty details of exactly what methods it should be calling, > but that seems brittle. I can skip all that and just make assertions about > the final series of objects, but I'd rather put those specs on the class > that's actually doing the conversion. > > Suggestions? Here's the code that I (think I) want to drive out: > > module BTree > def self.load_file file_name > raw = YAML::load_file file_name > tree = BehaviorTreeCreator.new(raw).create > end > end > > Its not obvious what specs to write for load_file because load_file is poorly named. It does far more than load a file. If you write your specs for load file and read them, they won't make sense e.g. load_file should use YAML (why should it use YAML, and what happens if the file isn't YAML load_file should create a behaviour tree (why should it create a TREE) Perhaps BTree only needs a yaml_to_tree, and you can pass the yaml into the method. If this was the case you might spec the following: what happens if you pass invalid YAML what happens if you pass valid YAML what happens if you pass nothing Generally if a method is hard to spec, then its smelly, there is something wrong with it, it needs work HTH Andrew > _______________________________________________ > 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 wagner.andrew at gmail.com Sat Oct 30 22:35:51 2010 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Sat, 30 Oct 2010 22:35:51 -0400 Subject: [rspec-users] What should I test/specify? In-Reply-To: References: Message-ID: On Sat, Oct 30, 2010 at 9:54 PM, Andrew Premdas wrote: > On 30 October 2010 14:40, Andrew Wagner wrote: > >> Ok, so here's the scenario. I have a top-level module, with a method >> called load_file. It should take a file name, get the YAML module (Syck) to >> parse it, and then send the result to a class, which should convert that >> result into a series of objects. >> >> I'm not sure what specs, if any, I should write for load_file. I can get >> into the nitty gritty details of exactly what methods it should be calling, >> but that seems brittle. I can skip all that and just make assertions about >> the final series of objects, but I'd rather put those specs on the class >> that's actually doing the conversion. >> >> Suggestions? Here's the code that I (think I) want to drive out: >> >> module BTree >> def self.load_file file_name >> raw = YAML::load_file file_name >> tree = BehaviorTreeCreator.new(raw).create >> end >> end >> >> > Its not obvious what specs to write for load_file because load_file is > poorly named. It does far more than load a file. If you write your specs > for load file and read them, they won't make sense e.g. > > load_file should use YAML (why should it use YAML, and what happens if the > file isn't YAML > load_file should create a behaviour tree (why should it create a TREE) > > Perhaps BTree only needs a yaml_to_tree, and you can pass the yaml into the > method. If this was the case you might spec the following: > what happens if you pass invalid YAML > what happens if you pass valid YAML > what happens if you pass nothing > > Generally if a method is hard to spec, then its smelly, there is something > wrong with it, it needs work > > HTH > > Andrew > > >> _______________________________________________ >> 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 > An interesting perspective. The purpose of the behavior tree module is to provide a simple, standard way to represent behaviors in a plain-text format. I'm borrowing YAML because it seems like a good, lightweight approach. I'm using load_file (and load) to mirror YAML::load_file (and YAML::load). I'll definitely take some of your ideas into consideration, thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Oct 31 08:14:06 2010 From: dchelimsky at gmail.com (dchelimsky at gmail.com) Date: Sun, 31 Oct 2010 05:14:06 -0700 (PDT) Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: On Oct 28, 7:40?am, Alexey Ilyichev wrote: > I have made 2 examples for this and I can't figure out how to make both > pass. Take a look please: > > require 'spec_helper' > > describe "Mock" do > ? class A > ? ? def self.method_missing(name, *args, &block) > ? ? ? '*a_method_missing*' > ? ? end > > ? ? def self.present_method(arg) > ? ? ? '*present_method*' > ? ? end > ? end > > ? class B < A > ? ? def self.method_missing(name, *args, &block) > ? ? ? '*b_method_missing*' > ? ? end > ? end > > ? it 'should call derived class method_missing when args differ from what is > stubbed' do > ? ? B.stub!(:missing_method).with(1).and_return '*stub*' > ? ? B.missing_method(2).should == '*b_method_missing*' > ? end > > ? it 'should call present_method when it is defined in parent class and args > differ from what is stubbed' do > ? ? B.stub!(:present_method).with(1).and_return '*stub*' > ? ? B.present_method(2).should == '*present_method*' > ? end > end > > ---------- Forwarded message ---------- > From: Alexey Ilyichev > Date: Thu, Oct 28, 2010 at 12:44 PM > Subject: Issue with AR::Base descendants with certain argument > To: rspec-us... at rubyforge.org > > Hi! > > I am trying to upgrade rspec-rails to 1.3.3, and one of my specs fails. > > In before :each I stub finder method like this: > Payment.stub!(:find_by_id).with(@payment.id.to_s).and_return @payment > Payment class is derived from AR::Base > > And then in one of the examples I call Payment.find_by_id((@payment.id + > 1).to_s), and I am expecting it to return null, as it used to with 1.2.9 > version, however it leads to an exception in active_record/base.rb. > Analyzing the stack trace I figured that in line 115 of mock/proxy.rb method > find_by_id is called for ActiveRecord::Base, which is not correct. > > I'm not familiar with rspec internals, so I don't have an idea on where in > code the actual problem is. So any help would be greatly appreciated. The expected behaviour is that when you stub or mock a method on a real object (we call this partial stubbing/mocking), the framework takes over that method for the duration of the example. So the expectation that when the wrong args are received the call is delegated to the original object is incorrect, and making this change would introduce potential problems for other users who count on this behaviour. There is a request to add an explicit way to call to the original in rspec-mocks-2's issue tracker: http://github.com/rspec/rspec-mocks/issues#issue/23. HTH, David From starempireelite at gmail.com Sun Oct 31 21:14:51 2010 From: starempireelite at gmail.com (Curious Yogurt) Date: Sun, 31 Oct 2010 18:14:51 -0700 (PDT) Subject: [rspec-users] How do I figure out which (wrong) file rspec is loading? Message-ID: <38fb2488-9f95-4840-b540-ca9a518b4c0b@l8g2000yql.googlegroups.com> I'm using Rails 3.0.1, RSpec-Rails 2.0.1 and Webrat 0.7.1. I have the following test: describe PagesController do describe "GET 'main'" do it "should have the right title" do get 'main' response.should have_selector("title", :content => "My title") end end end The HTML of pages#main checks out: it contains My Title. When I run rspec, it gives me a failure on this test, and says it expects to find the tag in the following line: Since this is not the file stored at pages#main, I take it that rspec is, for some reason, loading the wrong page. How do I solve this? Or, failing a general solution, how can I get rspec to tell me which page it is trying to load, so that I can try to figure out why it is going to this other page? Thanks.