ruby - Test for warnings using RSpec -


Is it possible to check Ruby's warnings by using RSPC?

  class MyClass def Start Warning "Something Wrong" End End "Warning" MyClass.new.should Warning ("Something Wrong") End < / Code>   

warning to kernel Is defined, which is included in each item if you were not getting warnings during initialization, then you can specify a warning like this:

  obj = SomeClass.new obj. Should_receive (: warning) .with ("some messages") obj .method_that_warns It is more complicated to clarify the warning taken in the   

initialize method. If this should be done, you can swap and inspect it in a duplicate IO object for $ stderr . Just make sure to restore it after an example

  class MyClass def start alert "something is wrong" end myClass do @orig_stderr = $ stderr $ stderr = StringIO.new by terminating it The first description "Warns at Initialization" What to Do "MyClass.new $ stderr.rewind $ stderr.string.chomp.should eq (" Something's Wrong ") at the end of $ stderr = @orig_stderr End End  < / Pre>  

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -