Module: RSpec::Rails::Matchers::Assign
- Defined in:
- lib/rspec/rails/matchers/assign.rb
Defined Under Namespace
Classes: AssignMatcher, AssignMetaMatcher
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
131 132 133 134 135 |
# File 'lib/rspec/rails/matchers/assign.rb', line 131 def method_missing(method, *args, &block) # Allow infinitive forms of `be_<predicate>` matchers. return ::RSpec::Matchers::BePredicate.new(method.to_s.sub("is", "be"), *args, &block) if method.to_s =~ /\Ais_(.*)\Z/ super end |
Instance Method Details
#assign(*args, &block) ⇒ Object
Lets you write:
subject { get :show }
it { should assign(:blah) }
it { should assign(:blah =>"something") }
or, more interestingly:
it { should assign(:blah) == "something" }
it { should assign(:blah => is_a(String)) }
it { should assign(:blah => satisfy { |value| Thing.exists? :blah => value }) }
127 128 129 |
# File 'lib/rspec/rails/matchers/assign.rb', line 127 def assign *args, &block AssignMatcher.new self, *args, &block end |