Im using Pony to send email withing my sinatra applications. But the problem - i cant figure out how to debug or test it. Lest say, in php you can configure sendmail fake app (in php.ini) that will store all outgoing email as plain textfiles with all data in it.
How about ruby apps? Is it possible?
You surely found the solution already yourself
In the pony.rb file there is this code part which sends the mail:
def self.transport(tmail)
..
end
You can simply add a method to return the env:
def debug?
true #false
end
and do something special if debug mode is on
def self.transport(tmail)
puts "Debug message" if debug?
if File.executable? sendmail_binary
transport_via_sendmail(tmail)
else
transport_via_smtp(tmail)
end
end
Related
I'm trying to get a pure command line oauth flow for an installed app and it's not easy to piece this together... Docs are sorely lacking... I started with the drive example (https://github.com/google/google-api-ruby-client-samples/tree/master/drive) but when it gets to client.authorization = flow.authorize(file_storage) it tries to start webrick to put up a web page. I need something that works similarly to the CLI tools provided by google: it needs to print out the URL I need to visit and then read in the response that I can copy&paste. Is this possible with the google ruby client?
Looks like the following monkey-patch works:
module Google
class APIClient
class InstalledAppFlow
def authorize_cli(storage)
puts "Please visit: #{#authorization.authorization_uri.to_s}"
printf "Enter the code: code="
code = gets
#authorization.code = code
#authorization.fetch_access_token!
if #authorization.access_token
if storage.respond_to?(:write_credentials)
storage.write_credentials(#authorization)
end
#authorization
else
nil
end
end
end
end
end
I've written some Ruby code (connected with Cucumber) that will go to a website and click a file that I'd like to download. The browser I'm using for this is Google Chrome.
Typically, when you go to download a file in Chrome, it doesn't ask for permission. However, when I run the code I made, it says:
"This type of file can harm your computer. Do you want to keep file_name.exe anyway?" It gives 2 options, "keep" or "discard". I have to click keep.
Obviously, you don't want all executables to just start downloading; however, this particular website/file should always be trustworthy.
Is there a command in Ruby or Cucumber that allows you to click the "keep" button automatically? This could just be a general "click at this pixel" or something. Or is there a way to mark a particular website in Chrome as safe. You can't inspect the element because it's not part of the website, but, instead, part of the browser. Preferably without having to download other software.
With this being said, this suggests that if it is possible, it should also be possible to automate an installation (as in clicking next -> next -> etc) for you. Hopefully this is correct?
Thanks in advance.
You can implement it in any browser. But, for Google Chrome, here is the solution -
profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = "Absolute or relative path to your download directory"
browser = Selenium::WebDriver.for :chrome, :profile => profile
You haven't specified which gem you use for browser. But, even if you use watir-webdriver, you can use the same profile you created above with watir-webdriver.
browser = Watir::Browser.new :chrome, :profile => profile
I actually switched to using Sikuli, which worked pretty well. Thanks for the help, though.
Do you really need or want the browser to download the file? Are you really testing the browser's download feature, or do you want to verify that the server can serve the file and that it is what you expect?
I found the idea of setting up a default directory and having to check for the file clumsy, fragile and prone to errors, especially when setting up on a new host, especially for tests that run in multiple browsers.
My solution is to just use Ruby (or whatever language) features to download the file directly, and then validate that it is the file it's supposed to be. I'm not testing the browser, I'm testing the software. The only exception to that idea I can think of is if you use some javascript logic or something browser-dependent to redirect you to a link, but please don't ever do that.
However, you run into a problem if you have to log in to access your file; you either have to implement auth in your Ruby code, which isn't technically part of your Cucumber specification, or you need the cookies. I use this code to copy the cookies to avoid logging in again, and grab the file:
def assert_file_link(uri, filename, content_type)
f = open_uri_with_cookies uri
attachment_filename = f.meta["content-disposition"].sub("Attachment;filename=", "") # "Attachment;filename=Simple Flow - Simple Form.rtf"
content_length = Integer(f.meta["content-length"])
assert(f.status == ["200", "OK"], "Response was not 200 OK")
assert(f.content_type == content_type, "Expected content-type of '#{content_type}' but was '#{f.content_type}'")
assert(attachment_filename == filename, "Expected filename of '#{filename}' but was '#{attachment_filename}'")
assert(content_length > 0, "Expected content-length > 0 but was '#{content_length}'")
end
def open_uri_with_cookies(uri)
# hack the cookies from the existing session so we don't need to log in!
cookies = ""
#driver.manage.all_cookies.each { |cookie| cookies.concat("#{cookie[:name]}=#{cookie[:value]}; ") }
if block_given?
open(uri, "Cookie" => cookies, :proxy => nil) do |f|
yield f
end
else
open(uri, "Cookie" => cookies, :proxy => nil)
end
end
Hope this helps.
New to ActiveMQ. Using ruby stomp gem. I believe I'm successfully publish'ing messages to the server, as I see them in the queue in my browser admin client. But on subscribe nothing happens, no error, no output. The "in subscribe" test text from puts never appears in stdout, nor does the msg.
Should I be using a different naming format for the queues?
require 'stomp'
port = 61613
client = Stomp::Client.new( 'admin', 'admin', '127.0.0.1', port )
client.publish("/queue/mine2", "hello world!")
puts "about to subscribe"
client.subscribe("/queue/mine2") do |msg|
puts "in subscribe"
puts msg
end
client.close
I believe You are closing the client before it gets a chance to receive anything.
If there is no preemption between client.subscribe and client.close background thread that listens for new messages never gets run.
You should try adding
client.join
before closing it.
Although client.join did successfully pull down the first message or two for me, after it ran, the code completely stopped working, and the subscriber would simply hang again. I was starting my client in a very similar way (just lacking creds):
client = Stomp::Client.new('localhost', 61613)
But I was able to get it working by using a URL instead:
client = Stomp::Client.new('stomp://localhost:61613')
With creds, it would look something like:
client = Stomp::Client.new('stomp://login:passcode#host:port')
Hope this helps the next person with this issue.
I am using watir-webdriver + ruby + win7 to test same pages. and I would get these logs while I start the ie explorer by using watir-webdriver:
Started InternetExplorerDriver server (32-bit)
2.32.3.0
Listening on port 5555
are there any methods to remove these logs? any help would be appreciated!
IEDriver supports a --silent flag that suppresses diagnostic output when the server is started.
Unfortunately, at least to my knowledge, it is not configurable when creating a browser instance. Instead, you need to directly modify the Selenium::Webdriver::IE::Server class' server_args method. You can modify the lib\selenium\webdriver\ie\server.rb file directly, but it is probably easier to monkey patch.
To monkey patch the silent flag, add the following to your code some point after requiring watir-webdriver (ie selenium-webdriver) but before opening the browser.
class Selenium::WebDriver::IE::Server
old_server_args = instance_method(:server_args)
define_method(:server_args) do
old_server_args.bind(self).() << "--silent"
end
end
For example, the following will no longer log any messages.
require 'watir-webdriver'
class Selenium::WebDriver::IE::Server
old_server_args = instance_method(:server_args)
define_method(:server_args) do
old_server_args.bind(self).() << "--silent"
end
end
b = Watir::Browser.new :ie
I have stream of data coming to me via an http hit. I want to update data in realtime. I have started pushing HTTP hits data to a redis pubsub. Now I want to show it to users.
I want to update user's screen as soon as I get some data on redis channel. I want to use ruby as that is the language I am comfortable with.
I would use Sinatra's "stream" feature coupled with EventSource on the client side. Leaves IE out, though.
Here's some mostly functional server side code pulled from https://github.com/redis/redis-rb/blob/master/examples/pubsub.rb (another option is https://github.com/pietern/hiredis-rb):
get '/the_stream', provides: 'text/event-stream' do
stream :keep_open do |out|
redis = Redis.new
redis.subscribe(:channel1, :channel2) do |on|
on.message do |channel, msg|
out << "data: #{msg}\n\n" # This is an EventSource message
end
end
end
end
Client side. Most modern browsers support EventSource, except IE:
var stream = new EventSource('/the_stream');
stream.onmessage = function(e) {
alert("I just got this from the server: " + e.data);
}
As of I know you can do this via Faye check this link out
There are couple approach If you wish you can try
I remember myself building a Long Polling server using thin and sinatra to achieve something like this now If u wish you can do the same
I know of few like this and this flash client that you can use to connect directly to redis
There is EventMachine Websocket implementation u can use and hook it up with HTML 5 and Flash for non HTML 5 browser
Websocket-Rack
Other Approach you can try just a suggestion since most of them arent written in ruby
Juggernaut ( I dont think it based on Redis Pub-sub Thing also there used to ruby thing earlier not sure of now)
Socket.io
Webd.is
NULLMQ Not a redis pub sub but this is Zero MQ implementation in javascript
There are few other approach you can find If u google up :)
Hope this help