GithubHelp home page GithubHelp logo

Comments (16)

aslakhellesoy avatar aslakhellesoy commented on July 19, 2024

What colours do you get? One row grey (surplus) and one yellow (missing)? In that order or the opposite? It could be a cucumber bug, but it could also be a cuke4duke bug.

Wanna investigate?

from cuke4duke.

torbjornvatn avatar torbjornvatn commented on July 19, 2024

The second | 1 | 2 | is gray (surplus).
When I print the List<Map<String, String>> I made it looks like: [a1b2, {b=2, a=1}]
When I print table.hashes it looks like: a1b2

Could it be a JRuby RubyArray vs. Java ArrayList problem?

Will try to investigate, at least on the cuke4duke side. The ruby code in cucumber is a bit hardcore for me as a ruby novice

from cuke4duke.

aslakhellesoy avatar aslakhellesoy commented on July 19, 2024

Cool. The elimination technique works well here. If you can confirm it's not a cuke4duke bug I'll investigate on the cucumber/ruby side. Otherwise you'll fix the cuke4duke bug ;-)

from cuke4duke.

darrinholst avatar darrinholst commented on July 19, 2024

This is the first time I've looked at the diff stuff so maybe I'm missing something, but isn't that what is supposed to happen?

You initialized the list with what was already in the table and then added a new map giving you a surplus row

  # An exception is raised if there are missing rows or columns, or
  # surplus rows. An error is <em>not</em> raised for surplus columns.
  # Whether to raise or not raise can be changed by setting values in
  # +options+ to true or false:

It does look like the ruby hash prints differently then the java map, but I think it all works itself out by the time it gets to ruby land.

from cuke4duke.

torbjornvatn avatar torbjornvatn commented on July 19, 2024

Sorry about that,it was a copy/paste error in the last gist. Corrected here: http://gist.github.com/184345
The new error I get when this code is run looks like this:

[INFO]     When I add a table               
[INFO]       | a | b | b2 | a1 |
[INFO]       | 1 | 2 |    |    |
[INFO]       Tables were not identical (RuntimeError)
[INFO]       features/demo.feature:13:in `When I add a table'

The two new columns are gray (surplus)

from cuke4duke.

darrinholst avatar darrinholst commented on July 19, 2024

It appears to be the following method in cucumber where it converts the input to a Table

  def ensure_table(table_or_array) #:nodoc:
    puts table_or_array.class    #=> Java::JavaUtil::ArrayList
    puts table_or_array[0]       #=> {b=2, a=1} 
    puts table_or_array[0].class #=> Java::JavaUtil::HashMap
    return table_or_array if Table === table_or_array
    table_or_array = hashes_to_array(table_or_array) if Hash === table_or_array[0]
    table_or_array = enumerable_to_array(table_or_array) unless Array == table_or_array[0]
    Table.new(table_or_array)
  end

What is returned is
| b2 | a2 |

from cuke4duke.

aslakhellesoy avatar aslakhellesoy commented on July 19, 2024

Thanks Darrin. Looks like this method needs to be smarter in order to cater for Java collections. Alternatively, we could try to convert to Ruby types on the cuke4duke side before sending it down. Any suggestions?

from cuke4duke.

darrinholst avatar darrinholst commented on July 19, 2024

Yeah, I'd hate to have to change cucumber for this. Could we open up === in java::util::HashMap and handle it there? I couldn't find an easy way to convert java maps to ruby hashes. Would you just have to manually iterate over it?

from cuke4duke.

aslakhellesoy avatar aslakhellesoy commented on July 19, 2024

We could open up java::util::HashMap#===, but it's hacky. I'd prefer looking from some pertinent methods with respond_to? that could be used to separate "hashish", "arrayish" and "tableish" :-)

from cuke4duke.

darrinholst avatar darrinholst commented on July 19, 2024

Actually you'd have to open up Hash to handle HashMaps, but that screws up the === check when you're converting the options.

respond_to? was actually my first thought, but I can't find any common methods between Hash and HashMap. We could add a to_hash or alias contains_key? to has_key? in HashMap and check for those in cucumber.

from cuke4duke.

aslakhellesoy avatar aslakhellesoy commented on July 19, 2024

Doesn' java.util.Map classes respond to the same methods as Ruby Hash? At least you can use a java.util.Map as if it were a Hash.

from cuke4duke.

darrinholst avatar darrinholst commented on July 19, 2024

No, the jruby wrapper for a java Map just mixes in Enumerable, good article on that here http://www.engineyard.com/blog/2009/youve-got-java-in-my-ruby/ in the Decoration section.

from cuke4duke.

darrinholst avatar darrinholst commented on July 19, 2024

So I think we can do something like the following in cucumber_ext.rb

module java::util::Map
alias_method :has_key?, :contains_key?
end

from cuke4duke.

darrinholst avatar darrinholst commented on July 19, 2024

here's what I tried http://gist.github.com/184755, table.rb changed in cucumber and cucumber_ext.rb and StuffSteps.java changed in cuke4duke

Now I'm getting

When I add a table # public void simple.StuffSteps.iAddATable(cuke4duke.Table)

| a | b |

| 1 | 2 |

| 1 | 2 |

Tables were not identical (RuntimeError)

features/demo.feature:13:in `When I add a table'

Where the 3rd row is yellow and when I print the converted table out now it's

| b | a |

| 2 | 1 |

I tried figuring out the cucumber code where it's doing the diff and got lost, is it doing a text comparison to check for missing/surplus rows? The keys ('a', 'b') returned from the Java map come back in a different order than a ruby collection.

Any ideas? Or should we just go with converting java collections to ruby before calling diff?

from cuke4duke.

darrinholst avatar darrinholst commented on July 19, 2024

I went with the java map to ruby conversion - check it out at http://github.com/darrinholst/cuke4duke/commit/36e1a3fa8b89fb913b78f29ed38dbd12e9b8b8ef

It worked on the project I was trying to get this working on, I can update History.txt if you want to go with it.

from cuke4duke.

aslakhellesoy avatar aslakhellesoy commented on July 19, 2024

diffHashes method in Table not working properly. Closed by b07d8e5

from cuke4duke.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.