I am trying to add logging to a simple rspec test. I am using Watir to drive Chrome within the spec and this works fine. I am unable to get logs using the "Logger" library.
This is my spec:
require 'rubygems'
require 'watir-webdriver'
require 'rspec'
require 'logger'
describe 'ui tests' do
let(:browser) { browser ||= Watir::Browser.new :chrome }
let(:log) {
log = Logger.new(STDOUT)
log = Logger.new('watir.tests.log', 'daily')
log.level = Logger::DEBUG
}
before {
browser.goto 'http://translate.google.com'
}
after { browser.close }
context 'simple tests' do
it 'simple test' do
log.info("Running simple test")
browser.text_field(:id => "source").set("ost")
# actual test/asserts here
end
end
end
The problem is that I am unable to call any logging method such as log.info inside the example. I get this error:
Failures:
1) ui tests simple tests simple test
Failure/Error: log.info("Running simple test")
NoMethodError:
undefined method `info' for 0:Fixnum
Why is this failing? Is it a scope issue? If I comment out the log.info the spec runs fine. I can use any methods on the "browser" object (for example, the call to browser.text_field) inside the example without a problem.
Where I am going wrong?
let(:log)block does not return the Logger instance. Simply append a line withlogbefore the closing}