mocha/chai test Unexpected token => - mocha.js

I'm running a test, and I'm getting an unexpected error.
I'm sorting the results:
docs.sort((a, b) => m_ids.findIndex(id => a._id.equals(id)) -
m_ids.findIndex(id => b._id.equals(id)));
The error I'm getting is definitely related to that line
mbp:test testlab$ mocha .
/Users/testlab/Documents/workspace/KBase/controller/KBase.js:112
docs.sort((a, b) => m_ids.findIndex(id => a._id.equals(id)) -
^^
SyntaxError: Unexpected token =>
I was thinking about skipping the code by putting an if statement around it, but that doesn't seem to work either.

I rewrote the sort to not use =>, so it is working on the webpage and it is working on chai/mocha now.

Related

Getting error Aws::S3::Errors::InvalidBucketName when creating bucket

I am trying to create a bucket, with help of aws-sdk-ruby from ruby console. Following is the code I am running in my console:
Aws.config.update({
:region => "myRegion",
:credentials => Aws::Credentials.new("access_key", "secret_key"),
:endpoint => "http://Ip",
:force_path_style => true
})
bucket_name = "abc"
bucket = s3.bucket(bucket_name)
bucket.create({ acl: "authenticated-read", grant_full_control: "GrantFullControl"})
Last line gives this error:
Aws::S3::Errors::InvalidBucketName:
I dont see this error in the documentation here. When can one get such error and how to resolve this?
I was also getting this error.. the main reason why was getting this error because my bucket name was starting with capital letter.. Bucket name always starts with lowercase ..

CFE syntax errors

Trying to write a cfengine3 promise that will take an entire directory and move it down one level.
I've used my policy hub to distribute the promise, but I've not yet folded it into my active promise.cf
Here's the promise:
body common control
{
bundlesequence => { dirstructure };
}
#Find out by existance of directories if filesystem is old structure or new
#Set classes for each instance. If old, copy down one level.
#If new file system already, pat yourself on the back
bundle agent dirstructure
{
classes:
"oldFILEstructure"expression => isdir("/old/dir/structure/");
"newFILEstructure" expression => isdir("/new/dir/structure/");
reports:
oldFILEstructure::
"system has old file structure..";
newFILEstructure::
"system has new file structure..";
methods:
oldFILEstructure::
"migratedirectories" usebundle => movedirectories
}
bundle agent movedirectories
{
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/.");
depth_search => recurse ("inf");
}
I've used this "isdir" source and this example for local_cp, both from CFE to base the promise on.
When invoked, I get the following error output and I'm trying to figure out why.
:/var/cfengine/inputs/standalone# cf-agent --no-lock --inform --file ./file_structure.cf
./file_structure.cf:41:12: error: syntax error
depth_search => recurse ("inf");
^
./file_structure.cf:41:12: error: Expected promiser string, got 'depth_search'
depth_search => recurse ("inf");
^
./file_structure.cf:41:15: error: Expected ';', got '=>'
depth_search => recurse ("inf");
^
./file_structure.cf:41:23: error: Expected promiser string, got 'recurse'
depth_search => recurse ("inf");
^
./file_structure.cf:41:25: error: Expected ';', got '('
depth_search => recurse ("inf");
^
./file_structure.cf:41:31: error: Expected ';', got ')'
depth_search => recurse ("inf");
^
./file_structure.cf:41:32: error: Expected promiser string, got ';'
depth_search => recurse ("inf");
^
./file_structure.cf:42:1: error: Expected ';', got '}'
}
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/.");
depth_search => recurse ("inf");
}
You have an extra semicolon at the end of the copy_from line.
A semicolon ; identifies the end of a promise. Try switching the semicolon at the end of the copy_from line to a comma ,.
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/."),
depth_search => recurse ("inf");
}
Additionally you may want to check out the transformer attribute.
It may or may not be a good use for your case.\
bundle agent example
{
files:
"/old/dir/structure" -> { "jira:EXAMPLE-1234" }
transformer => "/bin/mv /old/dir/structure /new/dir/structure",
comment => "The standard is to use the new location because x, y, z. Bad thing Q or U might happen if this is not managed properly.";
}

should.kind_of?(model) error with expect syntax in RSpec

I had this:
builder.class.should.kind_of?(MyCustomFormBuilder)
which I changed to
expect(builder.class).to be kind_of?(MyCustomFormBuilder)
but I get
expected #<FalseClass:0> => false
got #<Class:25336780> => MyCustomFormBuilder
How can I do this comparison with expect?
Switching from
builder.class.should.kind_of?(MyCustomFormBuilder)
to this format
expect(builder).to be_kind_of(MyCustomFormBuilder)
worked.
Note:
just builder, not builder.class
be_kind_of, not kind_of?

SyntaxError on pageobject while accessing a select_list within fieldset

