Last active
December 16, 2015 09:09
-
-
Save walski/5410657 to your computer and use it in GitHub Desktop.
How I would like to test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "writing blog posts" do | |
testing {User.new} | |
helpers do | |
def write_post | |
subject.posts.new(title: …) | |
end | |
end | |
# describing certain expected behaviours that… | |
traits do | |
trait "can write posts" do | |
must_change(Blog.count, 1) {write_post} | |
end | |
trait "cannot write posts" do | |
wont_change(Blog.count) {write_post} | |
end | |
trait "can publish posts" do | |
post = write_post | |
user.publish!(post) | |
post.reload.public?.must_equal true | |
end | |
trait "cannot publish posts" do | |
post = subject.posts.new(title: …) | |
user.publish!(post) | |
post.reload.public?.must_equal | |
end | |
end | |
# … under specific circumstances… | |
when "the user is an author" do | |
before do | |
subject.add_role(:author) | |
end | |
# … are applied | |
it "can write posts" | |
it "cannot publish posts" | |
end | |
when "the user is an editor" do | |
before do | |
subject.add_role(:editor) | |
end | |
it "cannot write posts" | |
it "can publish posts" | |
end | |
when "the user is an editor and an author" do | |
before do | |
subject.add_role(:editor) | |
subject.add_role(:author) | |
end | |
it "can write posts" | |
it "can publish posts" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment