Skip to content

Instantly share code, notes, and snippets.

s = "test 'a' and 'b' and 'c'"
arguments = s.scan /'\w+'/
=> ["'a'", "'b'", "'c'"]
targets 1,2,3,4
def targets(*targets)
@targets=[targets]
end
@targets
=> [1,2,3,4]
namespace MockingCSharp
{
public class ImplementingMockableClass
{
IInterface mockedClass;
public ImplementingMockableClass (IInterface mockable)
{
mockedClass = mockable;
}
require 'java'
require 'out.jar'
include_class Java::ImplementingMockableClass
i = ImplementingMockableClass.new(v)
puts i.output_string
class ClassWithInterface
def get_string
"mocked"
@BenHall
BenHall / gist:265343
Created December 29, 2009 14:33
Albacore zip workaround
def find_files_in(directories, include, exclude=nil)
files = []
directories.each do |d|
found = Dir.glob("#{d}/bin/#{@build_type}/#{include}");
found = found - Dir.glob("#{d}/bin/#{@build_type}/#{exclude}") unless exclude.nil?
files = files + found
end
return files
end
@BenHall
BenHall / command to execute
Created January 5, 2010 17:02
RSpec 1.2.9 running on IronRuby 0.9.3
C:\ironruby\bin>ispec myspec.rb
0.9.3.0
.
Finished in 0.1406214 seconds
1 example, 0 failures
@BenHall
BenHall / Cucumber_Watir.rb
Created January 7, 2010 10:07
Compare C# to Ruby + WebRat or Watir
Given /^(?:I'm on|I go to) the search page$/ do
@browser.goto 'http://www.google.com/'
end
When /^I search for \"(.*)\"$/ do |query|
@browser.text_field(:name, 'q').set(query)
@browser.button(:name, 'btnG').click
end
Then /^I should be on the search page$/ do
@BenHall
BenHall / webrat_selenium_hack.rb
Created January 10, 2010 02:46
Hack to make the Webrat Selenium API work for within
# Taken from https://gist.github.com/225061/2ecbd30eb13ca1edbb918249d0e834964ab58d6b
module Webrat
class SeleniumSession
extend Forwardable
# Add more methods of webrat/core/session when needed
def_delegators :current_scope, :field_labeled, :table_at, :css_search
def within(selector)
scopes.push(Webrat::Scope.from_scope(self, current_scope, selector))
@BenHall
BenHall / iCucumber
Created January 9, 2010 22:25
Scripts for Cucumber running on IronRuby
#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
require 'rubygems'
require 'cucumber/rspec_neuter'
require 'cucumber/cli/main'
begin
# The dup is to keep ARGV intact, so that tools like ruby-debug can respawn.
failure = Cucumber::Cli::Main.execute(ARGV.dup)
Kernel.exit(failure ? 1 : 0)
@BenHall
BenHall / mocking_clr.rb
Created January 17, 2010 21:02
Alternative syntax for caricature IronRuby mocking framework
stubbed = stub 'System::Web::HttpRequestBase
.application_path.return("123") &&
.file_path.return("456")'
puts stubbed
puts stubbed.application_path
puts stubbed.file_path