Comments (15)
Nice trick to accomplish this with the gem as is:
RSpec.describe Range do
let(:range) { described_class.new( 1, 10 )}
describe '#cover?' do
subject { range.method(:cover?) }
its([2]) { is_expected.to eq true }
its([1..4]) { is_expected.to eq true }
end
end
Unfortunately not my idea 🙂 All credit goes to https://zverok.github.io/blog/2017-11-01-rspec-method-call.html
from rspec-its.
I like it. Many times I felt lack of that feature. Would be great to have it.
from rspec-its.
I'm +1 for #its
carrying multiple arguments.
from rspec-its.
+1 :)
from rspec-its.
I would like to have the second #its
argument as a description overriding rather than the argument for tested method.
I mean I want to write like this
Person = Struct.new(:name)
describe Person do
subject { Person.new("Jack") }
its(:name, 'should be taken from initialization argument') { should == "Jack" }
end
so that it would generate the following documentation output:
Person
name
should be taken from initialization argument
from rspec-its.
@stp-che 👍
from rspec-its.
I think multiple arguments feature for tested method is more needed. We can also add as a last argument of its
the description but what if tested method takes multiple arguments.
from rspec-its.
We could use a hash as a parameter. There could be a methods key with an
array or a single object as an input. For a description override, we could
have a should key.
On Thursday, August 14, 2014, Artur [email protected] wrote:
I think multiple arguments feature for tested method is more needed. We
can also add as a last argument of its the description but what if tested
method takes multiple arguments.—
Reply to this email directly or view it on GitHub
#19 (comment).
from rspec-its.
A hash, indeed, could solve the problem.
I imagine something like this:
its(:method, with: [arg1, arg2], should: 'return a value'){ ... }
from rspec-its.
@stp-che +1 It looks nice. :)
from rspec-its.
Just FYI guys.
There's a gem that does just this: https://github.com/dnagir/its
Although it hasn't been updated for a whilte I regularly use it in all my projects and it seems to be solid.
But TBH I would really love it to be part of rspec-it
.
from rspec-its.
👍 This looks very nice.
from rspec-its.
My apologies for not responding to this or any other issues/PRs for the last several months. I'll try to be better going forward.
That said, I'm inclined not to support this on the grounds that:
- The
its
method has historically been in place to support "attributes", i.e. argument-less methods which can be thought of as returning some "property" of the object, rather than arbitrary methods which "do something". Introducing support for arbitrary methods seems like it's heading down a slippery support of incorporating more general support for expectations. - I'd rather see additional arguments be used to provide support for other RSpec cababilities (e.g. metadata).
I see that others have supported this extension, but I'd like to hear from anyone who might be opposed.
from rspec-its.
Personally, I probably would not use this and would end up ignoring it. I agree that "its" semantically feels appropriate for properties rather than method calls.
That said, a corollary that might work would be something like a 'call' or 'send' method, so it would look like...
call(:some_method, with: [an_arguement, another_argument]) { should pass_some_assertion }
Such a thing seems beyond the scope of this project however.
from rspec-its.
Another option that doesn't involve rspec-its
:
describe '#root' do
def root(x)
MathExample.new.root(x)
end
it { expect(root(16)).to eq 4 }
it { expect(root(9)).to eq 3 }
end
RSpec.describe Range do
subject(:range) { described_class.new( 1, 10 )}
describe '#cover?' do
def cover?(range_or_value)
range.cover?(range_or_value)
end
it { expect(cover?(2)).to be(true) }
it { expect(cover?(1..4)).to be(true) }
end
end
All credit goes to the Effective Testing with RSpec 3 book.
from rspec-its.
Related Issues (20)
- The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported. HOT 11
- Test failing due to change in RSpec's execution_result method HOT 2
- RSpec 3 is being released tomorrow HOT 1
- It's not possible to focus on an `its` assertion. HOT 12
- 'its' for expecting exceptions HOT 2
- deep hash support HOT 3
- Should use `Object#public_send` instead of `Object#send`. HOT 16
- described_class is changed when using its HOT 1
- Possible to mark "its" examples as pending? HOT 1
- are_expected undefined HOT 3
- Please update to compatible with RSpec 3.2 HOT 2
- Link to documentation from Rubygems is wrong HOT 8
- rspec-its breaking InSpec HOT 4
- its against BasicObject fails to generate description HOT 1
- its([:attr]) has the proper value, its(:attr) does not HOT 1
- When requiring the Ruby's timeout library I can no longer retrieve a nested attribute named timeout on an OpenStruct HOT 3
- irb: warn: can't alias context from irb_context. HOT 3
- Is using `its` still recommended? HOT 4
- Wrong number of arguments HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rspec-its.