Guard not evaluating correct file - rspec-rails

I'm running Guard with rspec 3.0 and spring on Rails 4.1. When I try to write view specs for my app, guard isn't noticing the correct file being saved. For example, if I save a view spec at "/spec/views/api/v1/registrations/create.json.jbuilder_spec.rb", guard will run the spec for "/spec/controllers/api/v1/registrations_controller_spec.rb". My Guardfile is below:
guard :rspec, cmd: 'spring rspec', all_on_start: false do
watch(%r{^spec/models/.+integration_spec\.rb$})
watch(%r{^spec/helpers/.+_spec\.rb$})
watch(%r{^spec/routing/.+_spec\.rb$})
watch(%r{^spec/requests/.+_spec\.rb$})
watch(%r{^spec/views/.+_spec\.rb$})
watch(%r{^spec/controllers/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
end
If I comment out all of the "spec" regular expressions except for the view one, guard still has the same behaviour that I explained above. Also, this happens for every single view spec that I write. I'm not sure why this regular expression is picking this up, but any help is appreciated.

I figured out the problem. It turned out that the gem guard-rspec has a default failed_mode, which is set to focus (the first 10 failed specs, no matter what you run apparently). By setting this to 'none' in my Guardfile, it fixed my problem.

Related

Initialising a driver instance with callSingle does not work for automated UI tests [duplicate]

I was trying to find a way to launch all features in Karate testing through maven using an external variable to set up the browser (with a local webdriver or using a Selenium grid).
So something like:
mvn test -Dbrowser=chrome (or firefox, safari, etc)
or using a Selenium grid:
mvn test -Dbrowser=chrome (or firefox, safari, etc) -Dgrid="grid url"
With Cucumber and Java this was quite simple using a singleton for setting up a global webdriver that was then used in all tests. In this way I could run the tests with different local or remote webdrivers.
In Karate I tried different solution, the last was to:
define the Karate config file a variable "browser"
use the variable "browser" in a single feature "X" in which I set up only the Karate driver
from all the other features with callonce to re-call the feature "X" for using that driver
but it didn't work and to be honest it doesn't seem to me to be the right approach.
Probably being able to set the Karate driver from a Javascript function inside the features is the right way but I was not able to find a solution of that.
Another problem I found with karate is differentiating the behavior using a local or a remote webdriver as in the features files they're set in different ways.
So does anyone had my same needs and how can I solve it?
With the suggestions of Peter Thomas I used this karate-config.js
function fn() {
// browser settings, if not set it takes chrome
var browser = karate.properties['browser'] || 'chrome';
karate.log('the browser set is: ' + browser + ', default: "chrome"');
// grid flag, if not set it takes false. The grid url is in this format http://localhost:4444/wd/hub
var grid_url = karate.properties['grid_url'] || false;
karate.log('the grid url set is: ' + grid_url + ', default: false');
// configurations.
var config = {
host: 'http://httpstat.us/'
};
if (browser == 'chrome') {
if (!grid_url) {
karate.configure('driver', { type: 'chromedriver', executable: 'chromedriver' });
karate.log("Selected Chrome");
} else {
karate.configure('driver', { type: 'chromedriver', start: false, webDriverUrl: grid_url });
karate.log("Selected Chrome in grid");
}
} else if (browser == 'firefox') {
if (!grid_url) {
karate.configure('driver', { type: 'geckodriver', executable: 'geckodriver' });
karate.log("Selected Firefox");
} else {
karate.configure('driver', { type: 'geckodriver', start: false, webDriverUrl: grid_url });
karate.log("Selected Firefox in grid");
}
}
return config;
}
In this way I was able to call the the test suite specifying the browser to use directly from the command line (to be used in a Jenkins pipeline):
mvn clean test -Dbrowser=firefox -Dgrid_url=http://localhost:4444/wd/hub
Here are a couple of principles. Karate is responsible for starting the driver (the equivalent of the Selenium WebDriver). All you need to do is set up the configure driver as described here: https://github.com/intuit/karate/tree/master/karate-core#configure-driver
Finally, depending on your environment, just switch the driver config. This can easily be done in karate-config.js actually (globally) instead of in each feature file:
function fn() {
var config = {
baseUrl: 'https://qa.mycompany.com'
};
if (karate.env == 'chrome') {
karate.configure('driver', { type: 'chromedriver', start: false, webDriverUrl: 'http://somehost:9515/wd/hub' });
}
return config;
}
And on the command-line:
mvn test -Dkarate.env=chrome
I suggest you get familiar with Karate's configuration: https://github.com/intuit/karate#configuration - it actually ends up being simpler than typical Java / Maven projects.
Another way is to set variables in the karate-config.js and then use them in feature files.
* configure driver = { type: '#(myVariableFromConfig)' }
Keep these principles in mind:
Any driver instances created by a "top level" feature will be available to "called" features
You can even call a "common" feature, create the driver there, and it will be set in the "calling" feature
Any driver created will be closed when the "top level" feature ends
You don't need any other patterns.
EDIT: there's some more details in the documentation: https://github.com/intuit/karate/tree/develop/karate-core#code-reuse
And for parallel execution or trying to re-use a single browser for all tests, refer: https://stackoverflow.com/a/60387907/143475

UIDocumentPickerViewController iOS13 not Working

On my application, i use UIDocumentPickerViewController to allow the user to pick files (import), but starting from iOS 13 that functionality stop working, basically the document picker is open, but the user can't choose a file (taping the file does nothing).
I made a simple sample just to isolate the code:
class ViewController: UIViewController, UIDocumentPickerDelegate {
#IBAction func openDocumentPicker(_ sender: Any) {
let types = [String(kUTTypePDF)]
let documentPickerViewController = UIDocumentPickerViewController(documentTypes: types, in: .import)
documentPickerViewController.delegate = self
present(documentPickerViewController, animated: true, completion: nil)
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("Cancelled")
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
print("didPickDocuments at \(urls)")
}
}
Sample project:
https://github.com/Abreu0101/document-picker-iOS13-issue
Reference:
When I got this issue, I realised that it's working when choosing files from "Browse" tab because I implemented the method "didPickDocumentAt", but it was not working when I tapped on files from "Recent" tab.
To make it work on "Recent" tab, I'd to implement the method "didPickDocumentsAt", which makes the same thing, but it handles an array of URLs.
On Mojave there's the problem, make sure you upgrade your os to Catalina.
https://github.com/Elyx0/react-native-document-picker/issues/246
UIDocumentBrowserViewController error "Cannot create urlWrapper for url" on iOS13 simulator
I enountered this issue on iOS 13.2.2. Updated to iOS 13.2.3 fixed this issue without any code changes.

Premake "no active solution, project or configuration" error

I am trying to run premake with custom script like this
premake4.exe -file=proj4_shared.lua vs2010
And I get
proj4_shared.lua:2: no active solution, project, or configuration
Contens of the proj4_shared.lua:
#!lua
solution ("Proj4")
project "proj4"
language "C++"
kind "SharedLib"
files { "proj4/*.h", "src/src/*.c", "src/src/proj4.def" }
excludes { "src/src/cs2cs.c", "src/src/geod.c", "src/src/nad2bin.c", "src/src/nad2nad.c" }
location (BUILD_DIR .. "vcproj")
includedirs { "src/src" }
defines { "WIN32", "_CRT_SECURE_NO_WARNINGS" }
buildoptions { "/W1" }
local p = project()
p.uuid = GetExistingUuid(p) or p.uuid
configuration { "Debug*" }
defines { "_DEBUG", "DEBUG" }
flags { "Symbols" }
targetsuffix "D"
configuration { "Release*" }
defines { "NDEBUG" }
flags { "Optimize" }
if (not DISABLE_RELEASE_SYMBOLS) then flags { "Symbols" } end
targetsuffix ""
According to https://github.com/premake/premake-4.x/wiki/solution
The solution function creates a new solution and makes it active
So what is the issue?
I recommend you try:
solution ("Proj4")
local p = project "proj4"
...
I suspect the call to project() with no argument is confusing the system.
ALTERNATIVELY:
You can try:
local p = premake.api.current.project
Which should also work to get you a reference to the current project.
NOTE: I am using premake5.exe, not premake 4, so some things may have changed in the interim.

What is the gradle way to filter a subset of files in src/main/webapp?

I'm doing a maven conversion to gradle and want to see the opinions on the best way to perform the following. I currently have multiple files under src/main/webapp. Some need filtered one way and some need filtered in another.
Notionally under src/main/webapp I have a directory foo containing html and binaries and under webapp many other files including html. I want to filter just the foo/*.html files.
In my notional build.gradle I can either do:
war {
eachFile {
if(shouldFilter(it)) {
it.filter(ReplaceTokens, tokens: [key: 'value'])
}
}
}
def shouldFilter(input) {
input.path.contains('foo') && input.name.endsWith('.html')
}
or move each subset into its own directory that is not copied by default
war {
from('src/main/foo-pre-filter') {
into 'foo'
include '*.html'
filter(ReplaceTokens, tokens: [key: 'value'])
}
}
Or is there another option I missed?
If I understand the question correctly, you can use filesMatching. Also, I would do it as part of the processResources task, as opposed to the war task. It would look something like this:
processResources {
filesMatching('foo/*.html') {
filter(ReplaceTokens, tokens: [key: 'value'])
}
}
I realize the initial question was asked 2 years ago, so this probably won't help the asker, but perhaps it could help someone else in the future.
I bumped into the same question today and couldn't find specific, working example right away from any of the results from Google search, one of the results led me here. After some tries, I finally get it works. Below is a working task:
war {
filesMatching("**/foo/*.html") {
filter(ReplaceTokens, tokens: [key: 'value'])
}
}
Link: filesmatching

Flex: Is it guaranteed that code is excluded from compiled build when not reachable?

Suppose you have
private static const INCLUDE_MY_DEBUG_CODE:Boolean = false;
public function runMyDebugCode():void
{
if ( INCLUDE_MY_DEBUG_CODE )
{
callADebugFunction();
}
}
private function callADebugFunction():void
{
...
}
Given there is no other reference to callADebugFunction, will it be guaranteed that callADebugFunction is not part of the compiled build?
If there no references to the file/class - then it's not going to be compiled.
In your case if you have reference from outside to this class - all the methods are going to be compiled.
Use compilation variables to eliminate debug code from release.
Go to Project->Properties->Flex Compiler and add
For debugging mode:
-define=CONFIG::release,false -define=CONFIG::debugging,true
or for release:
-define=CONFIG::release,true -define=CONFIG::debugging,false
Then in you function runMyDebugCode()
CONFIG::debugging {
trace("this code will be compiled only when release=false and debugging=true");
}
CONFIG::release {
trace("this code will be compiled only when release=true and debugging=false");
}
I highly doubt it. Since something IS referencing that function (regardless of whether or not it is reached at runtime), it is most likely that this code will in fact get compiled into your SWF/SWC file.
There are better ways to prevent debugging code from ending up in release builds. See zdmytriv's answer.

Resources