I have 2 fixtures with a bunch of tests:
fixture.meta({ app: '1', suite: 'smoke', env: '1' })('A')
fixture.meta({ app: '1', suite: 'smoke', env: '2' })('B')
I would like to only run fixture 'A'.
I am using the following command on the command line: .... --includeFixtures app=1 ,env=1. I am still seeing both fixtures A and B being run.
What am I missing?
It seems like you are just using the wrong CLI command. In order to run TestCafe fixtures by specifying additional meta data, you need to use the --fixture-meta command, which you could use like follows:
testcafe chrome my-tests --fixture-meta app=1,env=1
Related
Using Yii2 2.0.12, php 5.6.24 and codeception 2.3.3
On a recent upgrade a set of acceptance tests that have always worked up to now, failed. The upgrade was a standard composer update to the latest versions. The test scenario is as follows:
Test adding a record via a form
Grab the new record to verify
Test adding a second record via a form
Grab the new record to verify
The second grab fails in that it returns an empty record. I've traced this back to the 'queryInternal' method of the 'Command' object and there is a correctly formed PDO statement which performs the correct query but returns an empty result. I've tried breaking before the PDO->execute() and performing the query in MySQL. The query works but the PDO statement fails.
the code of the Cept test script is:
$I->wantTo('Do successive grabs');
$I->amOnPage('index.php?r=portfolio%2Fcreate');
$I->see('Create Portfolio');
$I->fillField('Name','Test Portfolio 1');
$I->click('Create');
$r = $I->grabRecord('app\models\Portfolio' , ['name' => 'Test Portfolio 1']);
$I->amOnPage('index.php?r=portfolio%2Fcreate');
$I->see('Create Portfolio');
$I->fillField('Name','Test Portfolio 2');
$I->click('Create');
$r = $I->grabRecord('app\models\Portfolio' , ['name' => 'Test Portfolio 2']);
The second "grabRecord" produces an empty record. Anyone else have a similar problem?
This seems to have been caused by the change in the 'cleanup' option in 2.2.6. Changing this value to false in the .yml file seems to clear the problem, although I'm not sure why.
I'm trying to run something like this directly on mysql server database:
SupportRequest.all.map{ |support_request| SupportRequestFeedback.create(support_request_id: support_request.id) if support_request.support_request_feedback == nil}
I know the query it produces but not how to implemented in a 1 query command (with the loop)?
You can enter this line in rails console to display queries:
ActiveRecord::Base.logger = Logger.new(STDOUT)
Then enter your code and the query will be displayed.
I may be wrong, but I don't think Rails provides a call to do this kind of operation at once.
You can setup a service to perform this for you, though:
support_requests_without_feedback = SupportRequest.includes(:support_request_feedback).where(support_request_feedback: {id: nil})
You could use the active_record-import gem to achieve mass db insert or you could use this: (not so effecient, though):
support_requests_without_feedback.map{|sr| sr.support_request_feedback.create }
I recently installed SQLAlchemy-FullText-Search dependency in (https://github.com/mengzhuo/sqlalchemy-fulltext-search), but since that I get unexpected results. When I run
nosetests -v
An OperationalError: (OperationalError) near "(": syntax error u'ALTER TABLE opportunity ADD FULLTEXT (title, content, requirements)' () comes out.
I'm defining fulltext_columns:
__fulltext_columns__ = ('title', 'content', 'requirements')
It looks like SQLAlchemy-FullText-Search does only work on MySQL databases - but the default test suite of a TurboGears 2 webapp is using an SQLite in-memory database, so that might be the problem.
I have coded a Ruby IRC bot which is on github (/ninjex/rubot) which is having some conflicting output with MySQL on a dedicated server I just purchased.
Firstly we have the connection to the database in the MySQL folder (in .gitignore) which looks similar to the following code block.
#con = Mysql.new('localhost', 'root', 'pword', 'db_name')
Then we have an actual function to query the database
def db_query
que = get_message # Grabs query from user i.e,./db_query SELECT * FROM words
results = #con.query(que) # Send query through the connection i.e, #con.query("SELECT * FROM WORDS")
results.each {|x| chan_send(x)} # For each row returned, send it to the channel via
end
On my local machine, when running the command:
./db_query SELECT amount, user from words WHERE user = 'Bob' and word = 'hello'
I receive the output in IRC in an Array like fashion: ["17", "Bob"] Where 17 is amount and Bob is the user.
However, using this same function on my dedicated server results in an output like: 17Bob I have attempted many changes in the code, as well as try to parse the data into it's own variable, however it seems that 17Bob is coming out as a single variable, making it impossible to parse into something like an array, which I could then use to send the data correctly.
This seems odd to me on both my local machine and the dedicated server, as I was expecting the output to first send 17 to the IRC and then Bob like:
17
Bob
For all the functions and source you can check my github /Ninjex/rubot, however you may need to install some gems.
A few notes:
Make sure you are sanitizing query via get_message. Or you are opening yourself up to some serious security problems.
Ensure you are using the same versions of the mysql gem, ruby and MySql. Differences in any of these may alter the expected output.
If you are at your wits end and are unable to resolve the underlying issue, you can always send a custom delimiter and use it to split. Unfortunately, it will muck up the case that is actually working and will need to be stripped out.
Here's how I would approach debugging the issue on the dedicated machine:
def db_query
que = get_sanitized_message
results = #con.query(que)
require 'pry'
binding.pry
results.each {|x| chan_send(x)}
end
Add the pry gem to your Gemfile, or gem install pry.
Update your code to use pry: see above
This will open up a pry console when the binding.pry line is hit and you can interrogate almost everything in your running application.
I would take a look at results and see if it's an array. Just type results in the console and it will print out the value. Also type out results.class. It's possible that query is returning some special result set object that is not an array, but that has a method to access the result array.
If results is an array, then the issue is most likely in chan_send. Perhaps it needs to be using something like puts vs print to ensure there's a new line after each message. Is it possible that you have different versions of your codebase deployed? I would also add a sleep 1 within the each block to ensure that this is not related to your handling of messages arriving at the same time.
I have the following code that run on heroku inside a controller that intermittently fails. It's a no-brainer that it should work to me, but I must be missing something.
#artist = Artist.find(params[:artist_id])
The parameters hash looks like this:
{"utf8"=>"������",
"authenticity_token"=>"XXXXXXXXXXXXXXX",
"password"=>"[FILTERED]",
"commit"=>"Download",
"action"=>"show",
"controller"=>"albums",
"artist_id"=>"62",
"id"=>"157"}
The error I get looks like this:
ActiveRecord::StatementInvalid: Mysql::Error: : SELECT `artists`.* FROM `artists` WHERE `artists`.`id` = ? LIMIT 1
notice the WHEREartists.id= ? part of the statement? It's trying to find an ID of QUESTION MARK. Meaning Rails is not passing in the params[:artist_id] which is obviously in the params hash. I'm at complete loss.
I get the same error on different pages trying to select the record in a similar fashion.
My environment: Cedar Stack on Heroku (this only happens on Heroku), Ruby 1.9.3, Rails 3.2.8, files being hosted on Amazon S3 (though I doubt it matters), using the mysql gem (not mysql2, which doesn't work at all), ClearDB MySQL database.
Here's the full trace.
Any help would be tremendously appreciated.
try sql?
If it's just this one statement, and it's causing production problems, can you omit the query generator just for now? In other words, for very short term, just write the SQL yourself. This will buy you a bit of time.
# All on one line:
Artist.find_by_sql
"SELECT `artists`.* FROM `artists`
WHERE `artists`.`id` = #{params[:artist_id].to_i} LIMIT 1"
ARel/MySQL explain?
Rails can help explain what MySQL is trying to do:
Artist.find(params[:artist_id]).explain
http://weblog.rubyonrails.org/2011/12/6/what-s-new-in-edge-rails-explain/
Perhaps you can discover some kind of difference between the queries that are succeeding vs. failing, such as how the explain uses indexes or optimizations.
mysql2 gem?
Can you try changing from the mysql gem to the mysql2 gem? What failure do you get when you switch to the mysql2 gem?
volatility?
Perhaps there's something else changing the params hash on the fly, so you see it when you print it, but it's changed by the time the query runs?
Try assigning the variable as soon as you receive the params:
artist_id = params[:artist_id]
... whatever code here...
#artist = Artist.find(artist_id)
not the params hash?
You wrote "Meaning Rails is not passing in the params[:artist_id] which is obviously in the params hash." I don't think that's the problem-- I expect that you're seeing this because Rails is using the "?" as a placeholder for a prepared statement.
To find out, run the commands suggested by #Mori and compare them; they should be the same.
Article.find(42).to_sql
Article.find(params[:artist_id]).to_sql
prepared statements?
Could be a prepared statement cache problem, when the query is actually executed.
Here's the code that is failing-- and there's a big fat warning.
begin
stmt.execute(*binds.map { |col, val| type_cast(val, col) })
rescue Mysql::Error => e
# Older versions of MySQL leave the prepared statement in a bad
# place when an error occurs. To support older mysql versions, we
# need to close the statement and delete the statement from the
# cache.
stmt.close
#statements.delete sql
raise e
end
Try configuring your database to turn off prepared statements, to see if that makes a difference.
In your ./config/database.yml file:
production:
adapter: mysql
prepared_statements: false
...
bugs with prepared statements?
There may be a problem with Rails ignoring this setting. If you want to know a lot more about it, see this discussion and bug fix by Jeremey Cole and Aaron: https://github.com/rails/rails/pull/7042
Heroku may ignore the setting. Here's a way you can try overriding Heroku by patching the prepared_statements setup: https://github.com/rails/rails/issues/5297
remove the query cache?
Try removing the ActiveRecord QueryCache to see if that makes a difference:
config.middleware.delete ActiveRecord::QueryCache
http://edgeguides.rubyonrails.org/configuring.html#configuring-middle
try postgres?
If you can try Postgres, that could clear it up too. That may not be a long term solution for you, but it would isolate the problem to MySQL.
The MySQL statement is obviously wrong, but the Ruby code you mentioned would not produce it. Something is wrong here, either you use a different Ruby code (maybe one from a before_filter) or pass a different parameter (like params[:artist_id] = "?"). Looks like you use nested resources, something like Artist has_many :albums. Maybe the #artist variable is not initialized correctly in the previous action, so that params[:artist_id] has not the right value?