Hi,
Googling ‘RSpec describe scope’ didn’t yield much, so apologies if
this question has been dealt with.
It seem well known that a ruby class is ‘visible’ between describes,
and if this is a problem then you should use some counter as prefix or
suffix:
‘class Item_001; … end’
Is there any work underway, or sheduled release where classes will
exist only in the scope they are defined?
Writing spec’s for Og is where this becomes an issue because Og will
grab all manageble objects it can ‘see’… all sorts of PITA can
arise.
Thanks for all the great work, T/BDD definitely is a brilliant way to
work, and RSpec makes it painless, esp for us amatuers 
Mark
On 11/21/07, Mark Van De Vyver [email protected] wrote:
exist only in the scope they are defined?
Writing spec’s for Og is where this becomes an issue because Og will
grab all manageble objects it can ‘see’… all sorts of PITA can
arise.
try something like this:
before do
@la_classe = Class.new(the_superclass)
or if you need to reload the class
load ‘file/with/class.rb’
end
after do
undefine the class (don’t remember off the top of my head - #undef
or something)
end
Aslak
On Nov 21, 2007 1:07 AM, Mark Van De Vyver [email protected] wrote:
exist only in the scope they are defined?
This has never been brought up before. Feel free to submit a feature
request at http://rspec.lighthouseapp.com/.
Writing spec’s for Og is where this becomes an issue because Og will
grab all manageble objects it can ‘see’… all sorts of PITA can
arise.
I found this:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/6924
So you could, in theory, monkey patch ExampleGroupMethods (in trunk
2937 - these names are changing a bit, so keep an eye out) to remove
the defined constant
Thanks for all the great work, T/BDD definitely is a brilliant way to
work, and RSpec makes it painless, esp for us amatuers 
That’s what we want to hear! Thanks.
Cheers,
David
On Nov 22, 2007 8:53 AM, Mark Van De Vyver [email protected] wrote:
and if this is a problem then you should use some counter as prefix or
grab all manageble objects it can ‘see’… all sorts of PITA can
arise.
I found this:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/6924
I thought to make a feature request with a spec, any comments on why
the following fails
OK, even if you remove quotes to have defined?(Item) I get:
#<NoMethodError: undefined method `defined?’ for Kernel:Module>
puzzled.
Mark
On 11/21/07, Mark Van De Vyver [email protected] wrote:
and if this is a problem then you should use some counter as prefix or
grab all manageble objects it can ‘see’… all sorts of PITA can
arise.
I found this:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/6924
I thought to make a feature request with a spec, any comments on why
the following fails
No idea, because you forgot to attach any output from RSpec 
Hi,
Thanks for the prompt responses…
On Nov 22, 2007 1:18 AM, David C. [email protected] wrote:
Is there any work underway, or sheduled release where classes will
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/6924
I thought to make a feature request with a spec, any comments on why
the following fails
rspec example
require ‘spec’
module Example
describe "RSpec " do
before(:each) do
class ::Item
attr_accessor :name
end
end
it "should not raise error on defined?" do
lambda{defined?("Item")}.should_not raise_error
end
it "should be defined after being removed" do
defined?("Item").should == "constant"
end
after(:each) do
Kernel.remove_const("Item")
end
end
end # rspec example
Appreciate any comments.
Mark
On Nov 22, 2007 9:01 AM, aslak hellesoy [email protected]
wrote:
It seem well known that a ruby class is ‘visible’ between describes,
Writing spec’s for Og is where this becomes an issue because Og will
No idea, because you forgot to attach any output from RSpec 
Apologies, the spec and output:
require ‘spec’
module Example
describe "RSpec " do
before(:each) do
class ::Item
attr_accessor :name
end
end
it "should not raise error on defined?" do
lambda{ defined?(Item)}.should_not raise_error
end
it "should be defined as a constant" do
defined?(Item).should == "constant"
end
after(:each) do
remove_const("Item")
end
end
end # spec
The output
FF
-
NoMethodError in ‘RSpec should not raise error on defined?’
undefined method `remove_const’ for [RSpec example]:#Class:0xb7bb2ef4
/usr/src/nitro-repo/og/test/rspec_example_spec.rb:19:
-
NoMethodError in ‘RSpec should be defined as a constant’
undefined method `remove_const’ for [RSpec example]:#Class:0xb7bb2ef4
/usr/src/nitro-repo/og/test/rspec_example_spec.rb:19:
Finished in 0.006203 seconds
2 examples, 2 failures
On Nov 21, 2007 11:08 PM, Mark Van De Vyver [email protected] wrote:
this question has been dealt with.
request at http://rspec.lighthouseapp.com/.
the following fails
describe "RSpec " do
defined?(Item).should == “constant”
end
after(:each) do
remove_const("Item")
end
end
end # spec
Try this:
module Example
describe “A class defined in before” do
before do
class Item
@@var ||= 0
@@var += 1
def self.var
@@var
end
end
end
it "should be redefined the first time" do
Item.var.should == 1
end
it "should be redefined the second time" do
Item.var.should == 1
end
after do
Example.send(:remove_const, 'Item')
end
end
end
It will fail without the after, so the after definitely undefines the
class so it can be redefined completely the next time.
HTH,
Aslak