Specifically I need to create some What would be the best way to write the rspec in a situation where either of two or more outcomes are acceptable? Here's an example of what I want to I have some specs, written in RSpec, that test various models.
I use Factory Girl to generate object for testing. Now the most peculiar thing happens Rspec examples can read a mocked ENV var. But my ruby class can't read the same Passes if the method called in the expect block yields with no arguments. Fails if it does not yield, or yields with arguments.
Index M » RSpec » Matchers no frames. Predicates In addition to matchers that are defined explicitly, RSpec will create custom matchers on the fly for any arbitrary predicate, giving your specs a much more natural language feel.
For example: expect [ ]. String passes expect 3. Numeric passes expect 3. Integer passes expect 3. You can easily define your own aliases, though: RSpec :: Matchers. The description will also change according to the new name: RSpec :: Matchers. Matcher DSL Imagine that you are writing a game in which players can be in various zones on a virtual board. To specify that bob should be in zone 4, you could say: expect bob.
You can override the failure messages and the generated description as follows: RSpec :: Matchers. This is normally done by including the method and the class in a module, which is then included in your spec: module CustomGameMatchers class BeInZone Used by rspec-core to clear the state used to generate descriptions after an example.
Passes if the provided matcher passes when checked against all elements of the collection. Applied to a proc, specifies that its execution will cause some value to change. Returns: RSpec::Expectations::Configuration — the configuration object. Note: You can also use this with compound matchers as well. Examples: expect [ 1 , 3 , 5 ]. Examples: expect actual. Examples: expect 5. Examples: expect result. You can either pass receiver and message , or a block, but not both.
Examples: expect [ 1 , 2 , 3 ]. Examples: expect Examples: expect " this string ". Examples: expect File.
Examples: expect email. Examples: expect results. Examples: expect " string ". Returns: Boolean. Yields target to the block. Given a Symbol, matches if the given proc throws the specified Symbol.
Note: This matcher is not designed for use with methods that yield multiple times. Generated on Thu Sep 21 by yard 0. Matchers :: BuiltIn :: Be. Oto Brglez Oto Brglez 3, 1 1 gold badge 24 24 silver badges 32 32 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end.
Does ES6 make JavaScript frameworks obsolete? Featured on Meta. Now live: A fully responsive profile. Related 0. Hot Network Questions. Question feed.
0コメント