I'm trying to access a select_list within a fieldset though Cheezy's pageobject.
The total html is far too long to post (well over 200 lines for just the fieldset), but I can supply the lines with all of the id's and such.
fieldset:
<fieldset class="dartPayer-Insurance" style="width: 730px;">
select_list:
<select id="dartPayer-Payer" style="width: 235px;">
Line in the pageobject I am attempting to use:
select_list(:payer_insurance){ element(:class => "dartPayer-Insurance").select_list_element(:id => "dartPayer-PayerList") }
The error I am getting when I try to run my cucumber test:
(eval):1: syntax error, unexpected '(', expecting $end
{:id=>"dartPayer-Insurance"}(identifier)
^ (SyntaxError)
This error occurs when I try to set the select_list with this line:
self.send(field, input) (Where field is "payer_insurance=" and input is "UMA")
This line works for other pages, so I am fairly certain this is not part of the problem. I'm sure it's a simple bit of syntax in the pageobject line, but I can't find any documentation for using the pageobject quite like I'm trying to. The only reference I can find is within a previous question I asked: Accessing a table within a table (Watir/PageObject)
Could anyone please tell me what I have done wrong?
Thank you in advance for your help.
Update: An example that reproduces the problem:
Given a page with the html:
<fieldset class="dartPayer-Insurance" style="width: 730px;">
<select id="dartPayer-Payer" style="width: 235px;">
<option value="UMA">UMA</option>
</select>
</fieldset>
And a page object defined as:
class MyPage
include PageObject
select_list(:payer_insurance){ element(:class => "dartPayer-Insurance").select_list_element(:id => "dartPayer-PayerList") }
def input_payer(field, input)
self.send(field, input)
end
end
Running the following code:
browser = Watir::Browser.new
browser.goto('C:\Scripts\Misc\Programming\PageObject\test.htm')
page = MyPage.new(browser)
field = "payer_insurance="
input = "UMA"
page.input_payer(field, input)
Generates the following exception:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/platforms/watir_webdriver/page_object.rb:968:in `instance_eval': (eval):1: syntax error, unexpected '(', expecting $end (SyntaxError)
{:class=>"dartPayer-Insurance"}(identifier)
^
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/platforms/watir_webdriver/page_object.rb:968:in `find_watir_element'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/platforms/watir_webdriver/page_object.rb:907:in `element_for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/element_locators.rb:11:in `element'
from pageobject.rb:7:in `block in <class:MyPage>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object.rb:379:in `instance_eval'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object.rb:379:in `call_block'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/accessors.rb:1089:in `block in standard_methods'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.0/lib/page-object/accessors.rb:246:in `block in select_list'
from pageobject.rb:10:in `input_payer'
from pageobject.rb:25:in `<main>'
Solution
The accessor you want for the select list is:
select_list(:payer_insurance){ element(:fieldset, :class => "dartPayer-Insurance").select_list_element(:id => "dartPayer-Payer") }
Problem
You were getting the syntax error due to the following part:
element(:class => "dartPayer-Insurance")
In the API docs for element, you can see that method definition is:
(Object) element(tag, identifier = {:index => 0})
Finds an element
Parameters:
the (Symbol) — name of the tag for the element
identifier (Hash) (defaults to: {:index => 0}) — how we find an element. You can use a multiple paramaters by combining of any of the following except xpath
The original code was missing the tag parameter, which caused the exception.
Note that the select list id was also incorrect - using dartPayer-PayerList instead of dartPayer-Payer.

Ruby block comment and profile questions

I have written a Ruby version of Erik Demaine's (MIT) docdist8.py. This is available on github as docdist-v3.rb. I faced two weird kind of situations:
1) In the function inner_product there is a block comment:
Inner product between two vectors, where vectors
are repeated as dictionaries of (word, freq) pairs.
Example : inner_product({"and":3, "of":2, "the":5},
{"and":4, "in":1, "of":1, "this":2}) = 14.0
If I wrap this with =begin and =end there is no problem, but if I wrap it with triple double-quotes """, I get errors as follows:
./docdist-v3.rb:71: syntax error, unexpected tIDENTIFIER, expecting kEND
Example : inner_product({"and":3, "of":2, "the":5},
^
./docdist-v3.rb:71: syntax error, unexpected tIDENTIFIER, expecting kEND
Example : inner_product({"and":3, "of":2, "the":5},
^
./docdist-v3.rb:72: syntax error, unexpected kIN, expecting kEND
... {"and":4, "in":1, "of":1, "this":2}) = 14.0
^
./docdist-v3.rb:72: syntax error, unexpected tIDENTIFIER, expecting kEND
... {"and":4, "in":1, "of":1, "this":2}) = 14.0
^
./docdist-v3.rb:72: syntax error, unexpected tIDENTIFIER, expecting kEND
..."and":4, "in":1, "of":1, "this":2}) = 14.0
^
Are there rules / allowed entries for """ that are different from =begin and =end?
2) When I run my program with the time command it executes in about 0.3 seconds. However, if I put require 'profile' the time it takes becomes very high in comparison - 30 seconds. Hence I don't get the correct output at all. This doesn't seem to be the case with the original Python version, where it takes only a marginal extra time to profile. How do I get the same profile run in Ruby?
Note: The two files I used to run the Ruby program are t2.bobsey.txt and t3.lewis.txt. They are available at http://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/dd_data.htm
1) Block comments always have the form:
=begin
Comment
=end
You are actually creating a string that is never used:
"""
Not a comment
"""
# => "\nNot a comment\n"
That's why you get an error when adding another quote and that's why the syntax highlighting renders them as strings.
2) It's slower with profiler but I get identical results:
ruby docdist-v3.rb t2.bobsey.txt t3.lewis.txt
File t2.bobsey.txt:262111 lines,49785 words,3354 distinct words
File t3.lewis.txt:1015474 lines,182355 words,8530 distinct words
The distance between the documents is: 0.574160 (radians)

Resources