Skip to content

Instantly share code, notes, and snippets.

@kalarani
kalarani / mocking_line.rb
Last active October 28, 2015 18:30
Use of Mocks in Unit Tests
File.write(‘sample_file.txt’, reversed_string)
@kalarani
kalarani / game_spec.rb
Last active October 23, 2015 07:57
Structure of unit tests
describe Game do
it 'should let players to be created' do
game = Game.new
game.start
player = game.createPlayer('Player 1')
expect(player).to_not be_nil
game.stop
end
@kalarani
kalarani / functional_test.rb
Last active October 1, 2015 07:33
Types of tests
require ‘selenium-webdriver’
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://string_util_test.com"
input_element = driver.find_element(:name, 'given_string')
input_element.send_keys "Functional Test"
reverse_button = driver.find_element(:id, "reverse")
reverse_button.click
class StringUtil
def reverse a_string
a_string.reverse
end
end
@kalarani
kalarani / pmadurai.rb
Created June 18, 2012 12:50
Define blocks to parse scrapify attribute
class Pmadurai
include Scrapify::Base
html "http://www.projectmadurai.org/pmworks.tscii.html"
attribute :name, xpath: "//table[@id = 'sortabletable']/tbody/tr/td[2]"
attribute :author, xpath: "//table[@id = 'sortabletable']/tbody/tr/td[3]"
attribute :urls, xpath: "//table[@id = 'sortabletable']/tbody/tr/td[7]" do |element|
element.children.map do |child|
child.xpath('@href').map(&:value)
end
@kalarani
kalarani / soap.rb
Created June 10, 2012 09:30
Savon Model and Thread safety
class Soap
extend Savon::Model
document "http://www.webservicex.net/CurrencyConvertor.asmx?WSDL"
def thread_safe?
p run_in_threads [:inr_to_usd, :usd_to_inr]
sleep 5
p run_in_threads [:usd_to_inr, :inr_to_usd]
end