Skip to content

Instantly share code, notes, and snippets.

@jlindley
Created November 4, 2008 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlindley/22144 to your computer and use it in GitHub Desktop.
Save jlindley/22144 to your computer and use it in GitHub Desktop.
# RSpec ticket: http://rspec.lighthouseapp.com/projects/5645/tickets/589
# see output and version string below...
require 'rubygems'
require 'spec'
class ApplicationModel
def self.address_attribute(address)
define_method "#{address}_attribute=" do |attributes|
load_address(address, attributes)
end
end
end
describe ApplicationModel do
describe "self.address_attribute" do
it "should work with multiple parameters" do
ApplicationModel.should_receive(:define_method).with("bork_attribute=")
ApplicationModel.address_attribute :bork
end
it "should define a new method" do
ApplicationModel.address_attribute :bork
end
end
end
# jlindley@Hypatia:~$ spec -v
# rspec 1.1.11
#
# jlindley@Hypatia:~/sites/cpi2/spec/models(master)$ spec application_model_spec.rb
# .F
#
# 1)
# NoMethodError in 'ApplicationModel self.address_attribute should define a new method'
# undefined method `define_method' for ApplicationModel:Class
# ./application_model_spec.rb:8:in `address_attribute'
# ./application_model_spec.rb:22:
#
# Finished in 0.007871 seconds
#
# 2 examples, 1 failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment