jump to navigation

Reloading classes in RSpec August 11, 2008

Posted by John Dewey in Code, Example, RSpec, Ruby.
trackback

I had a class where methods could change a class variable’s structure on load. However, RSpec doesn’t reload a class, so testing
these methods is difficult.

One can reload a class inside RSpec by adding a before task:

describe SimplyTabby, "remove_system_information class method" do
  before(:each) do
    Object.send(:remove_const, 'Clazz')
    load 'clazz.rb'
  end

  it "should ..."
	...
  end
end
Advertisements

Comments»

1. Steve - April 4, 2010

Thanks. This solved a problem with simple model validations not working. Seems ridiculous that this was the solution.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: