Skip to content

Instantly share code, notes, and snippets.

@hotgazpacho
Created June 9, 2010 04:42
Show Gist options
  • Save hotgazpacho/431058 to your computer and use it in GitHub Desktop.
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
Author

C:\Users\Will\dev\FactoryGirlSpike\InteropConsole\bin\Debug>InteropConsole.exe

Unhandled Exception: IronRuby.Classes.RuntimeError$2: Factory::DuplicateDefinitionError
   at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope, Boolean bindGlobals)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path)
   at InteropConsole.Program.Main(String[] args) in C:\Users\Will\dev\FactoryGirlSpike\InteropConsole\Program.cs:line 12

@hotgazpacho
Copy link
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