From peter.boling at gmail.com Fri Apr 1 09:19:50 2011 From: peter.boling at gmail.com (Peter Boling) Date: Fri, 1 Apr 2011 06:19:50 -0700 (PDT) Subject: [rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs? In-Reply-To: Message-ID: <13572405.970.1301663990605.JavaMail.geo-discussion-forums@yqog4> Wow! That's perfect, I think. I'll have to play around with it and make sure the after suite can be made to only run code if the entire suite has been run, but it looks promising! - Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.boling at gmail.com Fri Apr 1 11:34:43 2011 From: peter.boling at gmail.com (Peter Boling) Date: Fri, 1 Apr 2011 08:34:43 -0700 (PDT) Subject: [rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs? In-Reply-To: <13572405.970.1301663990605.JavaMail.geo-discussion-forums@yqog4> Message-ID: <32825517.475.1301672083809.JavaMail.geo-discussion-forums@yqib16> The before and after :suite hooks work for running code before and after rspec runs all the tests specified, but I need it to explicitly *not run* when anything less than every single spec is being run. In other words is we are running rspec spec or rake spec I need this before and after :suite hooks to run (to clean-up VCR cassettes). If we are not running the full suite, then it would mistakenly delete the VCR cassettes that were not used by the spec run. So I need it to not run the before and after :suite code if running, for example, rake spec:models or rspec spec/controllers. I am not sure if rspec, or spec helper is aware of the full test suite being run. ARGV won't work because when rake spec runs it executes rspec with every individual spec's path, so there is no way to tell from ARGV if it is the full suite, without getting really hacky. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Fri Apr 1 12:31:57 2011 From: jko170 at gmail.com (Justin Ko) Date: Fri, 1 Apr 2011 09:31:57 -0700 Subject: [rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs? In-Reply-To: <32825517.475.1301672083809.JavaMail.geo-discussion-forums@yqib16> References: <13572405.970.1301663990605.JavaMail.geo-discussion-forums@yqog4> <32825517.475.1301672083809.JavaMail.geo-discussion-forums@yqib16> Message-ID: On Fri, Apr 1, 2011 at 8:34 AM, Peter Boling wrote: > The before and after :suite hooks work for running code before and after > rspec runs all the tests specified, but I need it to explicitly *not run* when > anything less than every single spec is being run. In other words is we are > running rspec spec or rake spec I need this before and after :suite hooks to > run (to clean-up VCR cassettes). If we are not running the full suite, then > it would mistakenly delete the VCR cassettes that were not used by the spec > run. > > So I need it to not run the before and after :suite code if running, for > example, rake spec:models or rspec spec/controllers. I am not sure if > rspec, or spec helper is aware of the full test suite being run. ARGV won't > work because when rake spec runs it executes rspec with every individual > spec's path, so there is no way to tell from ARGV if it is the full suite, > without getting really hacky. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You could make your own task that depends on "spec": task :task_to_run_all_spec_and_do_something_with_vcr => :spec do # my VCR code end Obviously, this wouldn't work with "rspec spec" -------------- next part -------------- An HTML attachment was scrubbed... URL: From kai.schlamp at googlemail.com Sat Apr 2 09:20:27 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Sat, 2 Apr 2011 06:20:27 -0700 (PDT) Subject: [rspec-users] stubbing directly vs using stub method Message-ID: <346b5c5b-f289-4ef2-8528-958acc2a387f@l30g2000vbn.googlegroups.com> I use RSpec mock and stub like this: hit = mock("hit", :stored => 5) This works fine, but when using this instead: hit = mock("hit").stub(:stored) { 5 } then I get undefined method `stored' for # I always thought both were equivalent. Can someone enlighten me? Regards, Kai From dchelimsky at gmail.com Sat Apr 2 11:04:20 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 2 Apr 2011 10:04:20 -0500 Subject: [rspec-users] stubbing directly vs using stub method In-Reply-To: <346b5c5b-f289-4ef2-8528-958acc2a387f@l30g2000vbn.googlegroups.com> References: <346b5c5b-f289-4ef2-8528-958acc2a387f@l30g2000vbn.googlegroups.com> Message-ID: <2AEBA10B-9330-42D0-93D9-E7ABFDCC50EC@gmail.com> On Apr 2, 2011, at 8:20 AM, Kai Schlamp wrote: > I use RSpec mock and stub like this: > > hit = mock("hit", :stored => 5) > > This works fine, but when using this instead: > > hit = mock("hit").stub(:stored) { 5 } > > then I get > > undefined method `stored' for # 0xb688bb78> > > I always thought both were equivalent. Can someone enlighten me? This error message tells you the problem: the `stub` method in the second example returns an instance of RSpec::Mocks::MessageExpectation, not the double itself. If you did it this way, you'd get what you were looking for: hit = mock('hit') hit.stub(:stored) { 5 } hit.stored.should eq(5) Make sense? David > Regards, > Kai From kai.schlamp at googlemail.com Sat Apr 2 13:21:26 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Sat, 2 Apr 2011 10:21:26 -0700 (PDT) Subject: [rspec-users] stubbing directly vs using stub method In-Reply-To: <2AEBA10B-9330-42D0-93D9-E7ABFDCC50EC@gmail.com> References: <346b5c5b-f289-4ef2-8528-958acc2a387f@l30g2000vbn.googlegroups.com> <2AEBA10B-9330-42D0-93D9-E7ABFDCC50EC@gmail.com> Message-ID: > hit = mock('hit') > hit.stub(:stored) { 5 } > hit.stored.should eq(5) > > Make sense? Of course :-) Thanks. From patmaddox at me.com Sat Apr 2 15:22:21 2011 From: patmaddox at me.com (Pat Maddox) Date: Sat, 02 Apr 2011 12:22:21 -0700 Subject: [rspec-users] stubbing directly vs using stub method In-Reply-To: <346b5c5b-f289-4ef2-8528-958acc2a387f@l30g2000vbn.googlegroups.com> References: <346b5c5b-f289-4ef2-8528-958acc2a387f@l30g2000vbn.googlegroups.com> Message-ID: On Apr 2, 2011, at 6:20 AM, Kai Schlamp wrote: > I use RSpec mock and stub like this: > > hit = mock("hit", :stored => 5) > > This works fine, but when using this instead: > > hit = mock("hit").stub(:stored) { 5 } Not that it's really necessary, but to make this work you can do: hit = mock('hit').tap {|h| h.stub(:stored) { 5 } } although I prefer passing a hash into mock, much cleaner :) Pat From apnea.diving.deep at gmail.com Sat Apr 2 16:03:13 2011 From: apnea.diving.deep at gmail.com (apneadiving) Date: Sat, 2 Apr 2011 13:03:13 -0700 (PDT) Subject: [rspec-users] Rails Rspec Capybara Testing Javascript Message-ID: <1b81f7fe-4177-409d-9f54-53404964c42b@l30g2000vbn.googlegroups.com> I'm testing a Rails 3 app with Rspec and Capybara. For my integration tests, I need to test javascript. Of course, I watched http://railscasts.com/episodes/257-request-specs-and-capybara which presents the basics very well. Unfortunately an error is raised in the javascript as I can see using save_and_open_page It seems characters are encoded by Capybara or Selenium so this js loop crashes because of the <: Reason: Uncaught SyntaxError: Unexpected token ; I did put: in my head so I can't understand the problem. From matt at mattwynne.net Sat Apr 2 18:22:40 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 2 Apr 2011 23:22:40 +0100 Subject: [rspec-users] Can't put shared example group in its own file In-Reply-To: <491888.303.1301281463700.JavaMail.geo-discussion-forums@prmp17> References: <491888.303.1301281463700.JavaMail.geo-discussion-forums@prmp17> Message-ID: On 28 Mar 2011, at 04:04, Mike T wrote: > Any ideas? All I'd like to do is have two specs in different files use the same shared example group. I saw a similar thread about autotest, but I am not using that. > > $ uname -a > Darwin mbp.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386 > $ ruby -v > ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] > $ rails -v > Rails 3.0.5 > $ rails new shared > $ cd shared/ > $ echo "gem 'rspec-rails', '~> 2.5'" >> Gemfile > $ bundle --without production > $ rails generate rspec:install > $ rails generate scaffold foo > $ rake db:migrate > $ mkdir spec/support > $ nano spec/support/stuff_spec.rb > > -- spec/support/stuff_spec.rb > shared_examples_for "bar" do > end I'm sure David already replied about this - don't name your shared examples group *_spec.rb otherwise RSpec will load it and try to run it as a spec file. > > $ rake spec > (in /tmp/shared) > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S bundle exec rspec ./spec/controllers/foos_controller_spec.rb ./spec/helpers/foos_helper_spec.rb ./spec/models/foo_spec.rb ./spec/requests/foos_spec.rb ./spec/routing/foos_routing_spec.rb ./spec/support/stuff_spec.rb ./spec/views/foos/edit.html.erb_spec.rb ./spec/views/foos/index.html.erb_spec.rb ./spec/views/foos/new.html.erb_spec.rb ./spec/views/foos/show.html.erb_spec.rb > /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:45:in `ensure_shared_example_group_name_not_taken': Shared example group 'bar' already exists (ArgumentError) > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:6:in `shared_examples_for' > from /private/tmp/shared/spec/support/stuff_spec.rb:1 > from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' > from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' > from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:227:in `load_dependency' > from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `autorun' > from /Library/Ruby/Gems/1.8/bin/rspec:19 > rake aborted! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Apr 2 18:34:05 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 2 Apr 2011 17:34:05 -0500 Subject: [rspec-users] Autotest Parallel Support In-Reply-To: <5f7a4de8-0f72-4dba-a563-e31abae9c6e5@o21g2000prh.googlegroups.com> References: <5f7a4de8-0f72-4dba-a563-e31abae9c6e5@o21g2000prh.googlegroups.com> Message-ID: On Mar 28, 2011, at 3:53 PM, snelson wrote: > I have a commit to add support for the -p (parallel) option to > autotest, which is a feature provided by @grosser's autotest fork. > > The discussion is here: https://github.com/grosser/autotest/issues/#issue/13 > The commit is here: https://github.com/thisbythem/rspec-core/commit/de074af8ab19e432b3c7b3c54fdf97494187e4aa > > Being that this adds a feature only supported by a forked version of > autotest, I wanted to get some feedback as to wether or not this could > even go into rspec-core. If not, then we'll explore other options. I'm planning to extract autotest support out of rspec-core into its own gem when we release rspec-3 later this year, so this might be a good opportunity to get that started. Would you be interested in being the maintainer of that gem? If so, we could get it started now with this addition, and then merge in the other features that are now part of rspec-core when we release rspec-core-3. Thoughts? Cheers, David From ckponnappa at gmail.com Sat Apr 2 18:45:38 2011 From: ckponnappa at gmail.com (Sidu Ponnappa) Date: Sun, 3 Apr 2011 04:15:38 +0530 Subject: [rspec-users] Error running rspec on Debian In-Reply-To: References: Message-ID: I just wanted to confirm that you've verified that the exact same codebase has its specs run correctly on a different OS (or flavour of linux, even)? Best, Sidu. http://c42.in http://about.me/ponnappa On 29 March 2011 06:34, Carlos Torres wrote: > I'm new to Rails and I was planning on trying out RSpec. When I try to > execute the rspec command on Debian v6.0.1, I get the output below: > k4ru050 at DebianBox:~/Desktop/rails_projects/sample_app/spec$ bundle exec > rspec spec/controllers > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in > `load': no such file to load -- > /home/k4ru050/Desktop/rails_projects/sample_app/spec/spec/controllers > (LoadError) > from > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in > `block in load_spec_files' > from > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in > `map' > from > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in > `load_spec_files' > from > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in > `run' > from > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in > `run_in_process' > from > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in > `run' > from > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in > `block in autorun' > The versions I'm using are: Rails v3.0.5, Ruby v1.9.2 ?installed via rvm. > Any suggestions on how to find a workaround for this issue? > Thanks, > Carlos > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Apr 3 11:40:08 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 3 Apr 2011 10:40:08 -0500 Subject: [rspec-users] Bundler and Setting up RSpec In-Reply-To: References: Message-ID: <2113458D-9D82-49D1-83C3-030D47470010@gmail.com> On Mar 28, 2011, at 9:59 AM, Stuart Corbishley wrote: > Hi there, > > Does RSpec acknowledge bundler, and use the groups? RSpec doesn't really know anything about Bundler's internals, but the rake task does look for a Gemfile and shells out to 'bundler exec rspec' if it sees one unless you configure the task with skip_bundler: RSpec::Core::RakeTask.new(:spec) do |t| t.skip_bundler = true end > Also is there any good example of what is required for a function spec > rake task... > > I've had issues trying to create my own. > > require 'rubygems' > require 'bundler' > Bundler.setup(:default, :test) > > begin > require 'rspec/core/rake_task' > desc "Run the specs under spec/" > RSpec::Rake::SpecTask.new > rescue NameError, LoadError => e > puts e > end > > I get this back: no such file to load -- rake/tasklib I'd guess that rake is not in the Gemfile. If this is a Rails app you don't need it because rake is a dependency of rails, but if not, you need to add it yourself. HTH, David > I had a similar issue with another project written by someone else. I > get the feeling I'm using the RSpec 1.x ways or something of the sort. > Any advice? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From dchelimsky at gmail.com Sun Apr 3 12:14:10 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 3 Apr 2011 11:14:10 -0500 Subject: [rspec-users] Error running rspec on Debian In-Reply-To: References: Message-ID: <7520CB74-EEF2-40E9-AB19-E1D2E863E610@gmail.com> On Mar 28, 2011, at 8:04 PM, Carlos Torres wrote: > I'm new to Rails and I was planning on trying out RSpec. When I try to execute the rspec command on Debian v6.0.1, I get the output below: > > k4ru050 at DebianBox:~/Desktop/rails_projects/sample_app/spec$ bundle exec rspec spec/controllers > /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load': no such file to load -- /home/k4ru050/Desktop/rails_projects/sample_app/spec/spec/controllers (LoadError) First, this particular error has nothing to do with rspec or your OS. The rspec command is being invoked from ~/Desktop/rails_projects/sample_app/spec, but the last argument is spec/controllers. Unless there is a /home/k4ru050/Desktop/rails_projects/sample_app/spec/spec/controllers directory (with two nested 'spec' directories), this error is raised. That said, on any OS, you must run the rspec command from the project root. k4ru050 at DebianBox:~/Desktop/rails_projects/sample_app$ bundle exec rspec spec/controllers This is necessary because there are too many variables for RSpec to reliably be run from other locations and detect the LOAD_PATH correctly. HTH, David > from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files' > from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map' > from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files' > from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run' > from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process' > from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run' > from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun' > > The versions I'm using are: Rails v3.0.5, Ruby v1.9.2 installed via rvm. > > Any suggestions on how to find a workaround for this issue? > > Thanks, > > Carlos From phillipkoebbe at gmail.com Sun Apr 3 15:45:14 2011 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 03 Apr 2011 14:45:14 -0500 Subject: [rspec-users] Ruby 1.9.2 confusion Message-ID: <4D98CE4A.80706@gmail.com> I'm wondering if someone could shed a little light on something for me. I'm trying to get a Rails 2.3.11 project running on Ruby 1.9.2-p180, and the same specs that pass on 1.8.7-p302 don't pass on 1.9.2-p180 if I run them one way, but do if I run them another way. If I run a particular view spec via script/spec, it passes: $ script/spec spec/views/admin/media/new.html.haml_spec.rb .......... Finished in 1.121665 seconds 10 examples, 0 failures If I run it via spec, it fails: $ spec spec/views/admin/media/new.html.haml_spec.rb ......FF.. 1) MiniTest::Assertion in 'admin/media/new.html.haml without errors should not have a mime type select list' Expected at least 1 element matching "select#medium_mime_type_id", found 0. /Users/phillip/.rvm/gems/ruby-1.9.2-p180 at ischpc-2.3.11/gems/actionpack-2.3.11/lib/action_controller/assertions/selector_assertions.rb:307:in `assert_select' spec/views/admin/media/new.html.haml_spec.rb:40:in `block (3 levels) in ' 2) MiniTest::Assertion in 'admin/media/new.html.haml without errors should not have a medium type select list' Expected at least 1 element matching "select#medium_type", found 0. /Users/phillip/.rvm/gems/ruby-1.9.2-p180 at ischpc-2.3.11/gems/actionpack-2.3.11/lib/action_controller/assertions/selector_assertions.rb:307:in `assert_select' spec/views/admin/media/new.html.haml_spec.rb:44:in `block (3 levels) in ' Finished in 1.020134 seconds 10 examples, 2 failures Here is some system information: $ which ruby /Users/phillip/.rvm/rubies/ruby-1.9.2-p180/bin/ruby $ ruby -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0] $ which spec /Users/phillip/.rvm/gems/ruby-1.9.2-p180 at ischpc-2.3.11/bin/spec $ spec -v rspec 1.3.1 $ script/spec -v rspec 1.3.1 rspec-rails 1.3.3 is installed in both gemsets for 1.8.7 and 1.9.2. Thanks for any help, Phillip From lists at ruby-forum.com Sun Apr 3 21:00:52 2011 From: lists at ruby-forum.com (Matt S.) Date: Mon, 04 Apr 2011 03:00:52 +0200 Subject: [rspec-users] fields_for view spec Message-ID: <0ce10793933e6583810c4c9f3c9eb576@ruby-forum.com> For some reason I can't figure out how to make the fields_for tags render in the trivial example below; however, it works in the browser. What does #build_association do that my stubbed method does not replicate? (Or is that even the issue?) I appreciate the insight. Thanks! Matt Smith #spec/views/assets/new.html.erb_spec.rb describe "assets/new.html.erb" do let(:asset) { mock_model("Asset").as_new_record.as_null_object } let(:owner) { mock_model("Owner").as_new_record.as_null_object } before(:each) do asset.stub(:owner => owner) assign(:asset, asset) end it "renders new asset form" do render assert_select "form", :action => assets_path, :method => "post" do assert_select "input#asset_name", :name => "asset[name]" # passes assert_select "input#asset_owner_attributes_name", :name => "asset[owner_attributes][name]" # fails! end end end #app/views/assets/_form.html.erb <%= form_for(@asset) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.fields_for :owner do |owner_fields| %>
<%= owner_fields.label :name %> <%= owner_fields.text_field :name %>
<% end %>
<%= f.submit %>
<% end %> -- Posted via http://www.ruby-forum.com/. From phillipkoebbe at gmail.com Sun Apr 3 23:17:32 2011 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 03 Apr 2011 22:17:32 -0500 Subject: [rspec-users] Ruby 1.9.2 confusion In-Reply-To: <4D98CE4A.80706@gmail.com> References: <4D98CE4A.80706@gmail.com> Message-ID: <4D99384C.7020500@gmail.com> On 2011-04-03 2:45 PM, Phillip Koebbe wrote: > I'm wondering if someone could shed a little light on something for > me. I'm trying to get a Rails 2.3.11 project running on Ruby > 1.9.2-p180, and the same specs that pass on 1.8.7-p302 don't pass on > 1.9.2-p180 if I run them one way, but do if I run them another way. > > If I run a particular view spec via script/spec, it passes: > > $ script/spec spec/views/admin/media/new.html.haml_spec.rb > .......... > > Finished in 1.121665 seconds > > 10 examples, 0 failures > > If I run it via spec, it fails: > > $ spec spec/views/admin/media/new.html.haml_spec.rb > ......FF.. > > 1) > MiniTest::Assertion in 'admin/media/new.html.haml without errors > should not have a mime type select list' > Expected at least 1 element matching "select#medium_mime_type_id", > found 0. > /Users/phillip/.rvm/gems/ruby-1.9.2-p180 at ischpc-2.3.11/gems/actionpack-2.3.11/lib/action_controller/assertions/selector_assertions.rb:307:in > `assert_select' > spec/views/admin/media/new.html.haml_spec.rb:40:in `block (3 levels) > in ' > > 2) > MiniTest::Assertion in 'admin/media/new.html.haml without errors > should not have a medium type select list' > Expected at least 1 element matching "select#medium_type", found 0. > /Users/phillip/.rvm/gems/ruby-1.9.2-p180 at ischpc-2.3.11/gems/actionpack-2.3.11/lib/action_controller/assertions/selector_assertions.rb:307:in > `assert_select' > spec/views/admin/media/new.html.haml_spec.rb:44:in `block (3 levels) > in ' > > Finished in 1.020134 seconds > > 10 examples, 2 failures > > Here is some system information: > > $ which ruby > /Users/phillip/.rvm/rubies/ruby-1.9.2-p180/bin/ruby > > $ ruby -v > ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0] > > $ which spec > /Users/phillip/.rvm/gems/ruby-1.9.2-p180 at ischpc-2.3.11/bin/spec > > $ spec -v > rspec 1.3.1 > > $ script/spec -v > rspec 1.3.1 > > rspec-rails 1.3.3 is installed in both gemsets for 1.8.7 and 1.9.2. > > Thanks for any help, > Phillip Well, I "solved" my problem. I added gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 to the top of bin/spec of the rspec 1.3.1 gem and now both spec and rake spec work. It's a mystery to me that test-unit 1.2.3 is required in lib/tasks/spec.rake, but it doesn't seem to make a difference. Does anyone have an idea of how to resolve this without actually changing one of the gem's files? Phillip From chrismear at gmail.com Mon Apr 4 04:31:20 2011 From: chrismear at gmail.com (Chris Mear) Date: Mon, 4 Apr 2011 09:31:20 +0100 Subject: [rspec-users] fields_for view spec In-Reply-To: <0ce10793933e6583810c4c9f3c9eb576@ruby-forum.com> References: <0ce10793933e6583810c4c9f3c9eb576@ruby-forum.com> Message-ID: On 4 April 2011 02:00, Matt S. wrote: > For some reason I can't figure out how to make the fields_for tags > render in the trivial example below; however, it works in the browser. > What does #build_association do that my stubbed method does not > replicate? (Or is that even the issue?) > > I appreciate the insight. Thanks! Matt Smith > > #spec/views/assets/new.html.erb_spec.rb > describe "assets/new.html.erb" do > ?let(:asset) { mock_model("Asset").as_new_record.as_null_object } > ?let(:owner) { mock_model("Owner").as_new_record.as_null_object } > > ?before(:each) do > ? ?asset.stub(:owner => owner) > ? ?assign(:asset, asset) > ?end > > ?it "renders new asset form" do > ? ?render > > ? ?assert_select "form", :action => assets_path, :method => "post" do > ? ? ?assert_select "input#asset_name", :name => "asset[name]" # passes > ? ? ?assert_select "input#asset_owner_attributes_name", :name => > "asset[owner_attributes][name]" # fails! > ? ?end > ?end > end > > #app/views/assets/_form.html.erb > <%= form_for(@asset) do |f| %> > > ?
> ? ?<%= f.label :name %>
> ? ?<%= f.text_field :name %> > ?
> > ?<%= f.fields_for :owner do |owner_fields| %> > ? ?
> ? ? ?<%= owner_fields.label :name %> > ? ? ?<%= owner_fields.text_field :name %> > ? ?
> ?<% end %> > > ?
> ? ?<%= f.submit %> > ?
> <% end %> In similar view specs, I've stubbed #owner_attributes= on the 'assets' mock. I think Rails' nested form/assignment implementation does a check on the existence of this method to make sure that the Asset model does indeed accept nested assignment for that attribute. Chris From lists at ruby-forum.com Tue Apr 5 02:45:36 2011 From: lists at ruby-forum.com (Scarmt Yelon) Date: Tue, 05 Apr 2011 08:45:36 +0200 Subject: [rspec-users] spec_helper aware of full test suite being run? After hook to run code after running all specs? In-Reply-To: References: Message-ID: The other day my child wanted to make a project. As a Dad it was my duty to help him out in his project. But when he told me the topic, I was so moved by it, http://www.samrx.com/buy-kamagra-oral-jelly.aspx because your name popped in my mind immediately and within no time the project could be completed. Thank you for your stuff!!! You are good. -- Posted via http://www.ruby-forum.com/. From akleak at gmail.com Sun Apr 3 11:24:51 2011 From: akleak at gmail.com (andyl) Date: Sun, 3 Apr 2011 08:24:51 -0700 (PDT) Subject: [rspec-users] Mocks and CL Programs Message-ID: <3753194.849.1301844291096.JavaMail.geo-discussion-forums@preo10> I am using rspec/aruba to do integration tests of a command-line program i'm writing. I'd like to use something like FakeWeb to stub the network calls in the command-line program. But with aruba, the program under test runs in a separate process, and FakeWeb won't work. I'm thinking of adding a command-line option to my program for testing, and embedding the network faking into the executable. Alternatively, I could write a local web service that delivers fake results. But I hate these solutions! I'm curious if any of you have run into this issue, and if anyone can recommend a better approach. - Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Apr 5 09:43:55 2011 From: lists at ruby-forum.com (Matt S.) Date: Tue, 05 Apr 2011 15:43:55 +0200 Subject: [rspec-users] fields_for view spec In-Reply-To: References: <0ce10793933e6583810c4c9f3c9eb576@ruby-forum.com> Message-ID: <04321818c332c2dccf8a1d9bfc0b0ba6@ruby-forum.com> Chris Mear wrote in post #990804: > On 4 April 2011 02:00, Matt S. wrote: >> let(:owner) { mock_model("Owner").as_new_record.as_null_object } >> assert_select "input#asset_name", :name => "asset[name]" # passes >> <%= f.label :name %>
>>
>> <%= f.submit %> >>
>> <% end %> > > In similar view specs, I've stubbed #owner_attributes= on the 'assets' > mock. I think Rails' nested form/assignment implementation does a > check on the existence of this method to make sure that the Asset > model does indeed accept nested assignment for that attribute. > > Chris Thanks Chris, I'll give that a try and post my solution. Matt -- Posted via http://www.ruby-forum.com/. From peter.boling at gmail.com Tue Apr 5 12:11:09 2011 From: peter.boling at gmail.com (Peter Boling) Date: Tue, 5 Apr 2011 09:11:09 -0700 (PDT) Subject: [rspec-users] no output from rspec In-Reply-To: Message-ID: <30533037.456.1302019869016.JavaMail.geo-discussion-forums@yqmi17> I had a similar issue recently. If you are using bundler and only specify rspec-rails to load in the :test environment, i.e. not in the :development environment, when you run rake rspec you will get no output. You must specify rspec-rails in :test AND :development (it doesn' t load the whole gem in :development, just the rake tasks and generators). -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Apr 5 14:04:45 2011 From: lists at ruby-forum.com (Matt S.) Date: Tue, 05 Apr 2011 20:04:45 +0200 Subject: [rspec-users] fields_for view spec In-Reply-To: <04321818c332c2dccf8a1d9bfc0b0ba6@ruby-forum.com> References: <0ce10793933e6583810c4c9f3c9eb576@ruby-forum.com> <04321818c332c2dccf8a1d9bfc0b0ba6@ruby-forum.com> Message-ID: <387340cfd47370902ce182c8361492c3@ruby-forum.com> Matt S. wrote in post #991032: >> In similar view specs, I've stubbed #owner_attributes= on the 'assets' >> mock. I think Rails' nested form/assignment implementation does a >> check on the existence of this method to make sure that the Asset >> model does indeed accept nested assignment for that attribute. >> >> Chris > > Thanks Chris, > > I'll give that a try and post my solution. > > Matt Well it appears I am still stumped... If I change Asset to: class Asset < ActiveRecord::Base belongs_to :owner accepts_nested_attributes_for :owner def owner_attributes=(attributes) #test end end The new form works in the browser, but not in the test. If I change my before block to the following (and eliminate the def owner_attributes=), the test still fails. before(:each) do asset.stub(:owner => owner) asset.stub(:owner_attributes=).with(anything()) # new line assign(:asset, asset) end Any thoughts? Am I stubbing this incorrectly? Much thanks, Matt -- Posted via http://www.ruby-forum.com/. From jimmymartin at gmail.com Tue Apr 5 21:58:06 2011 From: jimmymartin at gmail.com (James Martin) Date: Wed, 6 Apr 2011 11:58:06 +1000 Subject: [rspec-users] Mocks and CL Programs In-Reply-To: <3753194.849.1301844291096.JavaMail.geo-discussion-forums@preo10> References: <3753194.849.1301844291096.JavaMail.geo-discussion-forums@preo10> Message-ID: On Mon, Apr 4, 2011 at 1:24 AM, andyl wrote: > I am using rspec/aruba to do integration tests of a command-line program > i'm writing. > > ... > > Alternatively, I could write a local web service that delivers fake > results. > > I like the idea of this for end-to-end tests, depending on the complexity of the external service. -------------- next part -------------- An HTML attachment was scrubbed... URL: From shamaoke at hotmail.com Wed Apr 6 03:53:06 2011 From: shamaoke at hotmail.com (Shamaoke) Date: Wed, 6 Apr 2011 00:53:06 -0700 (PDT) Subject: [rspec-users] Metadata raises CompatibilityError when I try to inspect it Message-ID: <9055cef9-b0fa-4105-b667-9884b80d69f6@n10g2000yqf.googlegroups.com> Hi. When I try to inspect example metadata, for some reason it raises the encoding compatibility exception. ~~~ describe RSpec::Core::Metadata do describe '#inspect' do it 'raises Encoding::CompatibilityError' do expect { example.metadata.inspect }.to raise_error(Encoding::CompatibilityError) end end describe '#to_s' do it 'raises Encoding::CompatibilityError' do expect { example.metadata.to_s }.to raise_error(Encoding::CompatibilityError) end end end ~~~ ~~~ $ rspec metadata_spec.rb .. Finished in 0.00128 seconds 2 examples, 0 failures ~~~ It raises nothing if I use the `$ ruby ...` instead of `$ rspec ...` command. What is the reason of this bug? How can I fix it? Thanks. Debian GNU/Linux 6.0.1; Ruby 1.9.2p0; RSpec 2.5.1. From jko170 at gmail.com Thu Apr 7 01:04:40 2011 From: jko170 at gmail.com (Justin Ko) Date: Wed, 6 Apr 2011 22:04:40 -0700 Subject: [rspec-users] Metadata raises CompatibilityError when I try to inspect it In-Reply-To: <9055cef9-b0fa-4105-b667-9884b80d69f6@n10g2000yqf.googlegroups.com> References: <9055cef9-b0fa-4105-b667-9884b80d69f6@n10g2000yqf.googlegroups.com> Message-ID: On Wed, Apr 6, 2011 at 12:53 AM, Shamaoke wrote: > Hi. > > When I try to inspect example metadata, for some reason it raises the > encoding compatibility exception. > > ~~~ > describe RSpec::Core::Metadata do > describe '#inspect' do > it 'raises Encoding::CompatibilityError' do > expect { > example.metadata.inspect > }.to raise_error(Encoding::CompatibilityError) > end > end > > describe '#to_s' do > it 'raises Encoding::CompatibilityError' do > expect { > example.metadata.to_s > }.to raise_error(Encoding::CompatibilityError) > end > end > end > ~~~ > > ~~~ > $ rspec metadata_spec.rb > .. > > Finished in 0.00128 seconds > 2 examples, 0 failures > ~~~ > > It raises nothing if I use the `$ ruby ...` instead of `$ rspec ...` > command. > > What is the reason of this bug? How can I fix it? > > Thanks. > > Debian GNU/Linux 6.0.1; > Ruby 1.9.2p0; > RSpec 2.5.1. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Hello, I think this might be a bug in your Ruby 1.9.2 patch version. I'm using 1.9.2-p180 and cannot reproduce this. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathanvda at gmail.com Thu Apr 7 10:37:15 2011 From: nathanvda at gmail.com (nathanvda) Date: Thu, 7 Apr 2011 07:37:15 -0700 (PDT) Subject: [rspec-users] getting weird "no route matches" error, using rspec2 and rails3 (just migrated) but app works Message-ID: Hi there, in my main view i have a link to the root_path, which converts to {:controller => "home", :action => :index} In every spec i run, i get the error: No route matches {:controller=>"home"} While if i run the application in development, everything renders without any problem and is clickable correctly. Does anybody have any clues as to what i did wrong? I should add that the rails application is in the process of being migrated from rails 2.3.11 to rails 3. I must have overlooked something, but i can't see what. Does anybody have any tips? From groups at inbox.avdi.org Thu Apr 7 13:20:51 2011 From: groups at inbox.avdi.org (Avdi Grimm) Date: Thu, 7 Apr 2011 13:20:51 -0400 Subject: [rspec-users] RSpec is for the literate Message-ID: I posted an article on RSpec this morning, I thought it might be of interest to this list: http://avdi.org/devblog/2011/04/07/rspec-is-for-the-literate/ -- Avdi Grimm http://avdi.org From patmaddox at me.com Thu Apr 7 17:44:09 2011 From: patmaddox at me.com (Pat Maddox) Date: Thu, 07 Apr 2011 14:44:09 -0700 Subject: [rspec-users] Mocks and CL Programs In-Reply-To: <3753194.849.1301844291096.JavaMail.geo-discussion-forums@preo10> References: <3753194.849.1301844291096.JavaMail.geo-discussion-forums@preo10> Message-ID: <315FB958-C8A9-4A7C-B100-EAC18F8EE5DF@me.com> On Apr 3, 2011, at 8:24 AM, andyl wrote: > I am using rspec/aruba to do integration tests of a command-line program i'm writing. > > I'd like to use something like FakeWeb to stub the network calls in the command-line program. > > But with aruba, the program under test runs in a separate process, and FakeWeb won't work. > > I'm thinking of adding a command-line option to my program for testing, and embedding the network faking into the executable. > > Alternatively, I could write a local web service that delivers fake results. > > But I hate these solutions! I'm curious if any of you have run into this issue, and if anyone can recommend a better approach. > > - Andy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Add a second CL program that loads up the test-specific stuff and then loads the original program. Have Aruba call that instead. Pat From szimek at gmail.com Thu Apr 7 09:22:47 2011 From: szimek at gmail.com (Szymon Nowak) Date: Thu, 7 Apr 2011 06:22:47 -0700 (PDT) Subject: [rspec-users] How to use url helpers like link_to in mailers specs? Message-ID: <18624020.351.1302182567064.JavaMail.geo-discussion-forums@yqhp25> Hey, I tried including ActionView::Helpers::UrlHelper, but it was complaining about missing "controller" method. Cheers, Szymon -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.kanev at gmail.com Fri Apr 8 02:52:58 2011 From: stefan.kanev at gmail.com (Stefan Kanev) Date: Fri, 8 Apr 2011 09:52:58 +0300 Subject: [rspec-users] Overriding Kernel#inspect just for tests Message-ID: Hi all. Occasionally, I write specs that verify the order in which some ActiveRecord objects are returned. For example, in a toy project I do: Reply.stub :per_page => 2 topic.replies_on_page(1).should == [second, first] The spec out quickly get unwieldy when it fails: 1) Topic paginates its replies in chronological order Failure/Error: topic.replies_on_page(1).should == [second, first] expected: [#, #] got: [#, #] (using ==) This is a rather simple example with a simple model. If Topic would have more columns or the list contains more items, it quickly gets very hard to understand the failure. I tried overriding #inpsect in my models, but I'm not sure I like that. Results are a lot better, but now using rails console gets trickier. Is there a way to do this just for RSpec? I found an old thread in rspec-devel [1], but I don't think it ever resulted to something that got merged. [1]: http://old.nabble.com/Better-inspect-method-for-active-record-objects-in-rspec-rails-td20297318.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathanvda at gmail.com Fri Apr 8 03:08:36 2011 From: nathanvda at gmail.com (nathanvda) Date: Fri, 8 Apr 2011 00:08:36 -0700 (PDT) Subject: [rspec-users] getting weird "no route matches" error, using rspec2 and rails3 (just migrated) but app works In-Reply-To: References: Message-ID: <739824ec-9158-48ea-87e0-2f2adef0db0b@d19g2000yql.googlegroups.com> More information: If i run rspec spec/**/*_spec.rb I suddenly get the same errors as when using `rake spec`. So??? rspec spec/controllers/user_controller/*_spec.rb gives all green, and with the first command those same specs fail ???? From nathanvda at gmail.com Fri Apr 8 03:00:57 2011 From: nathanvda at gmail.com (nathanvda) Date: Fri, 8 Apr 2011 00:00:57 -0700 (PDT) Subject: [rspec-users] getting weird "no route matches" error, using rspec2 and rails3 (just migrated) but app works In-Reply-To: References: Message-ID: > > in my main view i have a link to the root_path, which converts to > > ? ? {:controller => "home", :action => :index} > > In every spec i run, i get the error: > > ? ? No route matches {:controller=>"home"} > > While if i run the application in development, everything renders > without any problem and is clickable correctly. > [EDIT: more findings] I have done some more digging. The test run perfectly fine in Rubymine, or if i use the command-line and type rspec spec/controllers/users_controller/*.spec.rb But they do not work if I use rake spec What is the difference? I have deleted the `lib/tasks/rspec.rake` file (which was generated for rspec1) and i can see that the correct command is executed: bundle exec rspec So I am a bit at a loss here. From simon.krollpfeifer at gmail.com Fri Apr 8 07:25:39 2011 From: simon.krollpfeifer at gmail.com (Clint) Date: Fri, 8 Apr 2011 04:25:39 -0700 (PDT) Subject: [rspec-users] [rspec-rails] reload of objects in tests Message-ID: hi, I am kind of confused, why this code is behaving the way it does. In a test, I wrote something like this: it "should do something" do @some = Factory(:some) initial_object = @some #do something with @some. e.g. update attributes etc. @some.reload @some.should_not == initial_object end Whenever I call reload on the object, the initial_object is set to object again. I don't understand why a reload on @some is also updating initial_object. Can someone explain this to me please? From dchelimsky at gmail.com Fri Apr 8 08:43:26 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Apr 2011 07:43:26 -0500 Subject: [rspec-users] Overriding Kernel#inspect just for tests In-Reply-To: References: Message-ID: On Fri, Apr 8, 2011 at 1:52 AM, Stefan Kanev wrote: > Hi all. > Occasionally, I write specs that verify the order in which some ActiveRecord > objects are returned. For example, in a toy project I do: > > Reply.stub :per_page => 2 > topic.replies_on_page(1).should == [second, first] > > The spec out quickly get unwieldy when it fails: > > 1) Topic paginates its replies in chronological order > ?? Failure/Error: topic.replies_on_page(1).should == [second, first] > ?? expected: [# created_at: "2011-04-07 06:38:34", updated_at: "2011-04-08 06:38:34">, > # "2011-04-06 06:38:34", updated_at: "2011-04-08 06:38:34">] > ?? ? ? got: [# created_at: "2011-04-06 06:38:34", updated_at: "2011-04-08 06:38:34">, > # "2011-04-07 06:38:34", updated_at: "2011-04-08 06:38:34">] (using ==) > > This is a rather simple example with a simple model. If Topic would have > more columns or the list contains more items, it quickly gets very hard to > understand the failure. > I tried overriding #inpsect in my models, but I'm not sure I like that. > Results are a lot better, but now using rails console gets trickier. > Is there a way to do this just for RSpec? Of course! Remember, this is just Ruby. Put something like this in spec/spec_helper.rb: #################### module InspectModelForRSpec def inspect ... end end ActiveRecord::Base.send(:include, InspectModelForRSpec) #################### Now, as long as the code is not inadvertently loading up spec/spec_helper.rb when running the app or console, you'll only see the result of this when you run specs. HTH, David >I found an old thread in > rspec-devel [1], but I don't think it ever resulted to something that got > merged. > [1]:?http://old.nabble.com/Better-inspect-method-for-active-record-objects-in-rspec-rails-td20297318.html > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nathanvda at gmail.com Fri Apr 8 09:01:29 2011 From: nathanvda at gmail.com (nathanvda) Date: Fri, 8 Apr 2011 06:01:29 -0700 (PDT) Subject: [rspec-users] getting weird "no route matches" error, using rspec2 and rails3 (just migrated) but app works In-Reply-To: References: Message-ID: <711c5a44-4dad-4bdf-a8a5-97d961a71110@27g2000yqv.googlegroups.com> I found it! It took my a while, eventually i diffed the log-files that see what happens differently. Apparently I have on spec file, where we try to test a baseclass. Inside that spec we define a new controller that derives from that baseclass, with a dummy index method. And also we need the routes, so inside that spec the following code was to be found: ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end and somehow this spec was always run first. This effectively clears the whole routing configuration i guess. Not sure if this change is caused by rails3 or rspec2, anyway the majority of my tests are now working, just need to fix this one test now. From stefan.kanev at gmail.com Fri Apr 8 09:30:15 2011 From: stefan.kanev at gmail.com (Stefan Kanev) Date: Fri, 8 Apr 2011 16:30:15 +0300 Subject: [rspec-users] Overriding Kernel#inspect just for tests In-Reply-To: References: Message-ID: Ah, that's clever. Thanks. On Fri, Apr 8, 2011 at 3:43 PM, David Chelimsky wrote: > On Fri, Apr 8, 2011 at 1:52 AM, Stefan Kanev > wrote: > > Hi all. > > Occasionally, I write specs that verify the order in which some > ActiveRecord > > objects are returned. For example, in a toy project I do: > > > > Reply.stub :per_page => 2 > > topic.replies_on_page(1).should == [second, first] > > > > The spec out quickly get unwieldy when it fails: > > > > 1) Topic paginates its replies in chronological order > > Failure/Error: topic.replies_on_page(1).should == [second, first] > > expected: [# > created_at: "2011-04-07 06:38:34", updated_at: "2011-04-08 06:38:34">, > > # > "2011-04-06 06:38:34", updated_at: "2011-04-08 06:38:34">] > > got: [# > created_at: "2011-04-06 06:38:34", updated_at: "2011-04-08 06:38:34">, > > # > "2011-04-07 06:38:34", updated_at: "2011-04-08 06:38:34">] (using ==) > > > > This is a rather simple example with a simple model. If Topic would have > > more columns or the list contains more items, it quickly gets very hard > to > > understand the failure. > > I tried overriding #inpsect in my models, but I'm not sure I like that. > > Results are a lot better, but now using rails console gets trickier. > > Is there a way to do this just for RSpec? > > Of course! Remember, this is just Ruby. Put something like this in > spec/spec_helper.rb: > > #################### > module InspectModelForRSpec > def inspect > ... > end > end > > ActiveRecord::Base.send(:include, InspectModelForRSpec) > #################### > > Now, as long as the code is not inadvertently loading up > spec/spec_helper.rb when running the app or console, you'll only see > the result of this when you run specs. > > HTH, > David > > >I found an old thread in > > rspec-devel [1], but I don't think it ever resulted to something that got > > merged. > > [1]: > http://old.nabble.com/Better-inspect-method-for-active-record-objects-in-rspec-rails-td20297318.html > > _______________________________________________ > > 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 mmazur at gmail.com Fri Apr 8 09:45:44 2011 From: mmazur at gmail.com (Mike Mazur) Date: Fri, 8 Apr 2011 21:45:44 +0800 Subject: [rspec-users] [rspec-rails] reload of objects in tests In-Reply-To: References: Message-ID: Hi, On Fri, Apr 8, 2011 at 19:25, Clint wrote: > I am kind of confused, why this code is behaving the way it does. > In a test, I wrote something like this: > > it "should do something" do > ?@some = Factory(:some) > ?initial_object = @some > > ?#do something with @some. e.g. update attributes etc. > ?@some.reload > ?@some.should_not == initial_object > end > > Whenever I call reload on the object, the initial_object is set to > object again. > I don't understand why a reload on @some is also updating > initial_object. > Can someone explain this to me please? It's because @some and initial_object both point to the same instance of an object. If you had: initial_object = @some.clone then initial_object and @some will point to separate instances. HTH, Mike From shamaoke at hotmail.com Sat Apr 9 10:14:11 2011 From: shamaoke at hotmail.com (Shamaoke) Date: Sat, 9 Apr 2011 07:14:11 -0700 (PDT) Subject: [rspec-users] Metadata raises CompatibilityError when I try to inspect it In-Reply-To: References: <9055cef9-b0fa-4105-b667-9884b80d69f6@n10g2000yqf.googlegroups.com> Message-ID: <7b1b0aaf-ea86-4ef1-b26b-92b3d90933ee@d28g2000yqf.googlegroups.com> I installed Ruby 1.9.2-p180 from the sources. Unfortunatelly, the bug still exists: http://dl.dropbox.com/u/20481401/compatability_error.png On 7 ???, 09:04, Justin Ko wrote: > On Wed, Apr 6, 2011 at 12:53 AM, Shamaoke wrote: > > Hi. > > > When I try to inspect example metadata, for some reason it raises the > > encoding compatibility exception. > > > ~~~ > > describe RSpec::Core::Metadata do > > ?describe '#inspect' do > > ? ?it 'raises Encoding::CompatibilityError' do > > ? ? ?expect { > > ? ? ? ?example.metadata.inspect > > ? ? ?}.to raise_error(Encoding::CompatibilityError) > > ? ?end > > ?end > > > ?describe '#to_s' do > > ? ?it 'raises Encoding::CompatibilityError' do > > ? ? ?expect { > > ? ? ? ?example.metadata.to_s > > ? ? ?}.to raise_error(Encoding::CompatibilityError) > > ? ?end > > ?end > > end > > ~~~ > > > ~~~ > > $ rspec metadata_spec.rb > > .. > > > Finished in 0.00128 seconds > > 2 examples, 0 failures > > ~~~ > > > It raises nothing if I use the `$ ruby ...` instead of `$ rspec ...` > > command. > > > What is the reason of this bug? How can I fix it? > > > Thanks. > > > Debian GNU/Linux 6.0.1; > > Ruby 1.9.2p0; > > RSpec 2.5.1. > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Hello, I think this might be a bug in your Ruby 1.9.2 patch version. I'm > using 1.9.2-p180 and cannot reproduce this. > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From shamaoke at hotmail.com Mon Apr 11 05:08:00 2011 From: shamaoke at hotmail.com (Shamaoke) Date: Mon, 11 Apr 2011 02:08:00 -0700 (PDT) Subject: [rspec-users] Metadata raises CompatibilityError when I try to inspect it In-Reply-To: <7b1b0aaf-ea86-4ef1-b26b-92b3d90933ee@d28g2000yqf.googlegroups.com> References: <9055cef9-b0fa-4105-b667-9884b80d69f6@n10g2000yqf.googlegroups.com> <7b1b0aaf-ea86-4ef1-b26b-92b3d90933ee@d28g2000yqf.googlegroups.com> Message-ID: <08677b46-785a-41af-8b57-9442d059eaeb@x1g2000yqb.googlegroups.com> I tackled the problem. If you use the Unicode characters in the path to a spec directory the bug appears. If not to use them, all goes without any problems. So, using the path `/home/username/??????????/ruby/my_application/ spec` will raise the exception, but `/home/username/development/ruby/ my_application/spec` will not. On 9 ???, 18:14, Shamaoke wrote: > I installed Ruby 1.9.2-p180 from the sources. Unfortunatelly, the bug > still exists: > > http://dl.dropbox.com/u/20481401/compatability_error.png > > On 7 ???, 09:04, Justin Ko wrote: > > > > > > > > > On Wed, Apr 6, 2011 at 12:53 AM, Shamaoke wrote: > > > Hi. > > > > When I try to inspect example metadata, for some reason it raises the > > > encoding compatibility exception. > > > > ~~~ > > > describe RSpec::Core::Metadata do > > > ?describe '#inspect' do > > > ? ?it 'raises Encoding::CompatibilityError' do > > > ? ? ?expect { > > > ? ? ? ?example.metadata.inspect > > > ? ? ?}.to raise_error(Encoding::CompatibilityError) > > > ? ?end > > > ?end > > > > ?describe '#to_s' do > > > ? ?it 'raises Encoding::CompatibilityError' do > > > ? ? ?expect { > > > ? ? ? ?example.metadata.to_s > > > ? ? ?}.to raise_error(Encoding::CompatibilityError) > > > ? ?end > > > ?end > > > end > > > ~~~ > > > > ~~~ > > > $ rspec metadata_spec.rb > > > .. > > > > Finished in 0.00128 seconds > > > 2 examples, 0 failures > > > ~~~ > > > > It raises nothing if I use the `$ ruby ...` instead of `$ rspec ...` > > > command. > > > > What is the reason of this bug? How can I fix it? > > > > Thanks. > > > > Debian GNU/Linux 6.0.1; > > > Ruby 1.9.2p0; > > > RSpec 2.5.1. > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.org > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > Hello, I think this might be a bug in your Ruby 1.9.2 patch version. I'm > > using 1.9.2-p180 and cannot reproduce this. > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From pablolmiranda at gmail.com Mon Apr 11 13:53:56 2011 From: pablolmiranda at gmail.com (Pablo L. de Miranda) Date: Mon, 11 Apr 2011 14:53:56 -0300 Subject: [rspec-users] Subdomain test Message-ID: Hi guys, I'm developing a app where each subdomain has a independent data set. I did a few tries to rewrite a test for this, but all were unsuccessful. Do someone has a example how I can do that? any reference will help. Thanks, Pablo pablolmiranda at gmail.com From me at jbrains.ca Mon Apr 11 14:06:18 2011 From: me at jbrains.ca (J. B. Rainsberger) Date: Mon, 11 Apr 2011 14:06:18 -0400 Subject: [rspec-users] Overriding Kernel#inspect just for tests In-Reply-To: References: Message-ID: On Fri, Apr 8, 2011 at 02:52, Stefan Kanev wrote: > Occasionally, I write specs that verify the order in which some ActiveRecord > objects are returned. For example, in a toy project I do: > > Reply.stub :per_page => 2 > topic.replies_on_page(1).should == [second, first] > > The spec out quickly get unwieldy when it fails: If you only want to check the identity of the Reply objects, then shouldn't you only check the identity of the Reply objects? topic.replies_on_page(1).collect(&:id).should == [second, first].collect(&:id) Now introduce a custom matcher and off you go. topic.replies_on_page(1).should match_models([second, first]), maybe? -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From chrismear at gmail.com Mon Apr 11 16:44:11 2011 From: chrismear at gmail.com (Chris Mear) Date: Mon, 11 Apr 2011 21:44:11 +0100 Subject: [rspec-users] Subdomain test In-Reply-To: References: Message-ID: On Monday, 11 April 2011, Pablo L. de Miranda wrote: > Hi guys, > I'm developing a app where each subdomain has a independent data set. > I did a few tries to rewrite a test for this, but all were unsuccessful. > Do someone has a example how I can do that? any reference will help. In our app, we've used a request spec to specifically check some of our subdomain-related behaviour: https://github.com/oneclickorgs/one-click-orgs/blob/master/spec/requests/multi_tenancy_spec.rb This works by passing full URLs to #get, #post, etc.. The rest of the app specs rely on a method in ApplicationController which checks the subdomain of the request and does the necessary setup and data look-up. In the app, this is called in a before_filter on every action, and in the specs we stub this method to return the appropriate mock objects. Hope that gives some guidance. Chris From pablolmiranda at gmail.com Mon Apr 11 22:06:20 2011 From: pablolmiranda at gmail.com (Pablo L. de Miranda) Date: Mon, 11 Apr 2011 23:06:20 -0300 Subject: [rspec-users] Subdomain test In-Reply-To: References: Message-ID: Chris, Thanks man, it's great your code. I did a fork and started study it. Thank you again, Pablo pablolmiranda at gmail.com From dchelimsky at gmail.com Mon Apr 11 23:55:23 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Apr 2011 22:55:23 -0500 Subject: [rspec-users] rspec-1.3.2 is released! Message-ID: <2786D601-1AED-4B5A-9519-B1692FF6284A@gmail.com> rspec-1.3.2 is released! This is primarily a bug-fix release of the rspec-1.x series, and is recommended for all users who have not yet upgraded to rspec-2. === Version 1.3.2 / 2011-04-11 * Enhancements * Raise a meaningful error when an argument-scoped stub is called with the wrong args (Alexey) * Dev: ignore .rbc files (Myron Marston) * Bug fixes * Fix regression in which an expectation should return the value from a previously defined stub of the same method (Tom Stuart) * Support heckling class methods (Dan Kubb) * Only try to pass messages to the superclass if the superclass responds to the method (Andrew Selder) From dchelimsky at gmail.com Mon Apr 11 23:55:25 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Apr 2011 22:55:25 -0500 Subject: [rspec-users] rspec-rails-1.3.4 is released! Message-ID: <2728FCA9-E463-4BF9-9FB8-38CA9F7056C1@gmail.com> rspec-rails-1.3.4 is released! === Version 1.3.4 / 2011-04-11 * No new code * Depends on rspec ~> 1.3.2 * rspec-rails 1.3.3 depended on rspec-1.3.1 explicitly, so this release allows you to upgrade to rspec-1.3.2 with rspec-rails. From stephen.bannasch at deanbrook.org Tue Apr 12 10:45:22 2011 From: stephen.bannasch at deanbrook.org (Stephen Bannasch) Date: Tue, 12 Apr 2011 10:45:22 -0400 Subject: [rspec-users] rspec-1.3.2 is released! In-Reply-To: <2786D601-1AED-4B5A-9519-B1692FF6284A@gmail.com> References: <2786D601-1AED-4B5A-9519-B1692FF6284A@gmail.com> Message-ID: At 10:55 PM -0500 4/11/11, David Chelimsky wrote: >rspec-1.3.2 is released! > >This is primarily a bug-fix release of the rspec-1.x series, and is recommended for all users who have not yet upgraded to rspec-2. > Thanks for simplifying the gem build process by getting rid of hoe and using the bundler gem tasks along with the built-in gem functions. I got so annoyed yesterday trying to figure out why I couldn't get the rspec gem to build with hoe v2.9.4 -- there was still a reference to geminstaller.yml in the manifest and hoe was interpreting plain text in the readme as a url and auto-populating the gem spec.homepage attribute with this text -- which was invalid (at least it was with RubyGems 1.7.2). It's SO much simpler and less magical now! From lists at ruby-forum.com Tue Apr 12 14:59:35 2011 From: lists at ruby-forum.com (josh wall) Date: Tue, 12 Apr 2011 20:59:35 +0200 Subject: [rspec-users] RSpec 2.5 not seeing MiniTests? Message-ID: <0b1f45ae5f07aabdbd8307be4c0ee0d2@ruby-forum.com> I originally tried using the upgrade instructions on relish/core/upgrade but eventually stripped it down to a couple files and still cannot get RSpec to pick up my minitest tests. I don't actually use describe/should syntax, I am basically using Test::Unit but wanted the nice html formatting RSpec provides. I included both styles here for illustration. ####### On rspec1.2.9 it would have looked like ####### ### testpass.rb ### require 'spec/test/unit' class TestPass01 < TestUnit::Unit::TestCase def test_pass assert(true) end end describe 'testpass02' do it 'passes' do true end end ### command/output ### C:\tests\spec>spec testpass.rb .. Finished in 0.23 seconds 2 examples, 0 failures Neat, they're both found... ####### current config ####### winXP ruby 1.9.2p180 (2011-02-18) [i386-mingw32] rspec (2.5.0) rspec-core (2.5.1) rspec-expectations (2.5.0) rspec-mocks (2.5.0) ### spec_helper.rb ### puts '-->in spec_helper.rb' RSpec.configure do |config| config.run_all_when_everything_filtered = true config.expect_with :stdlib # => Test::Unit or MiniTest end ### TestPass01.rb ### puts '-->in TestPass01.rb' require 'minitest/unit' #got same behavior with 'minitest/autorun' class TestPass01 < MiniTest::Unit::TestCase puts '-->in class TestPass01' def test_pass_spec puts '-->in test test_pass_spec' assert(true) end end describe 'testpass02' do it 'passes' do puts '-->in test testpass02' true end end ### command line/output ### C:\tests\spec>rspec -r spec_helper.rb TestPass01.rb -->in spec_helper.rb -->in TestPass01.rb -->in class TestPass01 -->in test testpass02 . Finished in 0 seconds 1 example, 0 failures It's finding testpass02 but not testpass01. I have been banging my head against this for a couple days. Any help is greatly appreciated... -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Apr 12 15:53:16 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Apr 2011 14:53:16 -0500 Subject: [rspec-users] RSpec 2.5 not seeing MiniTests? In-Reply-To: <0b1f45ae5f07aabdbd8307be4c0ee0d2@ruby-forum.com> References: <0b1f45ae5f07aabdbd8307be4c0ee0d2@ruby-forum.com> Message-ID: On Apr 12, 2011, at 1:59 PM, josh wall wrote: > I originally tried using the upgrade instructions on relish/core/upgrade > but eventually stripped it down to a couple files and still cannot get > RSpec to pick up my minitest tests. I don't actually use > describe/should syntax, I am basically using Test::Unit but wanted the > nice html formatting RSpec provides. I included both styles here for > illustration. > > > ####### On rspec1.2.9 it would have looked like ####### > > ### testpass.rb ### > require 'spec/test/unit' > > class TestPass01 < TestUnit::Unit::TestCase > def test_pass > assert(true) > end > end > > describe 'testpass02' do > it 'passes' do > true > end > end > > > ### command/output ### > C:\tests\spec>spec testpass.rb > .. > Finished in 0.23 seconds > 2 examples, 0 failures > > > Neat, they're both found... > > > > > > ####### current config ####### > winXP > ruby 1.9.2p180 (2011-02-18) [i386-mingw32] > rspec (2.5.0) > rspec-core (2.5.1) > rspec-expectations (2.5.0) > rspec-mocks (2.5.0) > > > > ### spec_helper.rb ### > puts '-->in spec_helper.rb' > > RSpec.configure do |config| > config.run_all_when_everything_filtered = true > config.expect_with :stdlib # => Test::Unit or MiniTest > end > > > ### TestPass01.rb ### > puts '-->in TestPass01.rb' > > require 'minitest/unit' #got same behavior with 'minitest/autorun' > > class TestPass01 < MiniTest::Unit::TestCase > puts '-->in class TestPass01' > > def test_pass_spec > puts '-->in test test_pass_spec' > assert(true) > end > > end > > describe 'testpass02' do > it 'passes' do > puts '-->in test testpass02' > true > end > end > > > > ### command line/output ### > C:\tests\spec>rspec -r spec_helper.rb TestPass01.rb > -->in spec_helper.rb > -->in TestPass01.rb > -->in class TestPass01 > -->in test testpass02 > . > > Finished in 0 seconds > 1 example, 0 failures > > > It's finding testpass02 but not testpass01. I have been banging my head > against this for a couple days. Any help is greatly appreciated... RSpec-2 does not support running subclasses of Test::Unit::TestCase or MiniTest::Unit::TestCase. Just change the TestCase class declarations to calls to describe and you're good to go - you'll have access to all of the assertions, as you've seen in your example. HTH, David From ngw at nofeed.org Tue Apr 12 21:48:38 2011 From: ngw at nofeed.org (Nicholas Wieland) Date: Tue, 12 Apr 2011 18:48:38 -0700 Subject: [rspec-users] Need suggestions on how to test a class Message-ID: <824FB611-E7B5-46A2-88E1-0F1BF9923988@nofeed.org> Hi *, the class I need to test is: https://gist.github.com/49ef28014bb648ffa63e I know my question is very generic, but I honestly fail to see how to test something that is so strictly procedural and so dependent to the platform/libraries. Should I mock/stub filesystem, services and pretty much everything that is in there and test how it responds to different inputs, or adopt an "integration style" ? How would you proceed in this case ? (you can refer to RSpec book and point to parts that are relevant). ngw -- [ 926381, 23200231779, 1299022, 1045307475 ].collect { |a| a.to_s( 36 ) }.join( " " ) Nicholas Wieland (ngw) ngw at nofeed.org http://www.nofeed.org From matt at mattwynne.net Wed Apr 13 04:49:10 2011 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 13 Apr 2011 09:49:10 +0100 Subject: [rspec-users] Need suggestions on how to test a class In-Reply-To: <824FB611-E7B5-46A2-88E1-0F1BF9923988@nofeed.org> References: <824FB611-E7B5-46A2-88E1-0F1BF9923988@nofeed.org> Message-ID: <2A1F6332-24C3-490B-87D3-FAF8D50CDAE4@mattwynne.net> On 13 Apr 2011, at 02:48, Nicholas Wieland wrote: > Hi *, the class I need to test is: > > https://gist.github.com/49ef28014bb648ffa63e > > I know my question is very generic, but I honestly fail to see how to test something that is so strictly procedural and so dependent to the platform/libraries. > Should I mock/stub filesystem, services and pretty much everything that is in there and test how it responds to different inputs, or adopt an "integration style" ? > How would you proceed in this case ? (you can refer to RSpec book and point to parts that are relevant). > > ngw It depends on what you're worried about breaking. It looks to me like the unpack method is the most likely one to go wrong, and the most likely one to grow with more cases, so I'd focus my effort on that. You have about three distinct responsibilities going on in this class - there's something which sets up a directory structure, something which fetches zip files from S3, and something which unpacks a zip file into a folder structure. If you encapsulated what's going on in #sandbox into a Target or Destination or Sandbox class, with methods like write_stylesheet and and write_image, you could mock out that object easily. Similarly if you create a wrapper object around the responsibility of calling S3, you'd be able to test your unpack method with some fixture zip files from your test suite. The Sandbox and S3Fetcher classes will be pretty simple and unlikely to break, so you might not need to test them at all, other than with a quick manual integration test. Depending on how mission critical this code is, you might want a simple integration test to check it all wires up, but that depends on you appetite for risk, how often this code will change, and where that change happens. If all you do is add more cases to the unpack method, you're going to be safe testing those changes with specs and running a quick manual test. > > -- > [ 926381, 23200231779, 1299022, 1045307475 ].collect { |a| a.to_s( 36 ) }.join( " " ) > Nicholas Wieland (ngw) > ngw at nofeed.org > http://www.nofeed.org > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt -- Freelance programmer & coach Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne From lists at ruby-forum.com Wed Apr 13 04:56:23 2011 From: lists at ruby-forum.com (Paul S.) Date: Wed, 13 Apr 2011 10:56:23 +0200 Subject: [rspec-users] Skipping callbacks that aren't necessary for what i'm testing Message-ID: I have an Address model that has a before_validation callback that goes off and geocodes the address. I'm concerned that for all the tests in my Address model I'm going to be triggering that callback, even when it's not what I'm testing. Is there a nice way to stub the callback by default for all tests on a model and then re-enable it for specific tests that are testing the geocoding functionality. I'm using Rspec 2.5, Factory Girl and also Shoulda matchers. Any tips greatly received. Paul. -- Posted via http://www.ruby-forum.com/. From ckponnappa at gmail.com Wed Apr 13 05:57:07 2011 From: ckponnappa at gmail.com (Sidu Ponnappa) Date: Wed, 13 Apr 2011 15:27:07 +0530 Subject: [rspec-users] Need suggestions on how to test a class In-Reply-To: <824FB611-E7B5-46A2-88E1-0F1BF9923988@nofeed.org> References: <824FB611-E7B5-46A2-88E1-0F1BF9923988@nofeed.org> Message-ID: Hi Nicholas, You have little choice but to mock external dependencies like S3 and the file system in order to be able to do TDD. The problem is that, as Matt said, if it's a mission critical feature you'll want to create infrastructure to run tests against a real environment (even if it's just a smoke suite that's separate from the unit tests). Take a look at https://github.com/thoughtworks/cruisecontrol.rb/blob/master/test/file_sandbox.rb which deals with this kind of issue in CC.rb for a (what I consider) a rather nice way of dealing with this. Best, Sidu. http://c42.in http://about.me/ponnappa On 13 April 2011 07:18, Nicholas Wieland wrote: > Hi *, the class I need to test is: > > https://gist.github.com/49ef28014bb648ffa63e > > I know my question is very generic, but I honestly fail to see how to test something that is so strictly procedural and so dependent to the platform/libraries. > Should I mock/stub filesystem, services and pretty much everything that is in there and test how it responds to different inputs, or adopt an "integration style" ? > How would you proceed in this case ? (you can refer to RSpec book and point to parts that are relevant). > > ?ngw > > -- > [ 926381, 23200231779, 1299022, 1045307475 ].collect { |a| a.to_s( 36 ) }.join( " " ) > Nicholas Wieland (ngw) > ngw at nofeed.org > http://www.nofeed.org > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mmazur at gmail.com Wed Apr 13 07:19:46 2011 From: mmazur at gmail.com (Mike Mazur) Date: Wed, 13 Apr 2011 19:19:46 +0800 Subject: [rspec-users] Skipping callbacks that aren't necessary for what i'm testing In-Reply-To: References: Message-ID: Hi, On Wed, Apr 13, 2011 at 16:56, Paul S. wrote: > I have an Address model that has a before_validation callback that goes > off and geocodes the address. > > I'm concerned that for all the tests in my Address model I'm going to be > triggering that callback, even when it's not what I'm testing. > > Is there a nice way to stub the callback by default for all tests on a > model and then re-enable it for specific tests that are testing the > geocoding functionality. If you're using the RSpec Mocks framework, you can stub the specific before_validation method in spec_helper.rb, then use unstub![1] in a before for those specs where you need it. I'm not sure whether an unstub equivalent is available in other mocking frameworks. HTH, Mike [1] http://rubydoc.info/gems/rspec-mocks/2.5.0/RSpec/Mocks/Methods:unstub From humanoriented at gmail.com Sun Apr 10 19:45:55 2011 From: humanoriented at gmail.com (ybakos) Date: Sun, 10 Apr 2011 16:45:55 -0700 (PDT) Subject: [rspec-users] rspec _and_ Rails test::unit tests Message-ID: <1b3898f4-87a4-46d8-acc7-0d304398e496@l18g2000yql.googlegroups.com> There's so much different chatter about this issue and I was wondering if any of you could spare the time to assist. Start a new Rails3 project. Initialize rspec for the project. Now run autotest. Ok, great, "loading autotest/rails_rspec2" Now run autotest -s rails. Ok, great, the Rails test suite in test/ runs. How the heck do I get both to run by just running "autotest" ? I've tried adding mappings and also Autotest.add_discovery calls in .autotest, in autotest/discover.rb, etc. and always get screwed up results. Thanks for your time. Again, all that should need to be done is: - rails new someapp && cd someapp - rails generate rspec:install - (magic configuration here) - autotest I'd like to be able to add the magic configuration, run autotest, and see that both spec/* and test/* run. From freelancersbrasil at gmail.com Wed Apr 13 12:00:26 2011 From: freelancersbrasil at gmail.com (Lucas Renan) Date: Wed, 13 Apr 2011 09:00:26 -0700 (PDT) Subject: [rspec-users] TypeError: can't convert RSpec::Mocks::Mock to Hash In-Reply-To: <4b042b2f-b04e-481c-bca8-2c551eafd0a9@y36g2000pra.googlegroups.com> References: <4b042b2f-b04e-481c-bca8-2c551eafd0a9@y36g2000pra.googlegroups.com> Message-ID: What's orm you are using? activerecord? On 15 fev, 14:25, Karl wrote: > In MoneyOrdersController controller: > > def create > ? @money_order = current_user.money_orders.build(params[:money_order]) > ? if @money_order.save > ? ? flash.now[:msg_ok] = "Added money order for: > #{number_to_currency(@money_order.amount)}" > ? end > ? respond_with(@money_order) > end > > In MoneyOrdersController spec: > > describe "POST create" do > ? describe "with valid params" do > ? ? it "assigns a newly created money_order as @money_order" do > ? ? ? MoneyOrder.stub(:new).with({'these' => 'params'}) > { mock_money_order(:save => true) } > ? ? ? post :create, :money_order => {'these' => 'params'} > ? ? ? assigns(:money_order).should be(mock_money_order) > ? ? end > end > > It always throws this error: > > Failure/Error: post :create, :money_order => {'these' => 'params'} > TypeError: > ? ?can't convert RSpec::Mocks::Mock to Hash > (RSpec::Mocks::Mock#to_hashgives RSpec::Mocks::Mock) > > I'm sure the reason is simple, why I am getting this TypeError? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jeffdeville at gmail.com Thu Apr 14 01:51:03 2011 From: jeffdeville at gmail.com (JDeville) Date: Wed, 13 Apr 2011 22:51:03 -0700 (PDT) Subject: [rspec-users] Rails 3 route path helpers no longer accessible from /specs/requests/ Message-ID: <4852801.817.1302760263703.JavaMail.geo-discussion-forums@yqjl1> I just did a bundle update, and my integration specs stopped working. I was on Rails 3.0.5, and am now on 3.0.6. Any suggestions on how to get access to those routes back? In case the subject wasn't clear, this is what is no longer working: get sessions_path sessions_path (and every other path gen'd from my routes), have become undefined. I've read through the rspec-rails gem a bit, and have confirmed that my request specs are still including the RSpec::Rails::RequestExampleGroup module, which is about all I can think to check. Any suggestions? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dblockdotorg at gmail.com Fri Apr 15 12:02:47 2011 From: dblockdotorg at gmail.com (dblock) Date: Fri, 15 Apr 2011 09:02:47 -0700 (PDT) Subject: [rspec-users] warning: toplevel constant XYZ referenced Admin:XYZ Message-ID: I have an odd problem. I got controllers in a namespace and controllers outside of the namespace. For example, I have a PagesController and a Admin::PagesController. When I run rspec from the top, tests pass and I get the following warning: spec/controllers/admin/pages_controller_spec.rb:4: warning: toplevel constant PagesController referenced by Admin::PagesController This makes no sense. I do have a PagesController and an Admin::PagesController and specs for both that are declared properly. I get this for 3 out of about 20 controllers. Any ideas? From dchelimsky at gmail.com Fri Apr 15 17:04:46 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 15 Apr 2011 16:04:46 -0500 Subject: [rspec-users] rspec _and_ Rails test::unit tests In-Reply-To: <1b3898f4-87a4-46d8-acc7-0d304398e496@l18g2000yql.googlegroups.com> References: <1b3898f4-87a4-46d8-acc7-0d304398e496@l18g2000yql.googlegroups.com> Message-ID: On Apr 10, 2011, at 6:45 PM, ybakos wrote: > There's so much different chatter about this issue and I was wondering > if any of you could spare the time to assist. > > Start a new Rails3 project. Initialize rspec for the project. Now run > autotest. Ok, great, "loading autotest/rails_rspec2" > > Now run autotest -s rails. Ok, great, the Rails test suite in test/ > runs. > > How the heck do I get both to run by just running "autotest" ? > > I've tried adding mappings and also Autotest.add_discovery calls > in .autotest, in autotest/discover.rb, etc. and always get screwed up > results. > > Thanks for your time. Again, all that should need to be done is: > > - rails new someapp && cd someapp > - rails generate rspec:install > - (magic configuration here) > - autotest > > I'd like to be able to add the magic configuration, run autotest, and > see that both spec/* and test/* run. AFAIK, it's not supported. Autotest only supports invoking a single subclass of Autotest at a time, and RSpec's is designed to run specs. HTH, David From dchelimsky at gmail.com Fri Apr 15 17:57:27 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 15 Apr 2011 16:57:27 -0500 Subject: [rspec-users] warning: toplevel constant XYZ referenced Admin:XYZ In-Reply-To: References: Message-ID: On Apr 15, 2011, at 11:02 AM, dblock wrote: > I have an odd problem. I got controllers in a namespace and > controllers outside of the namespace. For example, I have a > PagesController and a Admin::PagesController. > > When I run rspec from the top, tests pass and I get the following > warning: > > spec/controllers/admin/pages_controller_spec.rb:4: warning: toplevel > constant PagesController referenced by Admin::PagesController > > This makes no sense. I do have a PagesController and an > Admin::PagesController and specs for both that are declared properly. > > I get this for 3 out of about 20 controllers. > > Any ideas? Can you post the top 4 lines of pages_controller_spec? From mmazur at gmail.com Fri Apr 15 19:46:29 2011 From: mmazur at gmail.com (Mike Mazur) Date: Sat, 16 Apr 2011 07:46:29 +0800 Subject: [rspec-users] warning: toplevel constant XYZ referenced Admin:XYZ In-Reply-To: References: Message-ID: Hi, On Sat, Apr 16, 2011 at 00:02, dblock wrote: > I have an odd problem. I got controllers in a namespace and > controllers outside of the namespace. For example, I have a > PagesController and a Admin::PagesController. > > When I run rspec from the top, tests pass and I get the following > warning: > > spec/controllers/admin/pages_controller_spec.rb:4: warning: toplevel > constant PagesController referenced by Admin::PagesController > > This makes no sense. I do have a PagesController and an > Admin::PagesController and specs for both that are declared properly. I would guess it's Ruby trying to warn you that the use of the constant PagesController in Admin::PagesController references the top-level PagesController, not Admin::PagesController. It can't know which one you mean. To make the warning go away, you can use ::PagesController where you mean the top-level PagesController. HTH, Mike From lbocseg at yahoo.com.br Fri Apr 15 20:35:44 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Fri, 15 Apr 2011 21:35:44 -0300 Subject: [rspec-users] Rails 3 route path helpers no longer accessible from /specs/requests/ In-Reply-To: <4852801.817.1302760263703.JavaMail.geo-discussion-forums@yqjl1> References: <4852801.817.1302760263703.JavaMail.geo-discussion-forums@yqjl1> Message-ID: <4DA8E460.2040701@yahoo.com.br> Em 14-04-2011 02:51, JDeville escreveu: > I just did a bundle update, and my integration specs stopped working. > I was on Rails 3.0.5, and am now on 3.0.6. Any suggestions on how to > get access to those routes back? In case the subject wasn't clear, > this is what is no longer working: > > get sessions_path > > sessions_path (and every other path gen'd from my routes), have become > undefined. I've read through the rspec-rails gem a bit, and have > confirmed that my request specs are still including the > RSpec::Rails::RequestExampleGroup module, which is about all I can > think to check. > > Any suggestions? > > You can try to upgrade just Rails first: >> bundle update rails That way, you can isolate your problem... HTH, Rodrigo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Apr 16 08:26:44 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Sat, 16 Apr 2011 14:26:44 +0200 Subject: [rspec-users] How to use rspec_scaffold generator with latest rspec gem. In-Reply-To: References: <2117e089d59778382e726a792115d13d@ruby-forum.com> Message-ID: <8f1c132c9e6ab5aefae1d9c246b62b26@ruby-forum.com> David Chelimsky wrote in post #986732: > On Mar 10, 2011, at 7:49 AM, Mohnish J. wrote: > >> also. >> Could you please tell me how should I give to accordingly for it to work >> for me using the above RoR configuration. > > rails generate rspec:install > rails generate scaffold > > In Rails 3, once you run the rspec:install generator, the Rails > generators delegate out to rspec-rails to generate the spec files. > > You might also want to check out http://ruby.railstutorial.org/. > > Cheers, > David Hi David, I have posted the same question stackoverflow.com( http://stackoverflow.com/questions/5260173/how-to-use-rspec-scaffold-generator-with-latest-rspec-gem ). It being posted around the same time that you had given your solution on this forum. Kindly post your answer in stackoverflow.com so that you could get your rightful credit for the answer to the question. I shall accept the answer once you have posted the same. Thanks again for your support. -- Posted via http://www.ruby-forum.com/. From lbocseg at yahoo.com.br Sat Apr 16 10:05:33 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Sat, 16 Apr 2011 11:05:33 -0300 Subject: [rspec-users] rspec execution speed footprint Message-ID: <4DA9A22D.20508@yahoo.com.br> Hi, I would like to figure out if it is possible for me to run my specs faster than it currently is. Before start optimizing my specs for speed, I tried to figure out what was the speed footprint of Rspec boot process itself for starting executing my specs. So I took my simplest spec with a single fast example: time bundle exec rspec ./spec/models/decision_spec.rb . Finished in 0.00794 seconds 1 example, 0 failures real 0m19.202s user 0m17.649s sys 0m1.300s All my specs run in about 54s. That means Rspec itself is responsible for about a third of the total time... Well, not exactly: time rails runner "puts 1" 1 real 0m13.918s user 0m12.805s sys 0m0.940s This means I could not get more than 5s in the best case from trying to optimize Rspec itself... Simple does not worth... Rails (3.0.7rc2) itself takes about 4s to boot up an empty application: rails new empty cd empty time rails runner "puts 1" 1 real 0m4.000s user 0m3.440s sys 0m0.492s That means I can try to optimize my application boot time first, which can reduce my specs running time up to 10 seconds... Then, I tried to give autotest a try in the hope it would skip the boot process for the next spec executions. But it didn't. It is not that smart. It just monitor file changes and call rspec on the possible affected specs... So, I would like to know if some of you know a good Ruby profiler that could show me how much time each method takes on a tree view... For instance, I enjoy very much the Javascript profiler that comes with Google Chrome Developer Tool. I tried adding "-r profile" to .rspec, but the output is not that useful in my opinion... And the "--profile" Rspec option will only show me the to 10 slowest examples, but not what is the bottleneck, so I need to do that manually... Also, it won't help me getting my Rails application to boot faster... Does anyone here knows of a good tool for profiling or finding bottlenecks on a Rails or Ruby application? Sorry if I took too long on my question... Cheers, Rodrigo. From dchelimsky at gmail.com Sat Apr 16 11:57:12 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 16 Apr 2011 10:57:12 -0500 Subject: [rspec-users] rspec execution speed footprint In-Reply-To: <4DA9A22D.20508@yahoo.com.br> References: <4DA9A22D.20508@yahoo.com.br> Message-ID: On Apr 16, 2011, at 9:05 AM, Rodrigo Rosenfeld Rosas wrote: > Hi, I would like to figure out if it is possible for me to run my specs faster than it currently is. > > Before start optimizing my specs for speed, I tried to figure out what was the speed footprint of Rspec boot process itself for starting executing my specs. So I took my simplest spec with a single fast example: > > time bundle exec rspec ./spec/models/decision_spec.rb > . > > Finished in 0.00794 seconds > 1 example, 0 failures > > real 0m19.202s > user 0m17.649s > sys 0m1.300s > > All my specs run in about 54s. That means Rspec itself is responsible for about a third of the total time Not really. If you want a sense of what RSpec is taking, do something like this: $ echo '1000.times do |n| describe n do it "is #{n}" do n.should eq(n) end end end' > example.rb $ time rspec example.rb ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Finished in 0.51265 seconds 1000 examples, 0 failures real 0m1.063s user 0m0.877s sys 0m0.131s So here, it took just over 1/2 a second to run 1000 examples and output a dot for each. This is admittedly slower than MiniTest/Spec $ echo 'require "minitest/autorun" > require "minitest/spec" > > 1000.times do |n| > describe "Spec#{n}" do > it "is #{n}" do > assert_equal(n,n) > end > end > end > ' > example.rb [david: rspec-core (master)]$ time ruby example.rb Loaded suite example Started ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Finished in 0.242546 seconds. 1000 tests, 1000 assertions, 0 failures, 0 errors, 0 skips Test run options: --seed 24068 real 0m0.571s user 0m0.537s sys 0m0.029s But if you have a couple of hundred examples that are taking 54 seconds, it is not because of RSpec. > ... Well, not exactly: > > time rails runner "puts 1" > 1 > > real 0m13.918s > user 0m12.805s > sys 0m0.940s > > This means I could not get more than 5s in the best case from trying to optimize Rspec itself... Simple does not worth... > > Rails (3.0.7rc2) itself takes about 4s to boot up an empty application: > > rails new empty > cd empty > time rails runner "puts 1" > 1 > > real 0m4.000s > user 0m3.440s > sys 0m0.492s > > That means I can try to optimize my application boot time first, which can reduce my specs running time up to 10 seconds... > > Then, I tried to give autotest a try in the hope it would skip the boot process for the next spec executions. But it didn't. It is not that smart. It just monitor file changes and call rspec on the possible affected specs... Check out spork. It loads the env once, and runs the suite in a fork each time you run it. > So, I would like to know if some of you know a good Ruby profiler that could show me how much time each method takes on a tree view... For instance, I enjoy very much the Javascript profiler that comes with Google Chrome Developer Tool. > > I tried adding "-r profile" to .rspec, but the output is not that useful in my opinion... And the "--profile" Rspec option will only show me the to 10 slowest examples, but not what is the bottleneck, so I need to do that manually... Also, it won't help me getting my Rails application to boot faster... > > Does anyone here knows of a good tool for profiling or finding bottlenecks on a Rails or Ruby application? > > Sorry if I took too long on my question... > > Cheers, Rodrigo. There is ruby-prof, and Rubnius has some profiling tools that look very interesting. HTH, David From jarmo.p at gmail.com Sat Apr 16 17:56:05 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Sat, 16 Apr 2011 14:56:05 -0700 (PDT) Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in Message-ID: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> Hello! I've just added a new cool matcher #in into my framework WatirSplash and thought that this could be integrated into RSpec directly actually if there's any interest. WatirSplash uses Watir (or Watir-like) frameworks for testing web pages via browser. If you're not familiar with it then here is a short example how you had to test ajax-heavy application before: browser.link(:id => "someid").click # let's wait up to 5 seconds for div to become visible browser.wait_until(5) {browser.div(:id => "otherid").visible?} It was quite cumbersome and i thought about adding and #in matcher to all matchers so i can do something like this instead: # clicking the link changed div's text from "before" to "after" in a maximum of 2 seconds expect { link.click }.to change {div.text}.from("before").to("after").in(2) # clicking link makes div as present in a maximum of 2 seconds link.click div.should be_present.in(2) # clicking link makes div as visible in a maximum of 2 seconds expect { link.click }.to make {div.visible?}.in(2) # use ActiveSupport for adding more meaning to numbers require "active_support" div.should exist.in(2.minutes) What do you guys think? Should i add that also into rspec-expectations to make spec-ing easier where timing is involved? :) Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net From lbocseg at yahoo.com.br Sat Apr 16 20:43:23 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Sat, 16 Apr 2011 21:43:23 -0300 Subject: [rspec-users] rspec execution speed footprint In-Reply-To: References: <4DA9A22D.20508@yahoo.com.br> Message-ID: <4DAA37AB.5050303@yahoo.com.br> Em 16-04-2011 12:57, David Chelimsky escreveu: > On Apr 16, 2011, at 9:05 AM, Rodrigo Rosenfeld Rosas wrote: > >> Hi, I would like to figure out if it is possible for me to run my specs faster than it currently is. >> >> Before start optimizing my specs for speed, I tried to figure out what was the speed footprint of Rspec boot process itself for starting executing my specs. So I took my simplest spec with a single fast example: >> >> time bundle exec rspec ./spec/models/decision_spec.rb >> . >> >> Finished in 0.00794 seconds >> 1 example, 0 failures >> >> real 0m19.202s >> user 0m17.649s >> sys 0m1.300s >> >> All my specs run in about 54s. That means Rspec itself is responsible for about a third of the total time > Not really. Yes, I know. That is why I continued in the e-mail: > ... Well, not exactly: > > time rails runner "puts 1" > 1 > > real 0m13.918s > user 0m12.805s > sys 0m0.940s > > This means I could not get more than 5s in the best case from trying to optimize Rspec itself... Simple does not worth... I didn't say it was responsible for the 5s, but that was just some theorical limit considering the rest of the analysis... > If you want a sense of what RSpec is taking, do something like this: > > $ echo '1000.times do |n| > describe n do > it "is #{n}" do > n.should eq(n) > end > end > end'> example.rb > $ time rspec example.rb > .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. > .......... > > Finished in 0.51265 seconds > 1000 examples, 0 failures > > real 0m1.063s > user 0m0.877s > sys 0m0.131s > > So here, it took just over 1/2 a second to run 1000 examples and output a dot for each. Yes, but this is a pure Ruby and Rspec example. It doesn't mean rspec-rails will have the same speed footprint... But anyway, I know that I should not be concerned about Rspec footprint in my case for now. For sure, I should start optimizing my application boot footprint and then my specs itself... > This is admittedly slower than MiniTest/Spec > > $ echo 'require "minitest/autorun" >> require "minitest/spec" >> >> 1000.times do |n| >> describe "Spec#{n}" do >> it "is #{n}" do >> assert_equal(n,n) >> end >> end >> end >> '> example.rb > [david: rspec-core (master)]$ time ruby example.rb > Loaded suite example > Started > .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. > .......... > Finished in 0.242546 seconds. > > 1000 tests, 1000 assertions, 0 failures, 0 errors, 0 skips > > Test run options: --seed 24068 > > real 0m0.571s > user 0m0.537s > sys 0m0.029s > > But if you have a couple of hundred examples that are taking 54 seconds, it is not because of RSpec. I would be glad if there were a couple of hundred example! :D Actually, there are only 54 examples (what a coincidence, right? ;) ). The most time consuming example is an integration spec that takes about 2 seconds. All specs take about 20 seconds according to Rspec. The remaining 34 seconds are related to Rails boot, Bundler loading, Rake loading and Rspec. I forgot to show this other result (I thought I did, but I just realized that I only sent the time for a new Rails application). This one is used by the real application: time rails runner 'puts 1' 1 real 0m14.855s user 0m12.973s sys 0m0.968s For bundler: time bundle exec ruby -e 'puts 1' 1 real 0m2.268s user 0m1.868s sys 0m0.328s for rake: time rake -T real 0m8.418s user 0m6.768s sys 0m0.740s That means, I can speed up the boot process up to 10s. Also it means that Rspec really doesn't add much (if something), since 54 (total time) - 20 (specs time) =~ 15 (Rails boot) + 2 (Bundler time) + 8 (rake time) >> Rails (3.0.7rc2) itself takes about 4s to boot up an empty application: >> >> rails new empty >> cd empty >> time rails runner "puts 1" >> 1 >> >> real 0m4.000s >> user 0m3.440s >> sys 0m0.492s >> >> That means I can try to optimize my application boot time first, which can reduce my specs running time up to 10 seconds... >> >> Then, I tried to give autotest a try in the hope it would skip the boot process for the next spec executions. But it didn't. It is not that smart. It just monitor file changes and call rspec on the possible affected specs... > Check out spork. It loads the env once, and runs the suite in a fork each time you run it. Yes, that helped a lot! But not that much if I use "rake spec". It takes about 40s (instead of 54s), while the alternative "bundle exec rspec ./path/to/specs.rb" takes 25s (why not 22s?). Thank you for the hint! >> So, I would like to know if some of you know a good Ruby profiler that could show me how much time each method takes on a tree view... For instance, I enjoy very much the Javascript profiler that comes with Google Chrome Developer Tool. >> >> I tried adding "-r profile" to .rspec, but the output is not that useful in my opinion... And the "--profile" Rspec option will only show me the to 10 slowest examples, but not what is the bottleneck, so I need to do that manually... Also, it won't help me getting my Rails application to boot faster... >> >> Does anyone here knows of a good tool for profiling or finding bottlenecks on a Rails or Ruby application? >> >> Sorry if I took too long on my question... >> >> Cheers, Rodrigo. > There is ruby-prof, and Rubnius has some profiling tools that look very interesting. It seems the Graphic profile may help. I'll take a closer look at it. I've seen a presentation about Rubinius profiling tools in last RubyConf Brazil if I remember correctly. I'll take another look at it if ruby-prof graphic profile doesn't help me... Thanks! Best regards, Rodrigo. From dchelimsky at gmail.com Sun Apr 17 11:01:34 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 17 Apr 2011 10:01:34 -0500 Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> Message-ID: On Apr 16, 2011, at 4:56 PM, Jarmo Pertman wrote: > Hello! > > I've just added a new cool matcher #in into my framework WatirSplash > and thought that this could be integrated into RSpec directly actually > if there's any interest. > > WatirSplash uses Watir (or Watir-like) frameworks for testing web > pages via browser. If you're not familiar with it then here is a short > example how you had to test ajax-heavy application before: > > browser.link(:id => "someid").click > # let's wait up to 5 seconds for div to become visible > browser.wait_until(5) {browser.div(:id => "otherid").visible?} > > It was quite cumbersome and i thought about adding and #in matcher to > all matchers so i can do something like this instead: > # clicking the link changed div's text from "before" to "after" in a > maximum of 2 seconds > expect { > link.click > }.to change {div.text}.from("before").to("after").in(2) > > # clicking link makes div as present in a maximum of 2 seconds > link.click > div.should be_present.in(2) > > # clicking link makes div as visible in a maximum of 2 seconds > expect { > link.click > }.to make {div.visible?}.in(2) > > # use ActiveSupport for adding more meaning to numbers > require "active_support" > div.should exist.in(2.minutes) > > What do you guys think? Should i add that also into rspec-expectations > to make spec-ing easier where timing is involved? :) > > Jarmo Pertman I _think_ I like the idea of a timing constraint, but #in seems too general to me. In fact, ActiveSupport is adding an #in? predicate [1] to Object that lets you specify that an object is in a collection: 4.in?([2,3,4]) Also, I'm not sure if I'd want this to be a matcher extension or something built into rspec core. I'm open to ideas though. Anybody else? [1] https://github.com/rails/rails/pull/258 From jko170 at gmail.com Sun Apr 17 11:58:46 2011 From: jko170 at gmail.com (Justin Ko) Date: Sun, 17 Apr 2011 10:58:46 -0500 Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> Message-ID: On Sun, Apr 17, 2011 at 10:01 AM, David Chelimsky wrote: > On Apr 16, 2011, at 4:56 PM, Jarmo Pertman wrote: > > > Hello! > > > > I've just added a new cool matcher #in into my framework WatirSplash > > and thought that this could be integrated into RSpec directly actually > > if there's any interest. > > > > WatirSplash uses Watir (or Watir-like) frameworks for testing web > > pages via browser. If you're not familiar with it then here is a short > > example how you had to test ajax-heavy application before: > > > > browser.link(:id => "someid").click > > # let's wait up to 5 seconds for div to become visible > > browser.wait_until(5) {browser.div(:id => "otherid").visible?} > > > > It was quite cumbersome and i thought about adding and #in matcher to > > all matchers so i can do something like this instead: > > # clicking the link changed div's text from "before" to "after" in a > > maximum of 2 seconds > > expect { > > link.click > > }.to change {div.text}.from("before").to("after").in(2) > > > > # clicking link makes div as present in a maximum of 2 seconds > > link.click > > div.should be_present.in(2) > > > > # clicking link makes div as visible in a maximum of 2 seconds > > expect { > > link.click > > }.to make {div.visible?}.in(2) > > > > # use ActiveSupport for adding more meaning to numbers > > require "active_support" > > div.should exist.in(2.minutes) > > > > What do you guys think? Should i add that also into rspec-expectations > > to make spec-ing easier where timing is involved? :) > > > > Jarmo Pertman > > > I _think_ I like the idea of a timing constraint, but #in seems too general > to me. In fact, ActiveSupport is adding an #in? predicate [1] to Object that > lets you specify that an object is in a collection: > > 4.in?([2,3,4]) > > Also, I'm not sure if I'd want this to be a matcher extension or something > built into rspec core. I'm open to ideas though. Anybody else? > > [1] https://github.com/rails/rails/pull/258 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Definitely matcher extension. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dblockdotorg at gmail.com Sun Apr 17 14:18:43 2011 From: dblockdotorg at gmail.com (dblock) Date: Sun, 17 Apr 2011 11:18:43 -0700 (PDT) Subject: [rspec-users] warning: toplevel constant XYZ referenced Admin:XYZ In-Reply-To: References: Message-ID: <29410cb3-3a5f-4cf7-99e6-c1a9270b2d1c@t16g2000vbi.googlegroups.com> None of this makes any sense :) dblock at dblock-magenta:~/source/Gravity/dblock$ find . -name "*.rb" | xargs grep PagesController ./spec/controllers/admin/pages_controller_spec.rb:describe Admin::PagesController do ./spec/controllers/pages_controller_spec.rb:describe PagesController do ./app/controllers/admin/pages_controller.rb:class Admin::PagesController < AdminController ./app/controllers/pages_controller.rb:class PagesController < ApplicationController Now, lets compare with a controller that doesn't yield the same issue. dblock at dblock-magenta:~/source/Gravity/dblock$ find . -name "*.rb" | xargs grep ArtworksController ./spec/controllers/admin/artworks_controller_spec.rb:describe Admin::ArtworksController do ./spec/controllers/artworks_controller_spec.rb:describe ArtworksController do ./app/controllers/admin/artworks_controller.rb:class Admin::ArtworksController < AdminController ./app/controllers/artworks_controller.rb:class ArtworksController < ApplicationController These are identical, unless I'm blind :) The only thing different is timestamps - it looks like in the case where things work the Admin spec is loaded after the non-admin spec. From dblockdotorg at gmail.com Sun Apr 17 14:24:26 2011 From: dblockdotorg at gmail.com (dblock) Date: Sun, 17 Apr 2011 11:24:26 -0700 (PDT) Subject: [rspec-users] warning: toplevel constant XYZ referenced Admin:XYZ In-Reply-To: References: Message-ID: > To make the warning go away, you can use ::PagesController where you > mean the top-level PagesController. I tried saying ::PagesController in the 2 places it's declared (the controller itself and the spec), no difference. From dblockdotorg at gmail.com Sun Apr 17 14:44:21 2011 From: dblockdotorg at gmail.com (dblock) Date: Sun, 17 Apr 2011 11:44:21 -0700 (PDT) Subject: [rspec-users] warning: toplevel constant XYZ referenced Admin:XYZ In-Reply-To: References: Message-ID: Top 4 lines of pages_controller_spec. require 'spec_helper' require 'spec_controllers_helper' describe PagesController do before(:each) do controller.stub!(:app_initialization).and_return(true) end Top 4 lines of admin/pages_controller_spec. require 'spec_helper' require 'spec_controllers_helper' describe Admin::PagesController do include Devise::TestHelpers before(:each) do controller.stub!(:app_initialization).and_return(true) log_in_test_user(Admin) end (changing PagesController to ::PagesController does nothing) From dchelimsky at gmail.com Mon Apr 18 02:02:56 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Apr 2011 01:02:56 -0500 Subject: [rspec-users] rspec-2.6.0.rc2 is released! Message-ID: We're releasing rspec-2.6.0.rc2 as a release candidate as there are some internal changes that we'd like to see put through their paces before doing a final release. Note that the changes I speak of are internal. There are no new deprecations in this release, nor any backward-incompatible changes. There are, however, some new features that we're really excited about. Please do check it out and please do report any issues to the appropriate github issue tracker: * [rspec-core](http://github.com/rspec/rspec-core/issues) * [rspec-expectations](http://github.com/rspec/rspec-expectations/issues) * [rspec-mocks](http://github.com/rspec/rspec-mocks/issues) * [rspec-rails](http://github.com/rspec/rspec-rails/issues) ### rspec-core-2.6.0.rc2 [full changelog](http://github.com/rspec/rspec-core/compare/v2.5.1...v2.6.1.rc2) * Enhancements * `shared_context` (Damian Nurzynski) * extend groups matching specific metadata with: * method definitions * subject declarations * let/let! declarations * etc (anything you can do in a group) * `its([:key])` works for any subject with #[]. (Peter Jaros) * `treat_symbols_as_metadata_keys_with_true_values` (Myron Marston) * Print a deprecation warning when you configure RSpec after defining an example. All configuration should happen before any examples are defined. (Myron Marston) * Pass the exit status of a DRb run to the invoking process. This causes specs run via DRb to not just return true or false. (Ilkka Laukkanen) * Refactoring of ConfigurationOptions#parse_options (Rodrigo Rosenfeld Rosas) * Report excluded filters in runner output (tip from andyl) * Bug fixes * Don't stumble over an exception without a message (Hans Hasselberg) * Remove non-ascii characters from comments that were choking rcov (Geoffrey Byers) * Fixed backtrace so it doesn't include lines from before the autorun at_exit hook (Myron Marston) * Include RSpec::Matchers when first example group is defined, rather than just before running the examples. This works around an obscure bug in ruby 1.9 that can cause infinite recursion. (Myron Marston) * Don't send example_group_[started|finished] to formatters for empty groups. * Get specs passing on jruby (Sidu Ponnappa) * Fix bug where mixing nested groups and outer-level examples gave unpredictable :line_number behavior (Artur Ma?ecki) * Regexp.escape the argument to --example (tip from Elliot Winkler) * Correctly pass/fail pending block with message expectations ### rspec-expectations-2.6.0.rc2 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.5.0...v2.6.1.rc2) * Enhancments * `change` matcher accepts Regexps (Robert Davis) * better descriptions for have_xxx matchers (Magnus Bergmark) * Bug fixes * Removed non-ascii characters that were choking rcov (Geoffrey Byers) * change matcher dups arrays and hashes so their before/after states can be compared correctly. * Fix the order of inclusion of RSpec::Matchers in Test::Unit::TestCase and MiniTest::Unit::TestCase to prevent a SystemStackError (Myron Marston) ### rspec-mocks-2.6.0.rc2 [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.5.0...v2.6.1.rc2) * Enhancements * Add support for any_instance.stub and any_instance.should_receive (Sidu Ponnappa and Andy Lindeman) * Bug fixes * fix bug in which multiple chains with shared messages ending in hashes failed to return the correct value ### rspec-rails-2.6.0.rc2 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.5.0...v2.6.1.rc2) * Enhancments * rails 3 shortcuts for routing specs (Joe Fiorini) * support nested resources in generators (Tim McEwan) * require 'rspec/rails/mocks' to use `mock_model` without requiring the whole rails framework * Bug fixes * fix typo in "rake spec:statsetup" (Curtis Schofield) * expose named routes in anonymous controller specs (Andy Lindeman) * error when generating namespaced scaffold resources (Andy Lindeman) From jarmo.p at gmail.com Mon Apr 18 08:49:31 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Mon, 18 Apr 2011 05:49:31 -0700 (PDT) Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> Message-ID: What does the "matcher extension" mean? E.g. some separate gem, which adds that method? Didn't know that ActiveSupport adds #in? to Object, but it doesn't conflict with matcher's #in anyway. Jarmo On Apr 17, 6:58?pm, Justin Ko wrote: > On Sun, Apr 17, 2011 at 10:01 AM, David Chelimsky wrote: > > > > > > > > > > > On Apr 16, 2011, at 4:56 PM, Jarmo Pertman wrote: > > > > Hello! > > > > I've just added a new cool matcher #in into my framework WatirSplash > > > and thought that this could be integrated into RSpec directly actually > > > if there's any interest. > > > > WatirSplash uses Watir (or Watir-like) frameworks for testing web > > > pages via browser. If you're not familiar with it then here is a short > > > example how you had to test ajax-heavy application before: > > > > ?browser.link(:id => "someid").click > > > ?# let's wait up to 5 seconds for div to become visible > > > ?browser.wait_until(5) {browser.div(:id => "otherid").visible?} > > > > It was quite cumbersome and i thought about adding and #in matcher to > > > all matchers so i can do something like this instead: > > > ?# clicking the link changed div's text from "before" to "after" in a > > > maximum of 2 seconds > > > ?expect { > > > ? ? ?link.click > > > ?}.to change {div.text}.from("before").to("after").in(2) > > > > ?# clicking link makes div as present in a maximum of 2 seconds > > > ?link.click > > > ?div.should be_present.in(2) > > > > ?# clicking link makes div as visible in a maximum of 2 seconds > > > ?expect { > > > ? ? ?link.click > > > ?}.to make {div.visible?}.in(2) > > > > ?# use ActiveSupport for adding more meaning to numbers > > > ?require "active_support" > > > ?div.should exist.in(2.minutes) > > > > What do you guys think? Should i add that also into rspec-expectations > > > to make spec-ing easier where timing is involved? :) > > > > Jarmo Pertman > > > I _think_ I like the idea of a timing constraint, but #in seems too general > > to me. In fact, ActiveSupport is adding an #in? predicate [1] to Object that > > lets you specify that an object is in a collection: > > > ?4.in?([2,3,4]) > > > Also, I'm not sure if I'd want this to be a matcher extension or something > > built into rspec core. I'm open to ideas though. Anybody else? > > > [1]https://github.com/rails/rails/pull/258 > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Definitely matcher extension. > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Mon Apr 18 09:05:59 2011 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 18 Apr 2011 14:05:59 +0100 Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> Message-ID: <29508078-B839-492A-B9E1-8275F124C20C@mattwynne.net> On 18 Apr 2011, at 13:49, Jarmo Pertman wrote: > What does the "matcher extension" mean? E.g. some separate gem, which > adds that method? > > Didn't know that ActiveSupport adds #in? to Object, but it doesn't > conflict with matcher's #in anyway. I think the point is that it clashes conceptually, since they give quite different meanings to the same word. Maybe #within_duration would be a more unambiguous name for the matcher method? > > Jarmo > > On Apr 17, 6:58 pm, Justin Ko wrote: >> On Sun, Apr 17, 2011 at 10:01 AM, David Chelimsky wrote: >> >> >> >> >> >> >> >> >> >>> On Apr 16, 2011, at 4:56 PM, Jarmo Pertman wrote: >> >>>> Hello! >> >>>> I've just added a new cool matcher #in into my framework WatirSplash >>>> and thought that this could be integrated into RSpec directly actually >>>> if there's any interest. >> >>>> WatirSplash uses Watir (or Watir-like) frameworks for testing web >>>> pages via browser. If you're not familiar with it then here is a short >>>> example how you had to test ajax-heavy application before: >> >>>> browser.link(:id => "someid").click >>>> # let's wait up to 5 seconds for div to become visible >>>> browser.wait_until(5) {browser.div(:id => "otherid").visible?} >> >>>> It was quite cumbersome and i thought about adding and #in matcher to >>>> all matchers so i can do something like this instead: >>>> # clicking the link changed div's text from "before" to "after" in a >>>> maximum of 2 seconds >>>> expect { >>>> link.click >>>> }.to change {div.text}.from("before").to("after").in(2) >> >>>> # clicking link makes div as present in a maximum of 2 seconds >>>> link.click >>>> div.should be_present.in(2) >> >>>> # clicking link makes div as visible in a maximum of 2 seconds >>>> expect { >>>> link.click >>>> }.to make {div.visible?}.in(2) >> >>>> # use ActiveSupport for adding more meaning to numbers >>>> require "active_support" >>>> div.should exist.in(2.minutes) >> >>>> What do you guys think? Should i add that also into rspec-expectations >>>> to make spec-ing easier where timing is involved? :) >> >>>> Jarmo Pertman >> >>> I _think_ I like the idea of a timing constraint, but #in seems too general >>> to me. In fact, ActiveSupport is adding an #in? predicate [1] to Object that >>> lets you specify that an object is in a collection: >> >>> 4.in?([2,3,4]) >> >>> Also, I'm not sure if I'd want this to be a matcher extension or something >>> built into rspec core. I'm open to ideas though. Anybody else? >> >>> [1]https://github.com/rails/rails/pull/258 >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> Definitely matcher extension. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From dchelimsky at gmail.com Mon Apr 18 09:21:00 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Apr 2011 08:21:00 -0500 Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> Message-ID: <6EF5B676-4915-4696-9A1A-32423C8F7873@gmail.com> On Apr 18, 2011, at 7:49 AM, Jarmo Pertman wrote: > On Apr 17, 6:58 pm, Justin Ko wrote: >> On Sun, Apr 17, 2011 at 10:01 AM, David Chelimsky wrote: >>> On Apr 16, 2011, at 4:56 PM, Jarmo Pertman wrote: >> >>>> Hello! >> >>>> I've just added a new cool matcher #in into my framework WatirSplash >>>> and thought that this could be integrated into RSpec directly actually >>>> if there's any interest. >> >>>> WatirSplash uses Watir (or Watir-like) frameworks for testing web >>>> pages via browser. If you're not familiar with it then here is a short >>>> example how you had to test ajax-heavy application before: >> >>>> browser.link(:id => "someid").click >>>> # let's wait up to 5 seconds for div to become visible >>>> browser.wait_until(5) {browser.div(:id => "otherid").visible?} >> >>>> It was quite cumbersome and i thought about adding and #in matcher to >>>> all matchers so i can do something like this instead: >>>> # clicking the link changed div's text from "before" to "after" in a >>>> maximum of 2 seconds >>>> expect { >>>> link.click >>>> }.to change {div.text}.from("before").to("after").in(2) >> >>>> # clicking link makes div as present in a maximum of 2 seconds >>>> link.click >>>> div.should be_present.in(2) >> >>>> # clicking link makes div as visible in a maximum of 2 seconds >>>> expect { >>>> link.click >>>> }.to make {div.visible?}.in(2) >> >>>> # use ActiveSupport for adding more meaning to numbers >>>> require "active_support" >>>> div.should exist.in(2.minutes) >> >>>> What do you guys think? Should i add that also into rspec-expectations >>>> to make spec-ing easier where timing is involved? :) >> >>>> Jarmo Pertman >> >>> I _think_ I like the idea of a timing constraint, but #in seems too general >>> to me. In fact, ActiveSupport is adding an #in? predicate [1] to Object that >>> lets you specify that an object is in a collection: >> >>> 4.in?([2,3,4]) >> >>> Also, I'm not sure if I'd want this to be a matcher extension or something >>> built into rspec core. I'm open to ideas though. Anybody else? >> >>> [1]https://github.com/rails/rails/pull/258 >> >> Definitely matcher extension. > What does the "matcher extension" mean? E.g. some separate gem, which > adds that method? Not in this case. I meant something like this: # new method in rspec-core within(2).seconds do obj.do_expensive_operation end vs this: # new method in rspec-expectations obj.should do_expensive_operation.within(2).seconds > > Didn't know that ActiveSupport adds #in? to Object, Next release will have it - it's already in git. > but it doesn't > conflict with matcher's #in anyway. It conflicts with the name :) It's a problem when we have one name that means completely different things in different contexts. Cheers, David ps - I moved your post to the bottom - please bottom or inline post, especially on threads that are already moving in that direction. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jarmo.p at gmail.com Mon Apr 18 10:39:14 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Mon, 18 Apr 2011 07:39:14 -0700 (PDT) Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: <6EF5B676-4915-4696-9A1A-32423C8F7873@gmail.com> References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> <6EF5B676-4915-4696-9A1A-32423C8F7873@gmail.com> Message-ID: On Apr 18, 4:21?pm, David Chelimsky wrote: > > but it doesn't > > conflict with matcher's #in anyway. > > It conflicts with the name :) It's a problem when we have one name that means completely different things in different contexts. It depends :) That's the point of OOP that the methods with the same name can mean different things if they're in different context (e.g. class). And it's #in vs #in?. Anyway i'm of course open for all suggestions. I'll see how #within_duration feels like in different situations. I like the shortness of #in :) > > Cheers, > David Jarmo From dchelimsky at gmail.com Mon Apr 18 10:59:39 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Apr 2011 09:59:39 -0500 Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> <6EF5B676-4915-4696-9A1A-32423C8F7873@gmail.com> Message-ID: <66AB81E7-E0F1-4971-9F62-1FEC7F4DCAC6@gmail.com> On Apr 18, 2011, at 9:39 AM, Jarmo Pertman wrote: > On Apr 18, 4:21 pm, David Chelimsky wrote: >>> but it doesn't >>> conflict with matcher's #in anyway. >> >> It conflicts with the name :) It's a problem when we have one name that means completely different things in different contexts. > > It depends :) That's the point of OOP that the methods with the same > name can mean different things if they're in different context (e.g. > class). Disagree 100%. The point of polymorphism is that a client can talk to different objects in the same way and expect the same range of results, whereas the actual implementation can differ from object to object. That has nothing to do with the idea that #in in one context means "I am in this array" and in another context means "I'd better finish within this time." These are completely different concepts at an abstract level. > And it's #in vs #in?. Anyway i'm of course open for all > suggestions. It would still confuse people. > I'll see how #within_duration feels like in different situations. I > like the shortness of #in :) What do you think of within(n).seconds { ... }? David From jarmo.p at gmail.com Tue Apr 19 04:00:29 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Tue, 19 Apr 2011 01:00:29 -0700 (PDT) Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: <66AB81E7-E0F1-4971-9F62-1FEC7F4DCAC6@gmail.com> References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> <6EF5B676-4915-4696-9A1A-32423C8F7873@gmail.com> <66AB81E7-E0F1-4971-9F62-1FEC7F4DCAC6@gmail.com> Message-ID: <415d3933-2226-4539-ada1-82df4a879579@2g2000vbl.googlegroups.com> On Apr 18, 5:59?pm, David Chelimsky wrote: > What do you think of within(n).seconds { ... }? I'm not sure i understand it fully taking into account the examples above. Let me try to write them below: expect { link.click }.to change {div.text}.from("before").to("after").within(2).seconds link.click div.should be_present.within(2).seconds expect { link.click }.to make {div.visible?}.within(2).seconds And what ought to be the syntactic sugar methods for timeframes: #seconds, #minutes, #hours? That syntax doesn't sound too bad, but i see that you wanted to do it slightly differently by having a block for within(2).seconds... I think that this removes some of the usages for currently existing matchers as i've shown above. WDYT? Jarmo From dchelimsky at gmail.com Tue Apr 19 09:08:01 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Apr 2011 08:08:01 -0500 Subject: [rspec-users] added new cool matcher into my framework WatirSplash - #in In-Reply-To: <415d3933-2226-4539-ada1-82df4a879579@2g2000vbl.googlegroups.com> References: <9531a329-40a8-4010-bf34-0639ed8de999@a26g2000vbo.googlegroups.com> <6EF5B676-4915-4696-9A1A-32423C8F7873@gmail.com> <66AB81E7-E0F1-4971-9F62-1FEC7F4DCAC6@gmail.com> <415d3933-2226-4539-ada1-82df4a879579@2g2000vbl.googlegroups.com> Message-ID: On Apr 19, 2011, at 3:00 AM, Jarmo Pertman wrote: > On Apr 18, 5:59 pm, David Chelimsky wrote: >> What do you think of within(n).seconds { ... }? > > I'm not sure i understand it fully taking into account the examples > above. Let me try to write them below: > expect { > link.click > }.to change {div.text}.from("before").to("after").within(2).seconds OK - I think I understand this better from this example. The idea here is that the matcher should keep asking if div.text == "after" until it returns true or 2 seconds have passed, whichever comes first, after which it fails. Correct? If so, then this is different from what I was envisioning with "within(2).seconds { ... }" I'm resistant to adding this because it opens up a lot of complications (like how to handle should_not, for one), so I'd prefer to see some experience with it first. Have you looked at writing an extension gem that adds this behavior? I think that would be a great way to go with this, because users could just add a gem dependency and have access to it, and if it became widely used we could always talk about merging it later. WDYT? David From gregorio.kusowski at gmail.com Tue Apr 19 13:44:27 2011 From: gregorio.kusowski at gmail.com (=?ISO-8859-1?Q?Greg=F3rio_Kusowski?=) Date: Tue, 19 Apr 2011 14:44:27 -0300 Subject: [rspec-users] samples_table Message-ID: Hey guys, I'm currently working on a project, that we use rspec. We don't like cucumber too much, because it seems too "verbose", but we like a lot the cucumber's table, that we can use to specify some scenarios. In order to use this feature, but withou using cucumber, or writing another files, I've wrote this simple gem, that gives me the possibility to create a table in my ruby code. https://github.com/gregoriokusowski/samples_table It is working right now, but I think there is a lot of features and cool stuff I can add to it. if you guys don't mind, I would appreciate any suggestion, question, etc. Thanks Greg?rio Chalinski Kusowski From lists at ruby-forum.com Tue Apr 19 14:24:03 2011 From: lists at ruby-forum.com (Josh N.) Date: Tue, 19 Apr 2011 20:24:03 +0200 Subject: [rspec-users] Faking Files, Data, Git interractions with mocks/stubs/fixtures Message-ID: <56c5ad56f04bbef1e93a769e2270762c@ruby-forum.com> I'm new to ruby and just learning cucumber and rspec. I have some examples(tests) that need to fake a directory structure and file grouping, fake a properly formatted json file and fake a ruby-git interraction (git.fetch, git.merge). I've been reading about mocks and stubs but still feeling a little in the dark. Given some example tests like the following describe "#update_repo" do it "should update the repository without errors" do git = double('git') # How do I mock this so that the Git object is "faked" and the calls to fetch/merge don't cause an error without actually talking to a remote repo lambda { @app.update_repo git }.should_not raise_error end end describe "#check_json" do it "should check that the har files are valid json if they exist" do # In the real context @app.files contains a list of har json files # How do I mock the json files on the file system test_contents = @app.organize_test_contents @app.files # Can I mock test_contents or use a fixture? result = @app.check_json test_contents result.should =~ /JSON Valid/ end end What are some recommended ways for faking data, faking file systems, faking network interractions -- Posted via http://www.ruby-forum.com/. From spocksplanet at gmail.com Tue Apr 19 17:32:28 2011 From: spocksplanet at gmail.com (planon) Date: Tue, 19 Apr 2011 14:32:28 -0700 (PDT) Subject: [rspec-users] "can't convert Symbol into Integer" error with Rspec and Mongoid Message-ID: I'm running into this error while trying to run a unit test on a Mongoid database: def show id=params[:id] @user=User.find(:first,id) end My test before(:each) do @user = Fabricate(:user) sign_in @user end ... it "should be successful" do get "show", :id => @user response.should be_success end And the error message 1) UsersController GET 'show' for the logged in user should be successful Failure/Error: get "show", :id => @user TypeError: can't convert Symbol into Integer # ./app/controllers/users_controller.rb:6:in `show' # ./spec/controllers/users_controller_spec.rb:31:in `block (4 levels) in ' Does anyone know why this keeps happening and what I can do to fix it? From mmazur at gmail.com Tue Apr 19 19:16:55 2011 From: mmazur at gmail.com (Mike Mazur) Date: Wed, 20 Apr 2011 07:16:55 +0800 Subject: [rspec-users] "can't convert Symbol into Integer" error with Rspec and Mongoid In-Reply-To: References: Message-ID: Hi, On Wed, Apr 20, 2011 at 05:32, planon wrote: > I'm running into this error while trying to run a unit test on a > Mongoid database: > > ?def show > ? ?id=params[:id] > ? ?@user=User.find(:first,id) > ?end > > My test > > ?before(:each) do > ? ?@user = Fabricate(:user) > ? ?sign_in @user > ?end > ?... > ?it "should be successful" do > ? ?get "show", :id => @user > ? ?response.should be_success > ?end > > And the error message > > ?1) UsersController GET 'show' for the logged in user should be > successful > ? ? Failure/Error: get "show", :id => @user > ? ? TypeError: > ? ? ? can't convert Symbol into Integer > ? ? # ./app/controllers/users_controller.rb:6:in `show' > ? ? # ./spec/controllers/users_controller_spec.rb:31:in `block (4 > levels) in ' Try adding to_param in your spec: get "show", :id => @user.to_param What's happening is the "show" action receives the entire user object in params[:id] instead of just an id. Mike From littlezhong222 at gmail.com Mon Apr 18 23:58:07 2011 From: littlezhong222 at gmail.com (Zhong) Date: Mon, 18 Apr 2011 20:58:07 -0700 (PDT) Subject: [rspec-users] how to pass command-line parameter to Rspec script? Message-ID: Dear all, Anyone know how to pass command-line parameter to Rspec script? For example: I want to run the test.rb script. Suppose there is a parameter that is set in test.rb script is sleep. For the convenience,I want to set the parameter for sleep in the command-line. If type : $ spec test.rb --sleep 10 The script will sleep 10 seconds. If type $ spec test.rb --sleep 5 The script will sleep 5 seconds. Anyone can describe the detail how to do that? Thanks in advance! From ufbobbo at gmail.com Tue Apr 19 11:51:53 2011 From: ufbobbo at gmail.com (iwasrobbed) Date: Tue, 19 Apr 2011 08:51:53 -0700 (PDT) Subject: [rspec-users] RSpec/Webrat Checking output is properly escaped Message-ID: <656f7154-2e68-430d-a53e-3e80c98c5b7c@bl1g2000vbb.googlegroups.com> I want to test that the JSON response from a create action is sanitized properly, but rspec or webrat appears to be parsing the output into proper HTML chars instead of escaped characters. I have verified that it escapes properly in the regular browser json response. The relevant RSpec test code is: include ActionView::Helpers::TextHelper include ActionView::Helpers::UrlHelper it "should automatically sanitize any HTML or script characters" do post :create, :post_id => @post.id, :content => "

Oh Hai!