I spend around 4 - 5 hours on this and now seeking help from you. I am trying to execute a Cucumber feature file via Ruby and getting below error via command prompt.
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansic
on/) to get coloured output on Windows
D, [23-10-2014 09:19:09 #1244] DEBUG -- : --------------------------------------
--
D, [23-10-2014 09:19:09 #1244] DEBUG -- : start time: 2014-10-23 09:19:09 +1100
C:/testapp/features/support/env.rb:56: warning: class variable access from toplevel
Variable is set in env.rb file and feature file and ruby code as below
Given(/^Testing feature"(.*?)" Open the page$/) do |feature_name|
test_url = $url_config["testdata"]["test_poc"]["test_url"]
#browser = $browser_instance
#browser.goto(test_url)
$logger.debug "Opened the page"
puts "Opened the page"
end
Note: When I put the URL directly to the test_url = "http://www.google.com" it's working.
Related
I have the following model test:
describe 'Checking for errors' do
it 'should check for any jobs that have errors and log them' do
logger = Logger.new('log/go_job_errors_test.log')
code_location = create(:code_location_with_best_code_set)
code_location.jobs << create(:complete_job, status: 3, exception: 'I failed to complete')
CodeLocationJobFeeder.create(code_location_id: code_location.id, url: code_location.repository.url, status: 2)
CodeLocationJobFeeder.check_for_errors(1)
logger.expects(:info).with("I failed to complete")
end
With the following model code:
def check_for_errors(amount)
processed.limit(amount).each do |code_location_job_feeder|
code_location = CodeLocation.includes(:jobs).find(code_location_job_feeder.code_location_id)
log_error(code_location) unless code_location.jobs.last.status != 3
end
end
private
def log_error(code_location)
logger = Logger.new('log/go_job_errors.log')
failed_job = code_location.jobs.last
logger.info do
"Job #{failed_job.id} with code location: #{code_location.id} failed. Exception: #{failed_job.exception}"
end
end
The gist of the test is that when I execute CodeLocationJobFeeder.check_for_errors I'll have a separate log file that will tell me all the info that I want concerning some errors. This works fine in development and I get the file that I want. However when I run the test, I get output in both log/go_job_errors_test.log and log/go_job_errors.log with the following output:
log/go_job_errors.log
[2017-06-28T18:23:46.164141 #29604] INFO -- : Job 40 with code location: 93 failed. Exception: I failed to complete
This is the content that I want but in the wrong file. Here is the second file:
log/go_job_error_test.log
# Logfile created on 2017-06-28 18:40:59 +0000 by logger.rb/47272
The correct file with the wrong content.
I've been trying to apply this s.o. answer Logger test but it doesn't seem to be working too great. Can someone help point out what I'm doing wrong?
This line "Logger.new('log/go_job_errors.log')" in the model instructs to log model errors to this file 'log/go_job_errors.log'. Irrespective of environment, the model errors are always logged here 'log/go_job_errors.log'
In your tests, you start with this line 'Logger.new('log/go_job_errors_test.log')', this line creates a new log file. And when your test calls the model, the model calls 'log_error(code_location)', but that method only logs to 'log/go_job_errors.log'.
When I log into my ruby applicaiton, the first page url is http://localhost:3000/tree_display/list. So , when I run the test to assert the same, I am getting this error.
[user1 project]$ rake test
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:66)
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:67)
Started
FAIL["test_login_and_access_bookmarks/managing_bookmarks", BookmarksTest, 0.678676891]
test_login_and_access_bookmarks/managing_bookmarks#BookmarksTest (0.68s)
expecting <"tree_display/list"> but rendering with <["content_pages/view", "shared/_header", "shared/_navigation", "auth/_login", "shared/_flash_messages", "shared/_footer_message", "layouts/application"]>
test/integration/bookmarks_test.rb:15:in `block in <class:BookmarksTest>'
1/1: [=========================================================================================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.68149s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
[user1 project]$
It is rendering with <["content_pages/view", "shared/_header", "shared/_navigation", "auth/_login", "shared/_flash_messages", "shared/_footer_message", "layouts/application"]>. These are supposed to be on the first page when I enter the username and password and then I go to http://localhost:3000/tree_display/list
I noticed that the session variable contains this :#host="www.example.com",
What is the problem here? Why is it not rendering the tree_display/list? Appreciate any help.
Probably login failed in your test or it is taking time to login while you are asserting on previous page in the test. Try adding delays in assertion and login step.
I want to write a table into a file which named by the date and time it created.
I can open a file with hard coded name, write the table into it, like below:
FILENAME_EVENTS="Events.txt" -- filename in string
local fp=io.open(FILENAME_EVENTS, a) -- open a new file with the file name
io.output(FILENAME_EVENTS) -- redirect the io output to the file
-- write the table into the file
for i, e in ipairs(eventlist) do io.write(e.title, e.category, e.ds, e.de, e.td) end
But when I try to:
FILENAME_EVENTS=os.date().."\.txt" -- filename in string with date
local fp=io.open(FILENAME_EVENTS, a) -- open a new file with the file name
io.output(FILENAME_EVENTS) -- redirect the io output to the file
-- write the table into the file
for i, e in ipairs(eventlist) do io.write(e.title, e.category, e.ds, e.de, e.td) end
I got an error
bad argument #1 to 'output' (10/06/11 17:45:01.txt: Invalid argument)
stack traceback:
[C]: in function 'output'
Why this "10/06/11 17:45:01.txt" is an invalid argument? due to it contains spaces or '/'? Or any other reasons?
BTW, the platform is win7 Pro + Lua 5.1.4 for win
Apparently it's both / and : that bork. The first probably because it is regarded as directory separator. This can be demonstrated as below:
fn=os.date()..'.txt'
print(io.open(fn,'w')) -- returns invalid argument
fn=os.date():gsub(':','_')..'.txt'
print(io.open(fn,'w')) -- returns nil, no such file or directory
fn=os.date():gsub('[:/]','_')..'.txt'
print(io.open(fn,'w')) -- returns file(0x...), nil <-- Works
BTW, instead of using strange gsub and concatenation tricks, you might also consider using something like
fn=os.date('%d_%m_%y %H_%M.txt')
I've got a cucumber suite set up to read a static PDF file and do assertions on it's content.
I recently updated all my gems, and since doing so, it doesn't work anymore.
The cucumber step is as follows:
When /^I follow PDF link "([^"]*)"$/ do |arg1|
temp_pdf = Tempfile.new('foo')
temp_pdf << page.body
temp_pdf.close
temp_txt = Tempfile.new('txt')
temp_txt.close
'pdftotext -q #{temp_pdf.path} #{temp_txt.path}'
page.drive.instance_variable_set('#body', File.read(temp_txt.path))
end
This used to work just fine. But after updating to Lion/my gems, It throws the following error when executing the line temp_pdf << page.body
encoding error: output conversion failed due to conv error, bytes 0xA3 0xC3 0x8F 0xC3
I/O error : encoder error
I tried a few different PDFs from different sources and they all seem to be failing. How can I get the PDF read into the temporary file?
The following piece of code works for me. Had to change temp_pdf << page.body, to page.source (as body is already parsed faulty). I also had to set the instance variable #dom on the drivers browser, instead of #body on the driver. This is because in the recent capybara versions (rack_test) driver no instance variable body exists, instead body calls '#browser.body':
https://github.com/jnicklas/capybara/blob/master/lib/capybara/rack_test/driver.rb
browser.body again, calls 'dom.to_xml', and if you look at 'dom' you see that it initializes #dom with Nokogiri::HTML, thus it makes a lot of sense that there've been nokogiri conversion errors in the first place.
https://github.com/jnicklas/capybara/blob/master/lib/capybara/rack_test/browser.rb
with_scope(selector) do
click_link(label)
temp_pdf = Tempfile.new('pdf')
temp_pdf << page.source
temp_pdf.close
temp_txt = Tempfile.new('txt')
temp_txt.close
temp_txt_path = "#{temp_txt.path}.html"
`pdftohtml -c -noframes #{temp_pdf.path} #{temp_txt_path}`
page.driver.browser.instance_variable_set('#dom', Nokogiri::HTML(File.read(temp_txt_path))
end
Here is the command line output:
breefiel#breefield.com [~/rails_apps/recurse]# rake gems
(in /home/breefiel/rails_apps/recurse)
- [ ] authlogic
- [ ] acts_as_archive
- [ ] haml
I = Installed
F = Frozen
R = Framework (loaded before rails starts)
Notice that the gems are not I, F, or R...what does this mean?
This is just one indicator that my gems aren't being detected. When I install them, they are stored in "/home/breefiel/ruby/gems", and I've added the line
Gem.path.push "/home/breefiel/ruby/gems"
To my environment.rb.
However, "rake gems" is still returning the above output, so I'm not sure. Any thoughts?
The code is determined with this line of code:
code = gem.loaded? ? (gem.frozen? ? (gem.framework_gem? ? "R" : "F") : "I") : " "
The blank code means the gem wasn't loaded. Make sure config.gem '...' doesn't have :lib => false because that will stop them from being loaded with Rails.
If that isn't the case, looking in Rails::GemDependency, loaded? will be set by load or determined by looking for the files (if load isn't called).
I have two suggestions,
Move your gems into the normal directories and see if that fixes the problem; or
Manually call load using a ruby console and see if you get any errors that rails is missing.