Questions tagged [rspec-expectations]

rspec-expectations is a module of the RSpec BDD suite that provides a readable API to express expected test outcomes, usable with other tools such as Cucumber as well as with RSpec.

rspec-expectations is a module of the RSpec BDD suite that provides a readable API to express expected test outcomes, usable with other tools such as Cucumber as well as with RSpec. It is implemented as a Ruby gem.

Instructions for how to use rspec-expectations with Cucumber can be found on Cucumber's Github wiki.

35 questions
12
votes
4 answers

Can I use a built-in RSpec matcher in a custom matcher?

I have the following expectation in a feature spec (pretty low-level but still necessary): expect(Addressable::URI.parse(current_url).query_values).to include( 'some => 'value', 'some_other' => String ) Note the second query value is a fuzzy…
awendt
  • 13,195
  • 5
  • 48
  • 66
11
votes
1 answer

How to use RSpec expectations in irb

I'd want to use [1,2,3].should include(1) in irb. I tried: ~$ irb 1.9.3p362 :001 > require 'rspec/expectations' => true 1.9.3p362 :002 > include RSpec::Matchers => Object 1.9.3p362 :003 > [1,2,3].should include(1) TypeError: wrong argument type…
Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123
8
votes
1 answer

How can I use rspec expectations and matchers outside of Rspec?

I have a script which has evolved into needing to do some assertions and matching. It is written in ruby, and I have included rspec in the Gemfile and required it. I found this very helpful SO post on how to use in irb: How to use RSpec expectations…
Satchel
  • 16,414
  • 23
  • 106
  • 192
5
votes
1 answer

New line characters in Cucumber Capybara

I'm using Cucumber with Capybara. I've noticed that suddenly, after a bundle install, that I'm getting failed tests now where new line characters are appearing in strings as part of the text. Example…
Tom
  • 1,055
  • 1
  • 14
  • 29
4
votes
2 answers

Rspec expect(instance) to receive method not working as expected

#controller file def update @payment = Payment.find_by(reference_id: params[:reference_id]) if @payment.update(update_params) @payment.do_something end end when trying to spec if do_something method was called, by expect(@payment).to…
Ajay
  • 91
  • 1
  • 6
4
votes
1 answer

Evaluating multiple rspec expectations with cucumber

I am using rspec expectations with cucumber. It seems that when using multiple expects in a cucumber steps, cucumber evaluates them until first of them fails. However I want to continue running also other expects to get a clear picture of what went…
Tians
  • 443
  • 1
  • 5
  • 14
4
votes
3 answers

Cucumber undefined methods

I'm using cucumber with capybara I've got several similar errors. For step: Then /I should see movies of rating 'PG' or 'R'/ do page.body.should match(/PG<\/td>/) page.body.should match(/R<\/td>/) end Cucumber error: undefined method…
megas
  • 21,401
  • 12
  • 79
  • 130
2
votes
1 answer

How to execute once and expect multiple changes with RSpec?

If I want to test, that an operation produces certain side-effects, how can I execute the operation once and use the change rspec matcher. Example: expect { some_method }.to change(Foo, :count).by(1) expect { some_method }.to change(Bar,…
Alexander Popov
  • 23,073
  • 19
  • 91
  • 130
2
votes
2 answers

Can I alias a nested RSpec matcher?

I have several RSpec examples that share the following complex expectation, with the array records and the floating point numbers min_long, max_long, min_lat, max_lat varying between these examples. expect(records).to all have_attributes( …
das-g
  • 9,718
  • 4
  • 38
  • 80
2
votes
1 answer

cucumber: RSpec::Expectations::ExpectationNotMetError: expected true to respond to `true?`

According the answer I can use the rspec expectation form with the cucumber. value = true expect(value).to be_a(TrueClass) # => true but if I use #be_true method it refused answering with exception: expect(true).to be_true # =>…
Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69
2
votes
1 answer

how can i use Rspec Expectations in page object classes

How can i use Rspec Expectations in Page-object classes. I need to assert elements. Currently i am using xpath, other locators to check element existence. I know using it is step definitions. But i need it in classes. Code: class AssertTest include…
spectator
  • 329
  • 2
  • 15
2
votes
2 answers

How can I use RSpec Expectations in PORO's

Hi, I am trying to DRY up some of my specs. I extracted an Assertion class that does a couple of shoulds ... but most of the RSpec expectation magic is not working anymore. I'll try to construct a simple example, to show my problem. The object…
DiegoFrings
  • 3,043
  • 3
  • 26
  • 30
2
votes
1 answer

Rspec expectations in Cucumber: undefined method 'be' when used inside a class

I'm using rspec expectations in a cucumber framework and they look fine when used at the steps definition level. I've configured my env.rb file with: require 'rspec/expectations' World(RSpec::Matchers) The problem I've noticed now is that if I try…
mickael
  • 2,033
  • 7
  • 25
  • 38
2
votes
1 answer

rspec: undefined local variable or method `be_true'

I am using rspec 2.4.0 and cucumber 0.6.4. I am running a simple scenario (for the sake of this question): Scenario: Simple Test When I test something with step definition: require 'rspec' require 'rspec/expectations' When /^I test something$/…
Mark Micallef
  • 1,051
  • 2
  • 12
  • 25
1
vote
1 answer

RSpec: how to chain receive().with()?

I've been writing tests with instance_doubles to stand in for message chains when I need more granularity in the midst of the chain. But, I'm wondering if I'm doing things the hard way. Here's the method I want to test: def run_produceable_job #…
Chiperific
  • 4,428
  • 3
  • 21
  • 41
1
2 3