Shaker
2007-Aug-22 03:44 UTC
[rspec-users] Can Rspec do module spec? What if module uses test data?
Dear fellows:
I am currently working on writing specs on some ruby modules(e.g.
myModule). At first I try to use script/generate to generate rspec_module,
but it failed. :-(
Later I manually created a file (e.g. named myModule_spec.rb) and put
the ''require ....spec_helper.rb'' as the first line of code
followed by
''describe'' block. Luckily, it seemed to be working. But it was
not likely to
be a logical way to generate module specs.
Question 1:Is there any better way of creating module spec??:confused:
Anyway, I started to write method specs in these manually created module
specs, and I found another problem. Module specs do not support
''fixtures''.
This means that if you test some methods which modify test data in your
module specs, that data won''t be restored after you finish running each
spec. In other words, all the modules specs actually share a copy of test
data. This will cause some module specs to fail if other modules do modified
the shared data beforehand.
Question 2:What should I do to resolve this problem, making module specs
access test data independently? :confused:
--
View this message in context:
http://www.nabble.com/Can-Rspec-do-module-spec--What-if-module-uses-test-data--tf4309226.html#a12267615
Sent from the rspec-users mailing list archive at Nabble.com.
aslak hellesoy
2007-Aug-22 07:54 UTC
[rspec-users] Can Rspec do module spec? What if module uses test data?
Here is an example from RSpec''s own specs:
describe Enumerable do
def each(&block)
["4", "2", "1"].each(&block)
end
it "should be included in examples because it is a module" do
map{|e| e.to_i}.should == [4,2,1]
end
end
If you pass the module to describe it will automatically be included
in each of your it blocks, so you''re right at home!
HTH,
Aslak
On 8/22/07, Shaker <flyeminent at hotmail.com>
wrote:>
> Dear fellows:
> I am currently working on writing specs on some ruby modules(e.g.
> myModule). At first I try to use script/generate to generate rspec_module,
> but it failed. :-(
> Later I manually created a file (e.g. named myModule_spec.rb) and put
> the ''require ....spec_helper.rb'' as the first line of
code followed by
> ''describe'' block. Luckily, it seemed to be working. But
it was not likely to
> be a logical way to generate module specs.
> Question 1:Is there any better way of creating module spec??:confused:
> Anyway, I started to write method specs in these manually created
module
> specs, and I found another problem. Module specs do not support
''fixtures''.
> This means that if you test some methods which modify test data in your
> module specs, that data won''t be restored after you finish running
each
> spec. In other words, all the modules specs actually share a copy of test
> data. This will cause some module specs to fail if other modules do
modified
> the shared data beforehand.
> Question 2:What should I do to resolve this problem, making module
specs
> access test data independently? :confused:
> --
> View this message in context:
http://www.nabble.com/Can-Rspec-do-module-spec--What-if-module-uses-test-data--tf4309226.html#a12267615
> Sent from the rspec-users mailing list archive at Nabble.com.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>