Hello,

I am trying to test a pure ruby program (not a Rails program) that contains 
'Logger.new'.

The command 'bundle exec ruby' requires Logger.new to have 1..3 arguments.

On the other hand, the command 'bundle exec rspec' requires 0 argument as 
shown below. Also Logger.new with 0 argument fails.

How do you treat Logger.new in a rspec program?

Thanks you for your advice.

Koji

----------
## spec/logger_spec.rb
require 'logger'
RSpec.describe "Logger.new" do
    it "has 1 argument" do
        logger1 = Logger.new('logfile')
    end
    it "has 0 argument" do
        logger2 = Logger.new
        logger2.info("HELLO WORLD")
     end
end

## results of 'bundle exec rspec spec/logger_spec.rb'
Logger.new
has 1 argument (FAILED - 1)
has 0 argument (FAILED - 2)

Failures:

1) Logger.new has 1 argument
Failure/Error: logger1 = Logger.new('logfile')

ArgumentError:
wrong number of arguments (given 1, expected 0)
# ./spec/logger_spec.rb:4:in `initialize'
# ./spec/logger_spec.rb:4:in `new'
# ./spec/logger_spec.rb:4:in `block (2 levels) in <top (required)>'

2) Logger.new has 0 argument
Failure/Error: logger2.info("HELLO WORLD")

NoMethodError:
undefined method `info' for #<Logger:0x00007ff59f396880>
# ./spec/logger_spec.rb:8:in `block (2 levels) in <top (required)>'

## software versions
RSpec 3.12
ruby 3.2.0

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rspec+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/9f256610-b1dc-4512-995e-e2f45b005cf2n%40googlegroups.com.

Reply via email to