Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
97 views
in Technique[技术] by (71.8m points)

RSpec: Is there a not for `and change`, e.g. `and_not to change`?

I find the .and method very useful for chaining many expectations.

expect {
  click_button 'Update Boilerplate'
  @boilerplate_original.reload
} .to  change { @boilerplate_original.title }.to('A new boilerplate')
  .and change { @boilerplate_original.intro }.to('Some nice introduction')

Is there something that let's me check for no change?

.and_not change { @boilerplate_original.intro }

Something like that? I couldn't find anything, and it's hard to search on Google for something like "and not".

question from:https://stackoverflow.com/questions/34967391/rspec-is-there-a-not-for-and-change-e-g-and-not-to-change

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No, there is no and_not and no general negation operator, as discussed in https://github.com/rspec/rspec-expectations/issues/493

There is, however, a mechanism to define a negated version of an existing matcher, as described in http://www.rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers.define_negated_matcher, which you can use with and.

The full set of compound matchers is documented at https://www.relishapp.com/rspec/rspec-expectations/v/3-4/docs/compound-expectations


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...