So you can have a test like this:
find(".blah").should have_content("blah blah")
But is there a way to just check if something is in blah?
find(".blah").should have_some_content
I do not believe there is a Capybara::RSpecMatchers for what you want. However, you could use the underlying Capybara::Node::Matchers.
Try:
find(".blah").has_no_text?.should be_true
If you really want to use the Capybara::RSpecMatchers, you could use have_content with a regex that looks for any non-whitespace character.
find(".blah").should have_content(/[^\s]/)
It looks like you are using Capybara.
Instead of the style in question, I will write it like this
page.should have_css('.bar', text: 'foo')
I would inspect the return value of find(".blah") and see what it is in the following two scenarios:
You know it's there, and something is returned
You know it's NOT there and something else (maybe nil?) is returned
Then writing the test just to confirm that, in your case, some elements with that class exist is easy. It's just a matter of knowing the difference between the return values of the .find method when there is and is not something found.
Related
Example:
In Ruby/capybara I would do:
if page.has(element)?
do somenthing
elsif page.has(element2)?
do another thing
else
print "Do nothing"
How could i do it in robotframework ?
*** Keywords ***
given I need to verify some conditions
Seems you want to implement conditional logics. For that there is keyword called "Run Keyword If" in Robotframework. Please try to look documentation for that.
Here is a link that might be helpful.
https://blog.codecentric.de/en/2013/05/robot-framework-tutorial-loops-conditional-execution-and-more/
so basically I have a bunch of HTML strings in a MySQL table and I am trying to display then through EJS.
For instance, I have a string that looks like this is a link with some <code>code</code> next to it. In my code I try to display it in that way.
<%- listOfStrings["myString"] -%>
However, as you probably guessed when reading the title, the string seems to be escaped when displaying on the screen.
What's even weirder to me is that I have two tables with such strings, and it works for the first one, while it doesn't for the second one. One difference though, is that the first one is hardcoded, while the second one can be edited through some tool on my website. Encoding is utf32_unicode_ci for both tables, if that matters.
For debugging purposes I tried to store the aforementioned strings in a js variable and display them in the console: then it seems like <and > characters are all escaped for some reason. Is there an explanation to this behavior, and if so how to fix it so that HTML renders correctly?
Thanks for your help!
You can try it :
<%=listOfStrings["myString"]%>
I read that you should use ? to match text non-greedily, so the regex
http://.*?\.png
...used on
http://example.png.png
...would return http://example.png.
But the non-greediness only seems to work from left to right. That is, if I matched it on
http://http://example.png
...it would return http://http://example.png.
How can I get the code to match http://example.png only?
Try this:
http://[A-Za-z0-9_-]+\.png
It wont get the first http:// because it has more than [A-Za-z0-9_-]+ between it and .png
Could also use this if you are worried about other characters in the URL:
http://[^:]+?\.png
You could use a negative look ahead too, but I think smerny 's answer is better.
http://(?!http://).*?\.png
I'm using the Linkedin gem to pull profile information for RoR 3.
Gem: https://github.com/pengwynn/linkedin
API Doc: https://developer.linkedin.com/documents/profile-fields#positions
Everything works except when I get to a property with a dash in the name.
<%=position.title %> displays correctly but<%= position.start-date %> return a NoMethodError in Users#show - undefined method start.
I've tried different operations like "startDate", "start_date", quotes around "start-date" but none have worked.
Is there a proper way to escape the dash/hyphen in the property name?
The expression in your ERB will be parsed as subtracting the value of the date variable from the result of a call to the start() method of the position object. Hyphens aren't valid in identifiers within Ruby.
I'm not familiar enough with the LinkedIn gem to suggest a solution, except to say that since it's based on an XML API, you should look for a way to manually pull data out of a tag pair. Most similar gems offer such a method. Also, this is a great case for using IRB as an exploratory tool: fire up an IRB session and see what happens when you call position.methods, after properly creating the position variable of course. My guess would be that you'll see something in that list which suggests an answer.
Looks like it returns a Hashie::Mash which converts keys, with a few extra rules:
https://github.com/pengwynn/linkedin/blob/master/lib/linked_in/mash.rb
You said you'd already tried position.start_date right? That should work. But if not, have you tried position['start-date'] or position['start_date'] one of those two should also work, since it's a Mash.
I am using a route like this
match "/v1/:method" => "v1#index"
My intention here is capture the name of the api method and then send the request to that method inside the controller.
def index
self.send params[:method], params
end
I figured this would send the other parameters as an argument to the method, but it didn't work. So my question is how can I pass the non-method parameters in a query string?
#query_parameters does exactly what you want:
request.query_parameters
It's also the most efficient solution since it doesn't construct a new hash, like the other ones do.
Stolen from the work of a colleague. I find this a slightly more robust solution, since it will work even if there are changes to the path parameters:
params.except(*request.path_parameters.keys)
I sort of solved this problem by doing this:
params.except("method","action","controller")