Comments (16)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
diffHashes method in Table not working properly. Closed by b07d8e5
from cuke4duke.
Related Issues (20)
- Antlib should define all tasks HOT 1
- Cannot get maven-cuke4duke-jump-start to work.... HOT 3
- cuke4duke wiki has dead links HOT 5
- gherkin 2.4.0 breaks cuke4duke 0.4.3/0.4.4 running using maven HOT 2
- The plugin 'org.apache.maven.plugins:maven-cuke4duke-plugin' does not exists HOT 1
- cuke4duke-maven-plugin is does not use username/password for proxy connection HOT 2
- OutOfMemoryError caused by SpringFactory HOT 1
- Cuke4Duke StepMother still using announce
- Cucuber 1.0.1 breaks cuke4duke HOT 10
- Errors while running java example "HelloCucumber" HOT 9
- java example hangs
- Configure Source Directory
- accessing tags for OutlineTable HOT 1
- Missing ant Buildlistener class
- Deploy maven plugins to Maven Central
- Step definitions inside jar HOT 6
- Example project 'jamesladd-maven-cuke4duke-jump-start' fails HOT 5
- cuke4duke install fails HOT 6
- better grails example HOT 3
- Deprecate this project more clearly
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 cuke4duke.