Coding Dojo slides

14 views
Skip to first unread message

Gavin Heavyside

unread,
Apr 27, 2011, 8:11:25 AM4/27/11
to surrey-rubyists
I hope everyone enjoyed the coding dojo last night. Someone asked about the slides I prepared to introduce the exercise but didn't show - they are now online at http://www.slideshare.net/gheavyside/coding-dojo-surrey-rubyists-2-26-april-2011

There are only a couple of slides I was going to use as a prop to to introduce the idea of improving as a developer by deliberate practice, through coding kata, dojos, code retreats etc.

Cheers,

Gavin

Andy Pike

unread,
Apr 27, 2011, 6:11:01 PM4/27/11
to surrey-...@googlegroups.com
Thanks Gavin. I thought this session was really useful, interesting and I definitely learnt from it. I think we should definitely do this again in the future.

I do have a question related to your setup which you might be able to help with or maybe point me in the right direction. I've setup Guard and Guard-rspec (also their dependents: growlnotify, growl gem and rb-fsevent gem) for a rails 3 app. If I run my specs with "$ rake spec" they all pass. If however I run "$ guard" it tries running the specs but raises an error (see below). Looking at the stack trace it isn't due to a failing test as it seems to be while loading the spec files. It looks like it's database related as it's failing due to an ActiveRecord uniqueness validation error. So, do you know if guard-rspec runs specs in a different mode or with different options to the rake task? I'm just using the generated Guardfile (but I have tried tweaking with these options).

Any ideas?

Cheers

Andy

==================================Stack trace==================================
Andrew-Pikes-iMac:feedbackize andy$ guard
Guard is now watching at '/Users/andy/Documents/Ruby/feedbackize'
Guard::RSpec is running, with RSpec 2!
Running all specs
/Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.6/lib/active_record/validations.rb:49:in `save!': Validation failed: Nickname The nickname person1 has already been taken (ActiveRecord::RecordInvalid)
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.6/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.6/lib/active_record/transactions.rb:245:in `block in save!'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.6/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.6/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.6/lib/active_record/transactions.rb:207:in `transaction'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.6/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.6/lib/active_record/transactions.rb:245:in `save!'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/proxy/create.rb:6:in `result'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:330:in `run'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:273:in `create'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/proxy/build.rb:17:in `associate'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/attribute/association.rb:15:in `add_to'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:327:in `block in run'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:325:in `each'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:325:in `run'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:253:in `build'
    from /Users/andy/Documents/Ruby/feedbackize/spec/factories.rb:39:in `block in <top (required)>'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:56:in `define'
    from /Users/andy/Documents/Ruby/feedbackize/spec/factories.rb:37:in `<top (required)>'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.6/lib/active_support/dependencies.rb:239:in `block in require'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.6/lib/active_support/dependencies.rb:227:in `load_dependency'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.6/lib/active_support/dependencies.rb:239:in `require'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:310:in `block in find_definitions'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:308:in `each'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:308:in `find_definitions'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl_rails-1.0.1/lib/factory_girl_rails/railtie.rb:11:in `block in <class:Railtie>'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.6/lib/active_support/lazy_load_hooks.rb:34:in `call'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.6/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.6/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.6/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.6/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/application/finisher.rb:46:in `block in <module:Finisher>'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/initializable.rb:25:in `run'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/initializable.rb:49:in `each'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/application.rb:134:in `initialize!'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/application.rb:77:in `method_missing'
    from /Users/andy/Documents/Ruby/feedbackize/config/environment.rb:5:in `<top (required)>'
    from /Users/andy/Documents/Ruby/feedbackize/spec/spec_helper.rb:6:in `require'
    from /Users/andy/Documents/Ruby/feedbackize/spec/spec_helper.rb:6:in `<top (required)>'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from /Users/andy/Documents/Ruby/feedbackize/spec/controllers/application_controller_spec.rb:1:in `<top (required)>'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
    from /Users/andy/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'

Andy Pike

unread,
Apr 27, 2011, 6:38:38 PM4/27/11
to surrey-...@googlegroups.com
As a follow up to this I can recreate the below error without Guard by just running "$ rspec spec". Running "$ rake spec" shows the output below:

So rake invokes bundler and lists the spec files. I tried adding the :bundler => true option in my Guardfile but that didn't seem to help.

Not sure what else I need to do.

Thanks in advance

Andy

