A Ruby gem for writing powerful tests in Rails apps with very little code. Shoulda-matchers provides Test::Unit- and RSpec-compatible one-liners that test common Rails functionality. These tests would otherwise be much longer, more complex, and error-prone.If you're not testing a Rails project or don't want to use the matchers, you can use shoulda-context independently to write tests
write tests like:
describe Post do it { should belong_to(:user) } it { should validate_presence_of(:title) } end
The belong_to and validate_presence_of methods are the matchers. All matchers are Rails 3-specific.
Add rspec-rails and shoulda-matchers to the project's Gemfile:
group :test do gem 'rspec-rails' gem 'shoulda-matchers' end
If you're not testing a Rails project or don't want to use the matchers, you can use shoulda-context independently to write tests like:
class CalculatorTest < Test::Unit::TestCase context "a calculator" do setup do @calculator = Calculator.new end should "add two numbers for the sum" do assert_equal 4, @calculator.sum(2, 2) end should "multiply two numbers for the product" do assert_equal 10, @calculator.product(2, 5) end end end
Points: 0
You voted ‘up’
View MANUFACTURERS Wallboard
Theme by Danetsoft and Danang Probo Sayekti