RSpec: Expect to change multiple

In RSpec 3 you can setup multiple conditions at once (so the single expectation rule is not broken). It would look sth like: expect { click_button ‘Save’ @user.reload }.to change { @user.name }.from(‘donald’).to(‘gustav’) .and change { @user.updated_at }.by(4) .and change { @user.great_field }.by_at_least(23} .and change { @user.encrypted_password } It is not a complete solution though … Read more

PatternSyntaxException: Illegal Repetition when using regex in Java

The { and } are special in Java’s regex dialect (and most other dialects for that matter): they are the opening and closing tokens for the repetition quantifier {n,m} where n and m are integers. Hence the error message: “Illegal repetition”. You should escape them: “\\{\”user_id\” : [0-9]*\\}”. And since you seem to be trying … Read more

Mockito match any class argument

Two more ways to do it (see my comment on the previous answer by @Tomasz Nurkiewicz): The first relies on the fact that the compiler simply won’t let you pass in something of the wrong type: when(a.method(any(Class.class))).thenReturn(b); You lose the exact typing (the Class<? extends A>) but it probably works as you need it to. … Read more