Tuesday, 27 June 2023

RSpec and comments in HTML

I needed to get at the html comment embedded in a page (don't ask why, it was part of the task I was given)

HTML comments were in the form:

<!-- Message: this is an embedded comment -->

Using the usual RSpec 

expect(page).to have_text('Message') doesn't work, as html comments are non-visible.

A way of getting around this is to use

expect(page.native.inner_html).to include('<!-- Message: this is an embedded comment -->')

does work.


This is a note for the next time I hit the problem.


Saturday, 11 April 2020

An MCU Movie Musing

Chronological order of the Marvel Comic Universe

These are notes to make it easier for me to binge-watch the MCU during this time of lockdown in the UK.

I have seen them all in the cinema, but currently abusing my Disney+ subscription.


  • Captain America: The First Avenger (2011)
  • Captain Marvel (2019)
  • Iron Man (2008)
  • Iron Man 2 (2010)
  • The Incredible Hulk (2008)
  • Thor (2011)
  • The Avengers (2012)
  • Iron Man 3 (2013)
  • Thor: The Dark World (2013)
  • Captain America: The Winter Soldier (2014)
  • Guardians of the Galaxy (2014)
  • Guardians of the Galaxy Vol. 2 (2017)
  • Avengers: Age of Ultron (2014)
  • Ant-Man (2015)
  • Captain America: Civil War (2016)
  • Spider-Man: Homecoming (2017)
  • Doctor Strange (2016)
  • Black Panther (2018)
  • Thor: Ragnarok (2017)
  • Ant-Man and The Wasp (2018)
  • Black Widow (2020)
  • Avengers: Infinity War (2018)
  • Avengers: Endgame (2019)
  • Spiderman: Far From Home (2019)

Thursday, 5 December 2019

Golang and private gitlab repos and 410 Gone

I've been following a microservices with golang tutorial recently, and needed to refer to one project from another.

After getting numerous errors with `go get` and much searching for answers, I stumbled across this solution.

In Gitlab add a personal access token.

In your ~/.netrc file add:

machine gitlab.com
  login {{personal_access_token_name}}
  password {{personal_access_token}}


Replacing the prompts with the actual values.

In your .bashrc add

export GOPRIVATE="gitlab.com/{{path_to_project}}"


This is working for me, a similar approach may well work with bitbucket or codebasehq.

Sunday, 3 March 2019

OSX and image not found readline.bundle

Something changed recently in my osx configuration, I'm not sure what, but it broke readline on the macbook.

The key part of the error message  was:

Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
  Referenced from: /Users/stokern/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle
  Reason: image not found - /Users/stokern/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle


The fix was to add the ruby readline gem:

group :development, :test do
  ...
  gem 'rb-readline'
end

This is the second time this has caught me out, so I thought I'd document it.

You're welcome

Saturday, 17 November 2018

OS X Unable to build mysql2 gem


The problem:
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
The solution:
gem install mysql2 -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"

Note that these are mainly notes to myself, but if you find them helpful then you're welcome.

Monday, 22 October 2018

rails-sass is deprecated

I've been seeing this for a while, and have finally got round to finding a solution.

In the project `Gemfile`, remove the reference to `sass-rails` and replace with `sassc`.

Sigh. It took more than two minutes to find the fix, so logging it here

Saturday, 7 July 2018

NameError: uninitialized constant RailsERD

This has been an occasional annoyance when setting up new Rails projects with the rails-erd gem.

The documentation for the gem is to add

gem 'rails-erd', :require=>false

into the Gemfile, and then run rails g erd:install to add the hook to run when a rails db:migrate is carried out.

I found that this creates /lib/tasks/auto_generate_diagram.rake containing

if Rails.env.development?
  RailsERD.load_tasks
end


One solution is to remove the :require=>false from the Gemfile, but apparently this may have an impact on efficiency rails erd issue 282.

I tried a slightly different approach, and changed /lib/tasks/auto_generate_diagram.rake to require the gem.

if Rails.env.development?
  require 'rails-erd'
  RailsERD.load_tasks
end

Sunday, 21 January 2018

Publishing Rails 5 apps to heroku

When attempting to migrate the database, I was getting errors with the following two messages

Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Gem::LoadError: can't activate pg (~> 0.18), already activated pg-1.0.0. Make sure all dependencies are added to Gemfile.


The second one turned out to be the main issue.

A solution was found in a rails issue 31669, briefly

Thank you for the issue. Rails still don't support pg 1.0.

My solution was to change the Gemfile reference to

group :production do
gem 'pg', '~> 0.18'
gem 'rails_12factor'
end

And the migration succeeded. Now to apply the issue to the other app I was looking at yesterday...

Rails 5 and optional has_many relationships

This is a continuation in the random notes from attempting to learn Ruby on Rails.

Todays' rambling is to do with having an optional relationship between two tables.
erd from project


I am building an application to help me track fuel usage, and was wanting to have a relationship set between Users and Vehicles, based on the diagram.

The spec tests were failing, because the User:Vehicle relationship was mandatory.

The issue appears to be that Rails 5 has made the belongs_to relationship required (as found in the answer to a StackOverflow question).

The solution seems relatively simple, add the optional link to the relationship:
 
belongs_to :user, optional: true
 
My tests are all passing again. For now.

Saturday, 4 November 2017

[Solved] Deprecation warnings Devise::TestHelpers

Another entry in the series of 'notes to myself' here.
A simple fix for the Deprecation warning saying that Devise::TestHelpers will be removed.
The fix is to replace the
 config.include Devise::Test::Helpers, :type => :controller  
with
config.include Devise::Test::ControllerHelpers, :type => :controller  
in spec/rails_helper.rb.
Unlike many of the suggested solutions, I don't have the devise configuration in the rails_helper file.
I have a separate set of helper functions, and the relevant location is 
spec/support/devise.rb.
 RSpec.configure do |config|  
  config.include Devise::Test::ControllerHelpers, :type => :controller  
 end  



You can stop reading now and go do something more productive instead.

Thursday, 19 January 2017

RSpec failing after a new Rails Composer project



RSpec issues

Add
require 'rails_helper.rb'
into the spec files to allow the tests to run as expected.

spec/features/visitors/sign_up_spec.rb

The minimum password length is set to be 6 characters, but the 'expected fail' password was set to 'please', causing the test to fail.

Changed password to 'short' and test passes.

spec/features/users/sign_in_spec.rb

The tests were looking for an authentication_key of 'email'. Changed to 'Email' to match the results from Devise.

Tuesday, 10 January 2017

Getting Puma to listen for all hosts with the Guardfile

This has been bugging me for a while, and I've finally had time to track down how to configure Guardfile in order to have Puma listen to all ip addresses.

guard 'rails', :host => '0.0.0.0' do
  watch('Gemfile.lock')
  watch(%r{^(config|lib)/.*})
end

Adding the :host => '0.0.0.0' gets puma to listen for all addresses.

Wednesday, 7 December 2016

Lost Dreams

Why do words come when I'm sad?
Nothing flows right when I'm glad.

I've told you how I feel, so why
You tell me things, nearly make me cry.

Hearing tales of lovers found
Im not the liked one, I'm losing ground

Games of strip poker, you were losing
Never seeing what I've been musing

You're not the first to break this ground
I now wonder why I'm not underground

Dreams of hope, sunk in the bog.
Sniffing my ankles, that great black Dog

Each night I hope as I wait for sleep
Sadly morning comes round but I'm still around

Saturday, 22 October 2016

Rails woes on Windows 10

The Rails community isn't strong on support for Windows based machines.

The github repository RubyOnWindowsWoes contains the source and issues found.

This note is to remind me how I eventually solve the problems!

Thursday, 13 October 2016

ConfigurationManager does not exist in the current context

This was plaguing me for some time.

Part of the solution is the
#include System.Config

The bit I kept missing was to include the System.Configuration reference to the project.

Sigh.


Monday, 28 December 2015

Windows 10 flickering on top few pixels after update

A bit of history first.

My laptop was originally a Windows 8.1 machine, and was updated to Windows 10 when that became available (although it took two attempts).

It has just had the November update applied (which took a long, long time).

Post update, I have noticed a flickering across the top few pixels of the screen. A quick look at recent posts didn't give many useful hints.

I had a look at the advanced screen settings, and saw the screen was set to 1366 x 768 picels - this wasn't the resolution I was expecting. I dropped the resolution to 1360 x 768 and this seems to have stopped the issue.

The recommended resolution is 1366 though, and I don't understand why changing the horizontal resolution has stopped the issue.

Sunday, 8 November 2015

Ruby, Windows and Timezones

With the current builds of Ruby on Rails, there are a couple of problems with a default installation.

The first is that Windows environments seem to need the timezone data gem including.

The second is to do with the initial layout file.

Timezone data

If you have a Rails folder already, you might just be able to get away with the following:

Details about the timezone gem are in github. Add the following line to your Gemfile:

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

then run 
bundle update

as usual when you change your Gemfile.

To build a new Rails project

Follow Fletcher Nichols' instructions, (basically running this gist, then adding a new environment variable SSL_CERT_FILE with the value C:\RailsInstaller\cacert.pem.

application.html.erb

The line:
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
is currently failing on Windows environments. Replace the line with:
<%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>

Adding the coffee-script-source gem to your the Gemfile seems fix the issue:
..
gem 'coffee-script-source', '1.8.0', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
seems to fix the issue.


Edit: added the coffee-script-source notes.
Edit2: Added the SSL_CERT_FILE notes

Thursday, 10 September 2015

Googlewhack! alfridariaANDxystarch

Googlewhacking is finding a pair of words that give just a single hit on Google.

Today's effort was made with the aid of a dictionary of less-commonly used words.

Wednesday, 9 September 2015

Googlewhack! XystarchANDyarker

Googlewhacking is finding a pair of words that give just a single hit on Google.

Today's effort was made with the aid of a dictionary of less-commonly used words.

This is the second one I've found today.

Googlewhack! xystarchANDsnaggers

Googlewhacking is finding a pair of words that give just a single hit on Google.

Todays effort was made with the aid of a dictionary of less-commonly used words.