Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate RSpec subjects/lets using Rantly #17

Open
thedrow opened this issue Jul 6, 2016 · 4 comments
Open

Generate RSpec subjects/lets using Rantly #17

thedrow opened this issue Jul 6, 2016 · 4 comments

Comments

@thedrow
Copy link
Contributor

thedrow commented Jul 6, 2016

Is there a way to parametrize subjects/lets using Rantly?

@abargnesi
Copy link
Member

You can return rantly data from rspec's let and subject methods for use in your tests.

let example

require 'rantly'

describe 'Rspec let with rantly' do
  let(:random_string) do
    Rantly { string }
  end

  it 'is a String' do
    expect(random_string).to be_a String
  end
end

subject example

require 'rantly'

describe 'Rspec subject with rantly' do
  subject do
    Rantly { integer }
  end

  it 'is a Number' do
    expect(subject).to be_an Integer
  end
end

@thedrow
Copy link
Contributor Author

thedrow commented Jul 7, 2016

I know I can, but I want to be able to run the tests multiple times. I managed to do it without the RSpec integration.

@abargnesi
Copy link
Member

@thedrow Could you provide an example of what you have done outside of the rspec integration?

You can also run each property test based on the RANTLY_COUNT environment variable. See here.

@thedrow
Copy link
Contributor Author

thedrow commented Jan 30, 2017

I no longer have access to the code. I just copy/pasted the blocks around.
As far as I understand from the documentation Rantly { integer } will only generate one example.

In order to utilize the rspec integration you have to use:

property_of {
  integer
}.check { |i|
  assert(i.is_a?(Integer), "integer property did not return Integer type")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants