thumblemonks / riot

Riot is a fast, expressive, and contextual ruby unit testing framework
http://thumblemonks.github.com/riot/
MIT License
314 stars 28 forks source link

Query methods don't work with asserts_topic #33

Closed rlepidi closed 12 years ago

rlepidi commented 13 years ago

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.

achiurizo commented 13 years ago

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 commented 13 years ago

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 commented 13 years ago

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 commented 12 years ago

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.