chriskottom / minitest_cookbook_source Goto Github PK
View Code? Open in Web Editor NEWSource code examples and sample projects for The Minitest Cookbook
Source code examples and sample projects for The Minitest Cookbook
I wonder if the following code in Testing Helpers section works. I think commnet1-3
should be @comment1-3
.
describe CommentsHelper do
let(:post) { posts(:with_comments) }
before do
comment1 = post.comments.build(text: "Comment 1",
user: "[email protected]")
comment2 = post.comments.build(text: "Comment 2",
user: "[email protected]")
comment3 = post.comments.build(text: "Comment 3",
user: "[email protected]")
end
describe "#comments_for" do
it "renders each top-level comment" do
render_comments_for(post)
[comment1, comment2, comment3].each do |comment|
assert_template partial: "_comment", locals: { comment: comment }
end
end
end
end
In Appendix A, the sample code for assert_send
is assert_send @calendar, :no_appointments?, :saturday
but it should be assert_send [@calendar, :no_appointments?, :saturday]
, I think.
Please see also: http://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-assert_send
This is a very tiny problem but the code below should be must_include
@calendar.days_of_week.must_includes "Monday"
minishop test fails like this:
➜ minishop git:(master) bundle exec rake test
Run options: --seed 58825
# Running:
.................E......................................
Fabulous run in 9.343703s, 5.9933 runs/s, 20.6556 assertions/s.
1) Error:
Shopping Feature Test#test_0001_add several items to the cart and check out:
ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked: commit transaction
app/controllers/line_items_controller.rb:12:in `block in create'
app/controllers/line_items_controller.rb:11:in `create'
56 runs, 193 assertions, 0 failures, 1 errors, 0 skips
So I changed test_helper.rb like this:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/rails'
require 'minitest/pride'
require 'minitest/rails/capybara'
Capybara.default_wait_time = 1
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
# Capybara.javascript_driver = :webkit
require "support/session_helpers"
require "support/shopping_helpers"
class ActiveSupport::TestCase
include SessionHelpers
fixtures :all
end
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
I think it is worth mentioning in the book.
Page 48 says;
“It's not doing much of anything, but what we have here is, in fact, a full-fledged test case. We could execute our test suite right now, and the framework would run it.”
It took me some back and forth to previous recipe to get my test suite to run without an error. Since these first few are targeting beginners and it’s not much code what do you think about showing a code summary of what is needed to type rake
and there be no issues?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.