I'm a newbie programmer currently working on the Roman Numeral Kata in Javascript. I've solved it at all specs (I'm using Jasmine) are passing. However, I have a lot of duplication in my specs. Here are just the first two:
describe("RomanNumeral", function () {
it('returns I for 1', function () {
expect(roman(1)).toEqual('I')
})
it('returns II for 2', function (){
expect(roman(2)).toEqual('II')
})
})
In Ruby I could solve the problem by doing something like this:
describe Roman do
[
[1, 'I'],
[2, 'II']
].each do | natural_number, roman_numeral |
it "converts #{natural_number} to #{roman_numeral}" do
Roman.of(natural_number).should == roman_numeral
end
end
end
I'm going to use a hash instead of an array but the goal is still the same. I'd like to iterate through that hash, call each, set a natural_number variable, set a roman_numeral variable and then have each spec ran by plugging in the arguments from the hash.
But right now all I've got is
describe("RomanNumeral", function () {
var test_hash = {1, 'I'}
var someFunction
_.each(test_hash, someFunction{
})
What is the best way to remove the duplication form my Javascript spec? Thank you!