It seems that I cannot find much documentation on Minitest/spec so I was wondering if somebody could help me figure out how to do what I need to do. Basically I want to run tests on all my classes and modules to make sure they 1.) Output the right value type if static or 2.) In the case of to_symbols all keys are symbols. Here is what I tried so far:
What I assume the Gherkin would look like:
Given binns
When the version method is called
then the return should be a float
and version should be a method or constant
What I assumed it would be with minitest/spec:
require 'minitest/autorun'
require 'minitest/spec'
require 'binns'
given Binns do
when "the version method is called" do
then "the return should be a float" do
# Do work
end
end
end
But I get:
syntax error, u开发者_Go百科nexpected keyword_when (SyntaxError)
when "the version method is called" do
^
Note: I am also open to other suggestions for testing (I don't know much about cucumber and heard it was hefty) or if somebody has a book suggestion, please do tell I've been looking for a good book on Ruby Unit Testing.
MiniTest/Spec uses Rspec-style syntax: desc, it, before, after...
require 'minitest/autorun'
require 'minitest/spec'
require 'binns'
desc Binns do
it "should return a float when the version method is called" do
# Do work
end
end
If it'd make the transition easier for you, you could alias the "desc" method to "given" and "it" method to "when".
Good tutorial from Peter Cooper here.
精彩评论