What type of "assert" should rspec use to verify prerequisites?

I am using rspec with ruby ​​on rails for testing.

Question. In the specification, if I had to do cross-validation, the precondition is set correctly before starting the test, which approach is recommended?

For example, using a query like rspec ".should" doesn’t seem like it would be correct, as I am only checking the precondition ...

+4
source share
3 answers

In this situation, it is quite correct, since this is a condition that must be valid at the beginning of the test. As a very trivial example:

it "should increment by one" do value = 10 value.should eql(10) value += 1 value.should eql(11) end 
+2
source

I would have two different tests: one claimed that things like your precondition can be set correctly, and the other provided that it works, and then tests everything that depends on it.

+5
source

I don't think the current RSpec has such a function, it would be nice to have some other method for these precondition statements such as

 it "should increment by one" do value = 10 value.must eql(10) # This is a necessary pre-condition, not the actual test value += 1 value.should eql(11) end 

But I believe that such a method does not exist, but rspec-given may be of interest.

0
source

Source: https://habr.com/ru/post/1399283/


All Articles