==============Output========================
Andrew-Pikes-iMac:feedbackize andy$ rake spec
(in /Users/andy/Documents/Ruby/feedbackize)
/Users/andy/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -S bundle exec rspec ./spec/controllers/application_controller_spec.rb ./spec/controllers/feedbacks_controller_spec.rb ./spec/controllers/pages_controller_spec.rb ./spec/controllers/sessions_controller_spec.rb ./spec/controllers/settings_controller_spec.rb ./spec/controllers/users_controller_spec.rb ./spec/helpers/application_helper_spec.rb ./spec/models/ability_spec.rb ./spec/models/activity_spec.rb ./spec/models/badge_spec.rb ./spec/models/feedback_spec.rb ./spec/models/reward_spec.rb ./spec/models/user_spec.rb ./spec/routing/routes_spec.rb
......................................................................**.........................................

Pending:
  Activity add some examples to (or delete) /Users/andy/Documents/Ruby/feedbackize/spec/models/activity_spec.rb
    # Not Yet Implemented
    # ./spec/models/activity_spec.rb:4
  Badge add some examples to (or delete) /Users/andy/Documents/Ruby/feedbackize/spec/models/badge_spec.rb
    # Not Yet Implemented
    # ./spec/models/badge_spec.rb:4

Finished in 0.98516 seconds
113 examples, 0 failures, 2 pending

Andy Pike

unread,
Apr 27, 2011, 6:50:07 PM4/27/11
to surrey-...@googlegroups.com
Sorry for all the emails, but I've cracked it. You need to run "$ rake db:test:prepare" before starting Guard. I think the guard-rspec docs are out of date as they reference calling "$ rake spec:prepare_fixtures" which isn't a task that exists in my rakefile (after checking with $ rake -T). I'm going to see if I can automate this when Guard loads.

Cheers

Andy

John Beynon

unread,
Apr 28, 2011, 3:16:39 AM4/28/11
to surrey-...@googlegroups.com
Really annoyed I missed this session - the description was simply 'Coding Dojo' and I inferred from that it was about the Dojo javascript toolkit which I wasn't particularly interested in - seems like I missed an excellent session.

From this can I request that session descriptions are a bit more descriptive perhaps?

Cheers,

Jb.

On Wed, Apr 27, 2011 at 11:11 PM, Andy Pike <andy.pi...@gmail.com> wrote:

Andy Pike

unread,
Apr 28, 2011, 3:24:45 AM4/28/11
to surrey-...@googlegroups.com
Hey John, yes I agree on the descriptions front. I'll try to be clearer about the sessions in future. Sorry about that.

Sent from my iPhone

Gavin Heavyside

unread,
Apr 28, 2011, 4:16:26 AM4/28/11
to surrey-...@googlegroups.com
This is probably because running tests with rake drops and recreates the test database, and initializes the schema using db/schema.rb before starting the test run (the db:test:prepare task).

I don't have to run anything with my Rails 3 apps before running guard. I'm using guard-rspec and guard-cucumber. Your error is from trying to create an entry that already exists in the test DB, which obviously has a unique constraint on the nickname. I think that I mostly don't hit this problem, either through using mocks and fixtures (with factory_girl) rather than explicitly creating entries in the test DB, or by cleaning the DB in the setup phase of my specs.

You could also look at the database_cleaner gem (https://github.com/bmabey/database_cleaner) which can hook into rspec, cucumber etc to ensure clean DB state before each test or set of tests, without doing a full recreation of the schema.

I think the reference to prepare_fixtures in the guard-rspec docs is for running guard-rspec's tests, not your own.

Cheers,

Gavin

Andy Pike

unread,
Apr 28, 2011, 6:50:57 AM4/28/11
to surrey-...@googlegroups.com
Thanks Gavin, I ended up using guard-spork and I added the rake call to my guardfile so when spork forks for each run it is using a clean state. My specs now run really fast (as there is no rails env startup time) so all I do is save a spec and within a second growl appears with the result. Really nice.

I think this is probably pointing out that I'm doing something wrong so I'll see what I can do to improve this.

Thanks for the help!

Sent from my iPhone

Julian Simpson

unread,
Apr 30, 2011, 10:38:52 AM4/30/11
to surrey-...@googlegroups.com
I just wanted to belatedly pitch in and add my thanks to Gavin.  I was a little bit cynical about coding dojos, but I can now say that was misplaced. I found it to be really positive, and an illustration of how sloppy my coding can get when I don't do any deliberate practice.

Also, it illustrated just how powerful Guard and friends could be.

Thanks!

J. 

Reply all
Reply to author
Forward
0 new messages