OK, I've never done much testing and I'm trying to learn. Given the following class in test.rb
<<
class MyTest
def initialize(x, y)
@x = x
@y = y
end
def addThem
@x + @y
end
def subtractThem
@x - @y
end
def multiplyThem
@x * @y
end
end
>>
Here's some test code I wrote:
<<
require 'rubygems'
require 'coulda'
require 'test'
include Coulda
Feature "Test It" do
in_order_to "demonstrate a simple test of test"
as_a "coulda developer"
i_want_to "provide a straight-forward scenario"
def start_test
@test = MyTest.new(2, 3)
end
Scenario "Test addThem" do
Given "Test initialized with 2 and 3" do
start_test
end
When "I addThem" do
@test.addThem
end
Then "it should be 5" do
assert(5)
end
Given "Test initialized with 2 and 3" do
start_test
end
When "I subtractThem" do
@test.subtractThem
end
Then "it should be -1" do
assert(-1)
end
end
# Scenario "Test subtractThem" do
# Given "Test initialized with 2 and 3" do
# start_test
# end
#
# When "I subtractThem" do
# @test.subtractThem
# end
#
# Then "it should be -1" do
# assert(-1)
# end
# end
end
Anything else I should be doing/not doing?
I'm also working with Ramaze. Has anyone done anything with coulda/Ramaze?
Evan,
Thanks for the feedback. One question, you suggest:
<<
def addThem
@x_plus_y = @x + @y
end
>>
which looks pretty "unnatural" to me and seems to be there just to make the testing work. Is that the case?
Would people normally write code like that?
Evan,
Thanks for the feedback. One question, you suggest:
<<
def addThem
@x_plus_y = @x + @y
end
>>
which looks pretty "unnatural" to me and seems to be there just to make the testing work. Is that the case?
Would people normally write code like that?
v0.4.0 adds support for Rails. 0.4.1, which I hope to have up later today, will get rid of those other gem dependencies.
On Oct 2, 2009 10:27 PM, "Scott LaBounty" <slab...@gmail.com> wrote:
Evan,
Thanks for the help. Yes, I probably wouldn't do a few of the things I did here normally either. I now do see where you're coming from (and yes I most certainly understand "eventful" days).
I'll try doing this with a more "real" example and post what I come up with either here or on my blog or both and maybe you or others can help me figure this out a bit more.
Once again, thanks for the help!
Scott
On Fri, Oct 2, 2009 at 3:44 PM, Evan Light <slei...@gmail.com> wrote: > > > On 10/2/09 6:30 PM, ...