Skip to content

Instantly share code, notes, and snippets.

@hotgazpacho
Created June 9, 2010 04:42
Show Gist options
  • Select an option

  • Save hotgazpacho/431058 to your computer and use it in GitHub Desktop.

Select an option

Save hotgazpacho/431058 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.Scripting.Hosting;
namespace InteropConsole
{
class Program
{
static void Main(string[] args)
{
ScriptEngine engine = IronRuby.Ruby.CreateEngine();
ScriptScope scope = engine.CreateScope();
engine.Execute("require 'factories.rb'", scope);
dynamic user = engine.Execute<FactoryGirlSpike.Poco.User>("u = Factory.build(:user)", scope);
Console.WriteLine(user);
}
}
}
require 'rubygems'
require 'factory_girl'
require 'FactoryGirlSpike.dll'
include FactoryGirlSpike::Poco
# Let's define a sequence that factories can use. This sequence defines a
# unique e-mail address. The first address will be "somebody1@example.com",
# and the second will be "somebody2@example.com."
Factory.sequence :email do |n|
"somebody#{n}@example.com"
end
# Let's define a factory for the User model. The class name is guessed from the
# factory name.
Factory.define :user do |f|
# These properties are set statically, and are evaluated when the factory is
# defined.
f.first_name 'John'
f.last_name 'Doe'
f.admin false
# This property is set "lazily." The block will be called whenever an
# instance is generated, and the return value of the block is used as the
# value for the attribute.
f.email { Factory.next(:email) }
end
@hotgazpacho

Copy link
Copy Markdown
Author

Change bee0db has this working now :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment