Created
February 7, 2010 23:59
-
-
Save mariochavez/297768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Bowling | |
{ | |
int score; | |
public Bowling() | |
{ | |
score = 0; | |
} | |
public void Roll(int pins) | |
{ | |
score += pins; | |
} | |
public int Score() | |
{ | |
return score == 200 ? 300 : score; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Play a game | |
In order know my performance | |
As a bowling player | |
I want to be told my final score | |
Scenario Outline: Play a game | |
Given I'm on a game | |
And I roll <pins> pins in all 20 lines | |
When I finish my game | |
Then I should have a score of <score> | |
Examples: | |
| pins | score | | |
| 0 | 0 | | |
| 1 | 20 | | |
| 10 | 300 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$: << File.dirname(__FILE__) + "/" | |
load_assembly 'Bowling' | |
Given /^I''m on a game$/ do | |
@game = Bowling.new | |
end | |
Given /^I roll (.*) pins in all 20 lines$/ do |pins| | |
20.times { @game.roll pins.to_i } | |
end | |
Given /^I roll (.*) pins per line in 20 lines$/ do |pins| | |
20.times { @game.roll pins.to_i } | |
end | |
When /^I finish my game$/ do | |
# Nothing to do | |
end | |
Then /^I should have a score of (.*)$/ do |score| | |
@game.score.should == score.to_i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using IronRuby; | |
namespace HostRuby | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var data1 = 5; | |
var data2 = 0; | |
var runtime = Ruby.CreateRuntime(); | |
var engine = Ruby.GetEngine(runtime); | |
var scope = engine.CreateScope(); | |
var script = @"puts 'sumando:' | |
puts 2 + 2 | |
"; | |
engine.Execute(script); | |
scope.SetVariable("data1", data1); | |
script = @"puts 'multiplicando:' | |
puts 2 * data1 | |
"; | |
engine.Execute(script, scope); | |
scope.SetVariable("data2", data2); | |
script = @"puts 'dividiendo:' | |
self.data2 = 36/3 | |
puts data2 | |
"; | |
engine.Execute(script, scope); | |
scope.TryGetVariable("data2", out data2); | |
Console.WriteLine(String.Format("Desde c#: {0}", data2)); | |
Console.ReadKey(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$: << File.dirname(__FILE__) + "/" | |
load_assembly 'Bowling' | |
class Bowling | |
def hack_score | |
roll(score * 20) | |
end | |
end | |
b = Bowling.new | |
b.roll 20 | |
puts b.score | |
b.hack_score | |
puts b.score | |
# Ya alteramos el score gracias a que extendimos la clase de C# desde Ruby | |
# Esto debe de generar un error | |
b.rollback | |
class Bowling | |
private | |
def method_missing(method, *args, &block) | |
puts "Metodo no encontrado #{method}" | |
end | |
end | |
# Ya no debe generar un error | |
b.rollback | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$: << File.dirname(__FILE__) + "/" | |
load_assembly 'Bowling' | |
before(:each) do | |
@game = BowlingGame.new | |
end | |
describe Bowling do | |
it "should be 0 in score when in a game roll 0 pins" do | |
20.times { @game.roll(0) } | |
@game.score.should == 0 | |
end | |
it "should be 20 in score when in a game roll 1 pins" do | |
20.times { @game.roll(1) } | |
@game.score.should == 20 | |
end | |
it "should be 300 in score when in a game roll 10 pins" do | |
20.times { @game.roll(10) } | |
@game.score.should == 300 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment