Query methods don't work with asserts_topic #33

Closed
rlepidi opened this Issue May 28, 2011 · 4 comments

Comments

Projects
None yet
3 participants
@rlepidi

rlepidi commented May 28, 2011

Both of these:

context "An array" do
  setup { [3] }
  asserts_topic.includes?(3)
end

context "An array" do
  setup { [] }
  asserts_topic.empty?
end

Generate the same error:

C:/Ruby192/lib/ruby/gems/1.9.1/gems/riot-0.12.3/lib/riot/assertion.rb:59:in `enh
ance_with_macro': undefined method `new' for nil:NilClass (NoMethodError)
        from riot.rb:6:in `block in <main>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/riot-0.12.3/lib/riot/middleware
.rb:102:in `instance_eval'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/riot-0.12.3/lib/riot/middleware
.rb:102:in `call'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/riot-0.12.3/lib/riot/context.rb
:118:in `prepare_middleware'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/riot-0.12.3/lib/riot/context.rb
:55:in `initialize'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/riot-0.12.3/lib/riot.rb:18:in `
new'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/riot-0.12.3/lib/riot.rb:18:in `
context'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/riot-0.12.3/lib/riot.rb:123:in
`context'

(Line 6 is the line that has the query method on it)

Non-query methods work fine.
Am I doing something wrong? This seems like too obvious of a bug to go undetected.

@achiu

This comment has been minimized.

Show comment Hide comment
@achiu

achiu May 28, 2011

Contributor

if you're trying to use the assertion methods its:

asserts_topic.includes 3
asserts_topic.empty

if you're trying to call their methods, you'll have to pass it to topic explicitly like:

asserts("that it includes 3") { topic.include? 3 }
asserts("that its empty") { topic.empty? }
Contributor

achiu commented May 28, 2011

if you're trying to use the assertion methods its:

asserts_topic.includes 3
asserts_topic.empty

if you're trying to call their methods, you'll have to pass it to topic explicitly like:

asserts("that it includes 3") { topic.include? 3 }
asserts("that its empty") { topic.empty? }
@gus

This comment has been minimized.

Show comment Hide comment
@gus

gus May 28, 2011

Member

Thanks, @achiu. Yep, the ? at the end of the usage of the includes macro is the culprit. Makes we wonder again if we should aliases for this.

Thanks for the question, @RyeGuy

Member

gus commented May 28, 2011

Thanks, @achiu. Yep, the ? at the end of the usage of the includes macro is the culprit. Makes we wonder again if we should aliases for this.

Thanks for the question, @RyeGuy

@rlepidi

This comment has been minimized.

Show comment Hide comment
@rlepidi

rlepidi May 28, 2011

Thanks guys.

Is that because they are the builtin macros? I admit I didn't scroll down all the way (just experimenting). I just assumed it'd delegate the call to the topic. Any reason why it doesn't just do that? That would be the expected behavior, imo.

At the very least the error message could be better.

rlepidi commented May 28, 2011

Thanks guys.

Is that because they are the builtin macros? I admit I didn't scroll down all the way (just experimenting). I just assumed it'd delegate the call to the topic. Any reason why it doesn't just do that? That would be the expected behavior, imo.

At the very least the error message could be better.

@gus

This comment has been minimized.

Show comment Hide comment
@gus

gus Mar 22, 2012

Member

As I said in comment on an issue yesterday:

I've been away a hell of a long time. Crazy things have happened. Hopefully those things are done. So, I'm going to pretend I didn't let all of these issues fester if everyone else agrees to play along and silently forgive me.

Hopefully, you'll also forgive me for the belated response.

Basically, one part of me really wants to support the query-able versions of these assertion macros. It seems logical/intuitive that you'd want to use include? where you would use include now, for instance, because include? is pretty common language in ruby. However, I've always thought of the whole assertion as being a statement: asserts that X does include Y or asserts that Foo is a kind of Thing, for instance. I never thought of the assertion being: does X include Y? or is Foo a kind of Thing?.

So, there's that.

On top of that, I'm not too keen on possibly overriding some behavior that is built into every Object: respond_to? and kind_of? for instance.

All that said, I might just be thinking about this all wrong. Let me know.

Member

gus commented Mar 22, 2012

As I said in comment on an issue yesterday:

I've been away a hell of a long time. Crazy things have happened. Hopefully those things are done. So, I'm going to pretend I didn't let all of these issues fester if everyone else agrees to play along and silently forgive me.

Hopefully, you'll also forgive me for the belated response.

Basically, one part of me really wants to support the query-able versions of these assertion macros. It seems logical/intuitive that you'd want to use include? where you would use include now, for instance, because include? is pretty common language in ruby. However, I've always thought of the whole assertion as being a statement: asserts that X does include Y or asserts that Foo is a kind of Thing, for instance. I never thought of the assertion being: does X include Y? or is Foo a kind of Thing?.

So, there's that.

On top of that, I'm not too keen on possibly overriding some behavior that is built into every Object: respond_to? and kind_of? for instance.

All that said, I might just be thinking about this all wrong. Let me know.

@gus gus closed this Mar 22, 2012

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