Re: [rspec-users] cucumber generator error in rails 3
Senthil kumar Loganathan, 2010-09-27 08:11: Did I missed any gems or do I need to do any configurations? I had cucumber:install work fine with rails3. Did you remember to `bundle install`? Also you did not seem to have Rails in your Gemfile. Do you have it vendored or? If `rails --version` is different from `script/rails --version` you might want to use the later. My Gemfile looks like this. gem 'rails', '3.0.0' gem 'authlogic', :git = 'http://github.com/binarylogic/authlogic.git' group :production do gem 'mysql2' end group :test do gem 'rspec-rails', '= 2.0.0.beta.22' gem 'cucumber-rails' gem 'capybara' end group :development do gem 'sqlite3-ruby', :require = 'sqlite3' gem 'ruby-debug' end You can use `bundle list` and `bundle show` to see what you have and where did they come from. `script/rails g` should list the generators you have, including the two Cucumber generators. Bundler basics, see http://gembundler.com/rationale.html -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Good practices on spec'ing views?
Stefan Kanev, 2010-04-30 11:26: And most importantly, how does the process of writing view specs feel? It sucks. ;) I don't feel like getting any return on the investment, so I don't write them. IMO views should be about looks, and looks only. The most prominent regression issue with views (as I regard them) is getting browsers to render them right (enough). If somebody does (even partially) automatized (even single browser) render testing, I'm all ears. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] should and != operator
2009-10-12 22:18, Tero Tilus: Expression x!=y is instead just syntactic sugar for !(x==y). To illustrate how this affects #should, think of 'some string'.should != 'some string' Now Ruby internals kick in and desugar this (before anything is even executed) to !('some string'.should == 'some string') Which obviously does not fail. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] [RSpec, Rails] POST create action spec and before_filter
2009-05-18 21:40, Florent Florent: I have this controller: http://pastie.org/482270 I wrote this spec: http://pastie.org/482273 There are a few spots which draw my attention. At spec line 4 you create a mock Page with #save that always fails (succesfull save returns true). Is that intentional? At line 9 you .and_return a value from a variable you don't set anywhere. Moreover the should set @context is imo a spec smell (even though it's in description string), because it refers to internal state of a PagesController instance, which you should not be interested in, but the external behavior. The spec should set @context works fine. But when running the spec should build a new message I got this error: Page(id: integer, title: string, content: text, created_at: datetime, updated_at: datetime) (class) expected :new with ({title=Introduction, content=page d'introduction}) once, but received it 0 time Could that have something to do with the fact that you end up stubbing Page.new one or two times before setting the expectation on it at line 14? It shouldn't, but you never know. I can not find why Page model does not receive new call, and playing around I can have the spec running successfully when I remove :create from the before_filter line! Could your filter be failing and the failure not showin up somehow? Does should set @context _really_ succeed? Comment the other example one out and then try again. Generally you shouldn't expect your examples (or specs) to run in any particular order. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] [RSpec, Rails] POST create action spec and before_filter
2009-05-19 10:22, Florent Florent: BTW how can I spec that my @context is correctly set by my filter? How can you tell from _outside_ if the context is properly set or not? What does your controller use the context for? And what happens if the controller does or doesn't know about the context? -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] what has RSpec got against stack traces?
2009-03-06 22:32, Phlip: Line 192 contains neither a stray nil nor a method 'macro'. So what exactly _is_ there? Do you know that particular line causes (or noes not cause) the error? In situations like this I usually pop to debugger right before the problematic line and then poke around (eval the problematic expression in smaller parts, move up in the call stack and look for anomalies) to find out whats up. The question is why did RSpec throw away the backtrace? How do you know it did that? From the information you gave us, I can't deduce that. ...and maybe I just suck at deduction. ;) Am I the first person in history to hit a programming error inside RSpec?? What makes you suspect you are? -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] what has RSpec got against stack traces?
2009-03-07 01:12, Phlip: Test::Unit::TestCase said the error was ~20 layers deeper - but exactly below the same to_xml() call as RSpec indicated. RSpec threw the stack trace away. You could have told that right away. :-/ It seems I cant reproduce the trace mangling. Do have steps to reproduce? Please please please focus: Nobody is asking how to debug We are trying. You did not tell you did debugging, so we told you to try it, because it is usually the first step. Please, don't take it personally that we might not all know you and your debug-fu. ;) -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] what has RSpec got against stack traces?
2009-03-07 01:17, Phlip: So the question becomes: Why do we sometimes get the correct stack trace and sometimes we don't? What do you mean by correct? To my knowledge you havent posted any single somehow incorrect stack trace. If you by correct mean complete, I dare to ask if you do script/spec -b or something else? -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] ActiveRecord::Base.should_receive(:find) fails
I've got an AR-model with some find-magic I want to test. When I have ActiveRecord::Base.should_receive(:find).with(anything(),assert_options) MyModel.find(:all,find_options) in my example find-method somehow disappears alltogether and I get NoMethodError in 'MyModel find-options are passed on correctly' undefined method `find' for MyModel And docs tell that (at least something really close to that one) should work http://rspec.info/documentation/mocks/partial_mocks.html -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Is #valid? automatically called?
2009-02-12 15:42, Pat Maddox: The fact that you are asking this shows that we're violating the principle of least surprise. Yes it's a surprise How do you know #errors_on not implicitly validating wouldn't be bigger surprise? Say 30 (instead of three now surprised) people would be surprised. Would documenting implicit validation on code comments. Now it only says Extension for should have on AR Model instances on #errors_on. And imo it could very well say Calls #valid? before returning list of errors. too, although seeing that yourself from source is only one click away if you you have dug yourself that deep in rspec-rails rdoc. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Is #valid? automatically called?
2009-02-12 21:27, Mark Wilden: It seems logical that #errors_on would call valid? Otherwise, how would it know? ...and that's exactly what I thought too. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] IRB-like utility for Cucumber?
2009-01-14 18:47, aslak hellesoy: What value vould it bring over plain old: cucumber features/scratchpad.feature:34 You gotta admit that at least the cool-factor would be pretty high. :) -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] IRB-like utility for Cucumber?
2009-01-14 18:23, Sebastian W.: interactive Cucumber session similar to irb? I can imagine it (when combined with Selenium) being not only cool, but very useful tool when writing features. Kinda same way console is useful when writing code. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Why can not a BigDecimal be compared to a Float via ==. How should I handle this???
2009-01-11 18:17, Greg Hauptmann: Any suggestions on how to write an rspec expectation for equality when you get a BigDecimal back. I see that big_decimal_variable.should == 123.23 If you register keywords comparison and float, you should train yourself to cry out delta without even thinking. ;) Would this work for you? big_decimal_variable.should be_close(123.23, 0.005) -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Examples not getting rolled back...
2009-01-08 07:37, David Chelimsky: I'd grab the 1.1.12 release candidates from github: gem sources -a http://gems.github.com [sudo] gem install dchelimsky-rspec [sudo] gem install dchelimsky-rspec-rails It gives me 1.1.11.6. Is that a 1.1.12 release candidate? Could I git clone 1.1.12 somewhere? I'd love to do that. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Examples not getting rolled back...
Forgot to mention before. I'm on Rails 2.2.2 and RSpec 1.1.4. Inspired by older discussion touching this issue (see http://www.nabble.com/Database-clearing-td19572270.html) I've now got Spec::Runner.configure do |config| config.use_transactional_fixtures = false ... tables_to_truncate = ActiveRecord::Base.connection.tables - [schema_migrations] config.before(:all) do tables_to_truncate.each do |table_name| ActiveRecord::Base.connection.execute(TRUNCATE TABLE #{table_name};) end end ... end And if I run rake spec all specs pass. But if I run script/spec spec/models/class_foo_spec.rb then it finds no ghost foos do ClassFoo.should have(:no).records end fails. That is the first example of describe ClassFoo. Looks like script/spec runs examples (see pastie http://pastie.org/354521) in the order they are defined and rake spec in reverse order. And that of course makes ClassFoo.should have(:no).records fail when run _after_ examples that create ClassFoo instances (befause ive got transactions off and the db state bleeds within one describe. 2009-01-07 16:11, Tero Tilus: I'm keep getting the following kind of pattern in my logs ... log from example starts here ... SQL (0.0ms) BEGIN SQL (0.0ms) BEGIN ClassFoo Create (0.2ms) INSERT ... Group Load (0.4ms) SELECT ... Contains Create (0.2ms) INSERT ... ... other stuff from example, no transaction stuff ... SQL (1.9ms) COMMIT SQL (0.1ms) ROLLBACK ... log from example ends here ... If I turn use_transactional_fixtures off, the outer transaction is gone. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Examples not getting rolled back...
2009-01-07 13:04, Stephen Eley: config.use_transactional_fixtures in config.spec_helper.rb? Tried true, false and commenting out. I could not see any difference. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Examples not getting rolled back...
2009-01-07 13:08, David Chelimsky: Is the app code opening transactions? Yes, but only one spot (iirc) which is not anywhere near the model whose test is failing here. I'll verify tomorrow that the failing test really doesn't run the app code in question. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Database.truncate_all
2008-12-05 08:32, Jeff Talbot: I want to clear out the database after every run so my tests are isolated. Maybe a minor detail, but I'd suggest you clear out the db _before_ each run. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] rake spec defaults to devel env
I was experiencing the weirdest behavior (rake spec running fine without a test database) the other day. Turned out that actually rake spec was (and has been for heavens know how long for me) running in development environment. However script/spec runs in test environment just as I expect it to do. Is this how it should go? Am I missing something? If there's something broken in my rails app where should I start debugging? -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] #stub! and #should_receive on the same method
2008-09-25 13:47, Nick Hoffman: I'm calling #stub! and #should_receive on the same method within a class, and am finding that the method doesn't return the value given to #stub! How about GMarker.should_receive(:new).with(foo).and_return mock_marker -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] #stub! and #should_receive on the same method
2008-09-25 14:04, Nick Hoffman: I knew there was a dead simple answer to the question. Thanks, Tero. Apologies for the brain fart. Np. Done the same quite a few times myself. ;) -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] scenarios on production data
2008-09-05 16:10, Nick Hoffman: I know what you mean about it feeling reassuring to know that your tests/specs passed when run on production data. However, if your specs, scenarios, tests, etc cover all behaviours, situations, edge cases, etc, then you needn't worry. All is well. I think you are overlooking the often stressed point of tests. You are supposed to gain confidence on your codebase by testing. If you have covered everything you can think of and still have the gut feeling that some end user voodoo hiding in production environment will kill your mighty app, why not run tests against production data too? You know very well, that if you have that icky feeling, it's not gonna go away if somebody says you needn't worry. ;) Of course, if you hit something in production data, you should immediately isolate and reproduce the case in your tests and then go debugging. That way you aren't actually using production data as test data, but using it to develop the test data. And isn't that (reproducing a crack in production env into tests) just what the Laziness[1] is for too? [1] http://agilewebdevelopment.com/plugins/laziness -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] WDYT, simple, anonymous story listeners?
2008-08-12 20:25, Zach Dennis: Sometimes I don't have a full need to make a class to do something, How's that _essentially_ different from making a class or extending an existing class? I am not knowledgeable enough to just see it, and becaus I can't understand the motivation, I'm bound to hate it. ;) This is influenced from the joys of JavaScript. It even looks like JavaScript. :D -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Someone please name this matcher for me
2008-08-06 13:11, Mike Vincent: [1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2] [1, 2, 3, 4, 1].should include_all [1, 3, 1, 4, 2] I'd then think that [1, 1, 1, 2, 3, 4].should include_all [1, 3, 1, 4, 2] [1, 2, 3, 4, 5, 6].should include_all [1, 3, 1, 4, 2] Which afaik was not what Pat had in mind. Or was it? And include_all_and_nothing_but is a bit verbose. :) -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] $LOAD_PATH problem when creating rake task
2008-07-29 11:59, Luis Lavena: Did you require rubygems first? Oh dear! You made my day. \o/ -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] $LOAD_PATH problem when creating rake task
I'm trying to put together some rake tasks to run my specs, but require 'spec/rake/spectask' complains no such file. I've gem installed rspec on my Ubuntu box and looks like it's locate in /var/lib/gems/1.8/gems/rspec-1.1.4/, which is not in load path irb $LOAD_PATH = [/usr/local/lib/site_ruby/1.8, /usr/local/lib/site_ruby/1.8/i486-linux, /usr/local/lib/site_ruby/1.8/i386-linux, /usr/local/lib/site_ruby, /usr/lib/ruby/1.8, /usr/lib/ruby/1.8/i486-linux, /usr/lib/ruby/1.8/i386-linux, .] Now what? What would be a kosher way around this, maybe ln -s something somewhere? I can see the issue being discussed though, https://bugs.launchpad.net/ubuntu/+source/libgems-ruby/+bug/145267 -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Rspec - stubbing same class multiple times with different co
2008-07-23 04:37, Ry An: User.stub!(:find).with(1).and_return(@user) User.stub!(:find).with(2).and_return(@user2) the second call returns undefined local variable or method `find' for #Class:0x7faf42964d00 This is a kludge, but you might be able to work around your situation using User.stub!(:find).and_return { ... calculate retval ... } or User.stub!(:find).and_return(@user, @user2) see http://rspec.info/documentation/mocks/stubs.html Any ideas as to why this is not working? or better still how to get it working. Uhh, no idea, sorry. -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] BDD/Rails/Shoulda
2008-04-30 15:51, Ashley Moran: about a month ago I was working on someone else's code and followed this process of uncommenting code as I wrote the specs for it (there were none for that class). I actually *removed* the 'if this_condition and that_condition' part of a line that follows the pattern you gave above. Maybe the fact that the code was not yours makes a difference here? Dunnot, but I'd expect it to. I don't see how you could end up with redundant code following this process. I can well imagine how you may end up not getting all the advantages of BDD thru uncommenting process when you compare to clean BDD. But uncommenting is definitely better than writing spec on top of existing code, which in turn is _way_ better than not writing spec at all. Maybe it's because I am blanking out what the code says when I write the specs? Lucky you if you are able to do that. I've noticed I'm not. -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] cleaning up after stories
On Wed, 19 Mar 2008, Joe Van Dyk wrote: do I have to manually clear out the database after a story runs? I'm wondering the same, but with specs. Database gets dirty and tests start to fail when i repeatedly do rake spec. -- Tero Tilus ## +358 (0)50 3635 235 ## http://www.tilus.net/koti/tero/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users