Re: [rspec-users] testing instance variables that are set inside views
Quoting aslak hellesoy <[EMAIL PROTECTED]>: > @header is an implementation detail of your view that you shouldn't > care about in your view spec at all. I recommend you use the have_tag > matcher instead to verify what content gets rendered as expected. > > Aslak > Thanks Aslak, I wondered this myself. I looked around here : http://rspec.rubyforge.org/rdoc/index.html for have_tag but didn't find it. Where would be a good place to find some of these matchers? Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] testing instance variables that are set inside views
Quoting David Chelimsky <[EMAIL PROTECTED]>: >>> >> Thanks Aslak, I wondered this myself. I looked around here : >> http://rspec.rubyforge.org/rdoc/index.html for have_tag but didn't find >> it. >> >> Where would be a good place to find some of these matchers? > > have_tag is not part of rspec's core, it's in the rails plugin. The > rdoc for that is at http://rspec.rubyforge.org/rdoc-rails/index.html > > Cheers, > David Perfect, thanks! Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] rspec for the svn-less (ruby version)
A couple of things: - it is defaulted to 1.0.5, but if there was a "current" I could probably use that instead. - it seems like everyone might not use the rspec_on_rails piece...what do other think? - there are some other checks I could put in here, suggestions are welcome. - general code suggestions are welcome as well. Mike B. Here is my ruby version: #!/usr/bin/ruby -w require 'ftools' def usage puts puts "Usage: makespec.rb []" puts puts "Version defaults to 1.0.5" puts puts "Example: " puts " makespec.rb /var/www/rails/railsapp 1.0.5" puts end if ARGV[0].nil? then usage puts puts "You must include a pathname" puts exit 1 end version = ARGV[1] if ARGV[1].nil? then puts puts "Defaulting to version: 1.0.5" puts version = "1.0.5" end rspec="rspec-" + version + ".tgz" rspecrails="rspec_on_rails-" + version + ".tgz" app = ARGV[0] if ! File.exist?(rspec) then puts puts "Rspec tarball (" + rspec + ") does not exist in the current directory" puts exit 1 end if ! File.exist?(rspecrails) then puts puts "Rspec-rails tarball (" + rspecrails + ") does not exist in the current d irectory" puts exit 1 end if FileTest.directory? app + "/vendor/plugins" then system("tar","zxvf", rspec) system("tar","zxvf", rspecrails) cwd = Dir.pwd Dir.chdir(app + "/vendor/plugins") File.move(cwd + "/" + File.basename(rspec,".tgz"),app + "/vendor/plugins/rspec") File.move(cwd + "/" + File.basename(rspecrails,".tgz"),app + "/vendor/plugins/rspec_on_rails") else puts app + "/vendor/plugins doesn't exist" exit 1 end This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] need help getting a word right
Well in that specific case, please seems like a good choice please do @thing.should be_somthing end But If you had text in between then it wouldn't seem the same: please "whatever text" do @thing.should be_something end Quoting David Chelimsky <[EMAIL PROTECTED]>: > Hey all, > > I see examples showing up that look like this: > > describe Thing do > before(:each) do >@thing = Thing.new > end > > it do >@thing.should be_something > end > end > > This will produce output like this: > > Thing > - should be something > > But "it do" is driving me mad :( > > We need a better word. Of course, 'specify' has not been completely > removed, so you can still do this: > > describe Thing do > before(:each) { @thing = Thing.new } > specify { @thing.should be_something } > end > > Consise? Yes. But I'm not psyched about 'specify' either. There IS a > perfect word for this situation. What is it? Suggestions? > > Thanks, > David > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Rspec on rails with out database?
Quoting David Chelimsky <[EMAIL PROTECTED]>: > On 7/27/07, David Chelimsky <[EMAIL PROTECTED]> wrote: >> On 7/27/07, David Chelimsky <[EMAIL PROTECTED]> wrote: >> > On 7/24/07, Eric Pugh <[EMAIL PROTECTED]> wrote: >> > > Hi all, >> > > >> > > I am trying to use rspec_on_rails in a Rails app that doesn't have a >> > > database. so far I have just been faking it out by dumping in a >> > > sqlite3 database just to make Rails happy. >> > >> > Try deleting config/database.yml (or renaming it to something else) >> > and then running: >> > >> > rake spec >> > >> > That should do it. >> >> I take it back. It doesn't work. There is an open RFE on making this >> work - perhaps it's time to address it. >> > > Ah - this worked using Rails 1.2.3 and RSpec's trunk. In > config/environments.rb: > > Rails::Initializer.run do |config| > config.frameworks -= [ :active_record ] > end David, I like this solution too, but then you don't have access to some of the other nicities for a model, like validations. I found these links: http://www.realityforge.org/articles/2005/12/02/validations-for-non-activerecord-model-objects http://wiki.rubyonrails.com/rails/pages/HowToUseValidationsWithoutExtendingActiveRecord http://www.railsweenie.com/forums/2/topics/724 That talk about different ways to solve this. The last link seems like the best. > > Cheers, > David > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] Using rcov and ouput to screen
I'd like to output my rcov data to the screen in ascii instead of html...is that possible using the rake spec:rcov command? Also, is there somewhere that will allow me to search the mail archives...I'm pretty sure someone else has asked similar questions. Thanks for the help. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] (no subject)
Scott said: >> I'd like to output my rcov data to the screen in ascii instead of >> html...is that possible using the rake spec:rcov command? > Look at the RSpec gem's rdoc. I believe it is something like > Rake::RcovTask. An option can be provided to give rcov options. Run > rcov --help. This told me I needed the -T option to get what I wanted. Just to give a little more detail, I had to modify this file: vendor/plugins/rspec_on_rails/tasks/rspec.rake and in this section of code: desc "Run all specs in spec directory with RCov (excluding plugin specs)" Spec::Rake::SpecTask.new(:rcov) do |t| t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] t.rcov = true t.rcov_opts = ['--exclude', 'spec', '--rails'] end Change this: t.rcov_opts = ['--exclude', 'spec', '--rails'] to this: t.rcov_opts = ['--exclude', 'spec', '--rails', '-T'] Any way to do this by passing a command line arg? like: rake spec:rcov -T <- This DOESN'T work. If it bugs me enough, maybe I'll submit a patch that allows an rcov.opts file like the spec.opts file. :) > > Also, is there somewhere that will allow me to search the mail > archives...I'm pretty sure someone else has asked similar questions. > > Google is your friend. Rubyforge also has the mailing lists, > although they aren't searchable. Google is such a great resource...with abundant responses! Sometimes this hinders my progress. :) Thanks for the hints. > Scott Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Using rcov and ouput to screen
Sorry I left off the subject by accident...hopefully this will connect to the thread. Mike B. - Forwarded message from [EMAIL PROTECTED] - Date: Fri, 10 Aug 2007 14:33:18 -0800 From: barsalou <[EMAIL PROTECTED]> Reply-To: barsalou <[EMAIL PROTECTED]> To: rspec-users@rubyforge.org Scott said: >> I'd like to output my rcov data to the screen in ascii instead of >> html...is that possible using the rake spec:rcov command? > Look at the RSpec gem's rdoc. I believe it is something like > Rake::RcovTask. An option can be provided to give rcov options. Run > rcov --help. This told me I needed the -T option to get what I wanted. Just to give a little more detail, I had to modify this file: vendor/plugins/rspec_on_rails/tasks/rspec.rake and in this section of code: desc "Run all specs in spec directory with RCov (excluding plugin specs)" Spec::Rake::SpecTask.new(:rcov) do |t| t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] t.rcov = true t.rcov_opts = ['--exclude', 'spec', '--rails'] end Change this: t.rcov_opts = ['--exclude', 'spec', '--rails'] to this: t.rcov_opts = ['--exclude', 'spec', '--rails', '-T'] Any way to do this by passing a command line arg? like: rake spec:rcov -T <- This DOESN'T work. If it bugs me enough, maybe I'll submit a patch that allows an rcov.opts file like the spec.opts file. :) > > Also, is there somewhere that will allow me to search the mail > archives...I'm pretty sure someone else has asked similar questions. > > Google is your friend. Rubyforge also has the mailing lists, > although they aren't searchable. Google is such a great resource...with abundant responses! Sometimes this hinders my progress. :) Thanks for the hints. > Scott Mike B. This message was sent using IMP, the Internet Messaging Program. - End forwarded message - This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] 1.0.8 tarball problem.
When I untar 1.0.8 after having downloaded it from rubyforge, I get these errors: rspec-1.0.8/spec/spec/runner/spec_parser_spec.rb rspec-1.0.8/spec/spec/spec_classes.rb gzip: stdin: decompression OK, trailing garbage ignored rspec-1.0.8/spec/spec/translator_spec.rb rspec-1.0.8/spec/spec_helper.rb rspec-1.0.8/UPGRADE tar: Child returned status 2 tar: Error exit delayed from previous errors And for rspec_on_rails: rspec_on_rails-1.0.8/spec_resources/views/ rspec_on_rails-1.0.8/spec_resources/views/controller_spec/ gzip: stdin: decompression OK, trailing garbage ignored rspec_on_rails-1.0.8/spec_resources/views/controller_spec/_partial.rhtml rspec_on_rails-1.0.8/spec_resources/views/controller_spec/action_setting_flash_after_session_reset.rhtml rspec_on_rails-1.0.8/tasks/ rspec_on_rails-1.0.8/tasks/rspec.rake tar: Child returned status 2 tar: Error exit delayed from previous errors I'm using this command on Linux: tar -zxvf rspec_on_rails-1.0.8.tgz Is that a broken tarball or is it the command I'm using? Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] 1.0.8 tarball problem.
Scott said: This was a known problem. I believe it should be fixed in the next release (fixed on trunk). Scott, Would that mean I have to use svn? I don't have that option at the moment. Thanks for letting me know, though. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] Tarball anyone
Anyone willing to tar me up the 1.0.8 of rspec and rspec_on_rails? I'm interested in giving the story runner stuff a try. I really got to get svn going somehow. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Tarball anyone
Thanks guys, I appreciate it. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] Login testing ideas
I've been going through Pat's example story and noticed that there was no checking for a bad login. I assume this is because that would have made the article bigger and more complicated than it needed to be. So the question that comes of of this is: How do folks normally handle the negative case? My plan was to just use another scenario, but as a new person to BDD/TDD, etc, I didn't want to start teaching myself bad habits. So my thought was to do something like: Story "The saga of the login" do Scenario "Good login" do Given "a valid user/pass pair", "gooduser", "goodpass" do #my needed code end Then "User should login ok" do # more needed code end end Scenario "Bad login" do Given "a invalid user/pass pair", "baduser", "badpass" do #my needed code end Then "User should get rejected" do # more needed code end end end Another idea was to do this: Story "The saga of the login" do Scenario "Good login" do Given "Logging in" do #my needed code end When "with a valid user/pass pair", "gooduser", "goodpass" do #my needed code end Then "User should login ok" do # more needed code end When "with an invalid user/pass pair", "baduser", "badpass" do #my needed code end Then "User should get rejected" do # more needed code end end end This doesn't even address the issue of a good user with a bad password, but that seemed like overkill. The second seemed more fluid for me. Do people even bother with this level of granularity? I'm probably over complicating the problem. Thanks for any insight you can provide. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] testing scripts
So in the past I've written a script that query's a remote DB, takes the data, validates it, then does some processing, producing a new file with the data in a completely different format. Since this is a script with it's own set of methods, etc, how do I go about testing the pieces parts? It seems like it should be no different than doing the rails testing I have been doing, but I think I'm missing something fundamental about ruby. What I'm doing now is wrapping the methods in a module, then including the module at the top of the script. I'm thinking this will allow me test those methods independently of the script itself. There still the problem of testing the logic of the script, but I'll keep banging away, and report back. Are there other ways one might do testing against a script like this? Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] testing scripts
Ashley said: Message: 7 Date: Tue, 13 Nov 2007 20:43:53 + From: Ashley Moran <[EMAIL PROTECTED]> Subject: Re: [rspec-users] testing scripts To: rspec-users Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes On Nov 13, 2007, at 7:45 pm, barsalou wrote: > What I'm doing now is wrapping the methods in a module, then including > the module at the top of the script. Can you post some examples of the modules, classes and methods you have? Every script I've written is basically just a little object-oriented app that's got a bit at the end to fire off some "main" class with the command line args. Testing one is no different than testing, say, lib code in Rails. Ideally you want each bit of functionality in a class (and therefore file) of its own, so it can be tested in isolation. But without seeing what you've got, it's hard to guess where the problem lies. Ashley -- Ashley, I think what I've come to realize is that I need to refactor what I've done. A quick example would be: def exists?(device) # do device validation end device = Device.find(1) if exists?(device) then # do my thing end I realize that exists? should really be part of Device and doing testing on this script is helping me look at the objects differently and I'm starting to refactor. So I think my initial problem with testing my script is that it's not really OO in the first place. You've confirmed for me what I had been thinking and I'll work to that end. Thanks for the feedback. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] MissingSourceFile spec/rails/story_adapter.rb
I can see that the file story_adapter.rb isn't where it is supposed to be, however, I don't know where it comes from in the first place. Can someone give me a hint here? I installed using: ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails The above is all on one line. This is a new machine I'm building out...rspec hasn't yet worked on this machine. Ruby 1.8.4, rails 1.2.5 Thanks for any direction. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] MissingSourceFile spec/rails/story_adapter.rb
Quoting [EMAIL PROTECTED]: > I can see that the file story_adapter.rb isn't where it is supposed to > be, however, I don't know where it comes from in the first place. > > Can someone give me a hint here? > > I installed using: > > > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec > > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails > > The above is all on one line. > > > CURRENT is the 1.0.8 release. > > Try getting the trunk instead: > > http://rspec.rubyforge.org/documentation/rails/install.html > And of course this works as you'd expect, DOH! :) Thanks David. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] specs on private methods
It's interesting that this thread has started because I just ran into this problem. The error I got was: NoMethodError in 'Signup she be a valid mac address' protected method `normalize_mac' called for # ./spec/models/signup_spec.rb:10: Here's the spec: describe Signup do before(:each) do @signup = Signup.new end it "she be a valid mac address" do @signup.mac_address = "00-11-22-33-44-55-66" normalized = @signup.normalize_mac(@signup.mac_address) @signup.mac_address.should == normalized end end I have a model that has mac_address attribute. In the before validation, I wanted to make the mac address have colons(:) instead of whatever the user typed in which could have spaces between, dashes, nothing at all. My thought was to just remove all of those special characters validate it against a regex then if it passed the regex check produce the mac address with the colons included. And, if I understand it properly, Pat's statement is saying that I really shouldn't be protecting that method...which would fix my problem. So my question is then, how do you know when to use protected and private or do I just do what Rick suggested and use send? I just realized this isn't really an rspec question...so I'll just move along. Mike B. This message was sent using IMP, the Internet Messaging Program. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users