Skip to content

Instantly share code, notes, and snippets.

@kinopyo
Created February 23, 2012 04:03
Show Gist options
  • Save kinopyo/1889982 to your computer and use it in GitHub Desktop.
Save kinopyo/1889982 to your computer and use it in GitHub Desktop.
Rspec Array Matching =~
it "finds upcoming published lessons" do
upcoming1 = Factory :lesson, start_at: 1.day.from_now
upcoming2 = Factory :lesson, start_at: 2.days.from_now
past = Factory :lesson, start_at: 1.day.ago
draft = Factory :lesson, visibility: 'draft'
Lesson.upcoming.should include(upcoming1, upcoming2)
Lesson.upcoming.should_not include(past, draft)
end
it "finds upcoming published lessons" do
upcoming1 = Factory :lesson, start_at: 1.day.from_now
upcoming2 = Factory :lesson, start_at: 2.days.from_now
past = Factory :lesson, start_at: 1.day.ago
draft = Factory :lesson, visibility: 'draft'
Lesson.upcoming.should =~ [upcoming1, upcoming2]
end
# https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/match_array.rb
[1,2,3].should =~ [1,2,3] # => would pass
[1,2,3].should =~ [2,3,1] # => would pass
[1,2,3,4].should =~ [1,2,3] # => would fail
[1,2,2,3].should =~ [1,2,3] # => would fail
[1,2,3].should =~ [1,2,3,4] # => would fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment